POST
|
Thanks for your reply. Actually, I am using the selection tool of the ArcMap to select lines splitted by my tool. So, selection using the mouse (after selection tool is active) is not working.
... View more
03-08-2016
10:29 PM
|
0
|
0
|
398
|
POST
|
Hi, I am creating a ArcGIS Desktop Python add-in that has a tool to cut polylines of a layer by drawing lines across, just like the cut polygon tools in editor mode. I am able to cut polylines with my tool and save it but the problem is; I am unable to select properly any polylines of that layer after my cut operation. My add-in code is given below. onLine method of CutTool is called when the mouse button is double-clicked to finish drawing the line on the map. class CutTool(object): """Implementation for PlugIn_addin.tool (Tool)""" def __init__(self): self.enabled = True self.shape = "Line" def cut_geometry(self, to_cut, sel_fid_query, cutter): """ Cut a feature by a line, splitting it into its separate geometries. :param to_cut: The feature to cut. :param sel_fid_query: Selected Query FID to cut. :param cutter: The polylines to cut the feature by. :return: The feature with the split geometry added to it. """ arcpy.AddField_management(to_cut, "SOURCE_OID", "LONG") geometries = None polyline = None edit = arcpy.da.Editor(os.path.dirname(to_cut)) # Edit session is started without an undo/redo stack for versioned data (for second argument, use False for unversioned data) edit.startEditing(False, True) # Start an edit operation edit.startOperation() insert_cursor = arcpy.da.InsertCursor(to_cut, ["SHAPE@", "SOURCE_OID"]) with arcpy.da.UpdateCursor(to_cut, ["SHAPE@", "OID@", "FID"], sel_fid_query) as polylines: for polyline in polylines: if cutter.disjoint(polyline[0]) == False: geometries = polyline[0].cut(cutter) polylines.deleteRow() if geometries: for geometry in geometries: insert_cursor.insertRow([geometry, polyline[1]]) # Stop the edit operation. edit.stopOperation() # Stop the edit session and save the changes edit.stopEditing(True) def onLine(self, line_geometry): mxd = arcpy.mapping.MapDocument("CURRENT") df = mxd.activeDataFrame layers = arcpy.mapping.ListLayers(mxd) to_cut = None sel_list = None query = None # Find the selected layer and selected polylines of that layer for layer in layers: desc = arcpy.Describe(layer) if desc.shapeType == "Polyline" \ and hasattr(desc, 'fidSet') and desc.fidSet: to_cut = layer sel_list = desc.fidSet.split(";") query = 'FID IN (' for sel_id in sel_list: if sel_id != sel_list[0]: query += "," query += sel_id query += ')' break if to_cut: self.cut_geometry(to_cut.dataSource, query, line_geometry) else: pythonaddins.MessageBox("There is no selection.", "Cut Polyline Features", 0) pass
... View more
03-07-2016
02:00 AM
|
0
|
2
|
5139
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|