jamesfreddyc that sounds intresting, but how would pass the click (input) to do the selection by location on the parcels?thanks for the replay.
def onMouseDownMap(self, x, y, button, shift): mxd = arcpy.mapping.MapDocument("CURRENT") pointGeom = arcpy.PointGeometry(arcpy.Point(x, y), mxd.activeDataFrame.spatialReference) searchdistance = getSearchDistanceInches(mxd.activeDataFrame.scale) lyr = arcpy.mapping.ListLayers(mxd)[0] # assumes you want to select features from 1st layer in TOC arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", pointGeom, "%d INCHES" % searchdistance) arcpy.RefreshActiveView()
This is a new script that i am trying to build and get working. I am not sure if it's working or not because when i run it the script that i posted above ArcMap just sits there thinking and thinking, i eventually have to use task manager to close arc map. I believe my problem is that the script takes every point and every taxparcels in the spatial join instead of just the newly point and the taxparcel it sits on. but i am not 100% certain becasue my python is not very good.what i have been trying to is do a select by location on the parcel layer to see what parcel the new point sits on then populate/copy the point with certain fields from that selected parcel only.
fcTarget = "Points_3" workspace = r"C:\Temp\default.gdb" #workspace = r"C:\Users\talmeida\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Connection to dsd15_sqlexpress.sde" arcpy.env.overwriteOutput = True ####Select by location on parcels with created point Parcellyr = "testParcelsAdmit" arcpy.MakeFeatureLayer_management(Parcellyr, "Parcel layer") entries = int(arcpy.GetCount_management(fcTarget).getOutput(0)) for i in xrange(entries): arcpy.MakeFeatureLayer_management(fcTarget, "point layer", "\"OBJECTID\"={}".format(str(i))) arcpy.SelectLayerByLocation_management("Parcel layer", "INTERSECT", fcTarget, "", "NEW_SELECTION") #if arcpy.Exists(pt_lyr): arcpy.Delete_management(pt_lyr) #### populates fields add_fields = ["ACCOUNT","SiteNum","OwnerName","SiteAddres","SiteNumSfx","SiteStreet","predir","StreetType","SubName"] # fix args if not isinstance(add_fields, list): # from script tool add_fields = add_fields.split(';') # do not need this scratch file fcOutput = r'in_memory\temp_join' arcpy.SpatialJoin_analysis("Parcel layer", fcTarget, fcOutput, 'JOIN_ONE_TO_MANY', 'KEEP_COMMON') # grab oid field from points oid_t = arcpy.Describe(fcTarget).OIDFieldName # init rowW and rowR curR = arcpy.SearchCursor(fcOutput) join_dict = dict([(r.JOIN_FID,[r.getValue(f) for f in add_fields]) for r in curR]) del curR # Now update the new target curW = arcpy.UpdateCursor(fcTarget) for row in curW: t_oid = row.getValue(oid_t) if t_oid in join_dict: for f in add_fields: row.setValue(f, join_dict[t_oid][add_fields.index(f)]) curW.updateRow(row) del row, curW arcpy.Delete_management(r"in_memory\temp_join") arcpy.AddMessage('Updated all records sucussefully')
import arcpy import pythonaddins arcpy.env.overwriteOutput = True fcTarget = "Points_1" workspace = r"C:\Temp\default.gdb" DS3 = "oool" if arcpy.Exists(DS3): arcpy.Delete_management(DS3) edit = arcpy.da.Editor(workspace) # Edit session is started without an undo/redo stack for versioned data # (for second argument, use False for unversioned data) edit.startEditing(True) # Start an edit operation edit.startOperation() input = arcpy.GetParameterAsText(0) CC_list = [] with arcpy.da.SearchCursor(fcTarget, ["AddressID"]) as cursor: for row in cursor: try: if "CC" in row[0]: CC_list.append(int(row[0].strip("CC"))) except TypeError: pass del cursor CC_list.sort() AddressID = CC_list[-1] + 1 AddressID = 'CC' + str(AddressID) rows = arcpy.SearchCursor(input) for row in rows: geom = row.shape x = geom.lastPoint.X y = geom.lastPoint.Y del row, rows row_values = [(x, y, (x, y), AddressID)] cursor = arcpy.da.InsertCursor(fcTarget, ["X_Coord", "Y_Coord", "SHAPE@XY", "ADDRESSID"]) for row in row_values: cursor.insertRow(row) #del cursor Parcellyr = "testParcelsAdmit" for row in sorted(arcpy.da.SearchCursor(fcTarget, ["OID@", "AddressID"]),reverse=True): mostRecentOID=row[0] mostRecentAddressID=row[1] break #Do stuff with mostRecentOID and mostRecentAddressID arcpy.MakeFeatureLayer_management(Parcellyr, "Parcel layer") if int(arcpy.GetCount_management(fcTarget).getOutput(0)) > 0: arcpy.SelectLayerByLocation_management(fcTarget, "INTERSECT", "Parcel layer", "", "NEW_SELECTION") #### populates fields add_fields = ["ACCOUNT","SiteNum","OwnerName","SiteAddres","SiteNumSfx","SiteStreet","predir","StreetType","SubName"] # fix args if not isinstance(add_fields, list): # from script tool add_fields = add_fields.split(';') # do not need this scratch file fcOutput = 'oool' arcpy.SpatialJoin_analysis("Parcel layer",fcTarget , fcOutput, 'JOIN_ONE_TO_MANY', 'KEEP_COMMON') # grab oid field from points oid_t = arcpy.Describe(fcTarget).OIDFieldName # init rowW and rowR curR = arcpy.SearchCursor(fcOutput) join_dict = dict([(r.JOIN_FID,[r.getValue(f) for f in add_fields]) for r in curR]) del curR # Now update the new target curW = arcpy.UpdateCursor(fcTarget) for row in curW: t_oid = row.getValue(oid_t) if t_oid in join_dict: for f in add_fields: row.setValue(f, join_dict[t_oid][add_fields.index(f)]) curW.updateRow(row) del row, curW #arcpy.Delete_management(r"in_memory\temp_join") arcpy.AddMessage('Updated all records sucussefully') arcpy.RefreshActiveView() # Stop the edit operation. edit.stopOperation() # Stop the edit session and save the changes edit.stopEditing(True)
for row in sorted(arcpy.da.SearchCursor(fcTarget, ["OID@", "AddressID"]),reverse=True): mostRecentOID=row[0] mostRecentAddressID=row[1] break #Do stuff with mostRecentOID and mostRecentAddressID
import arcpy import pythonaddins arcpy.env.overwriteOutput = True fcTarget = "TT" workspace = r"Connection to sqlexpress.sde" #arcpy.ChangeVersion_management('TT','TRANSACTIONAL','dbo.DEFAULT', "") # Start an edit session. Must provide the worksapce. edit = arcpy.da.Editor(workspace) # Edit session is started without an undo/redo stack for versioned data # (for second argument, use False for unversioned data) edit.startEditing(True) # Start an edit operation edit.startOperation() input = arcpy.GetParameterAsText(0) CC_list = [] with arcpy.da.SearchCursor(fcTarget, ["AddressID"]) as cursor: for row in cursor: try: if "CC" in row[0]: CC_list.append(int(row[0].strip("CC"))) except TypeError: pass del cursor CC_list.sort() AddressID = CC_list[-1] + 1 AddressID = 'CC' + str(AddressID) rows = arcpy.SearchCursor(input) for row in rows: geom = row.shape x = geom.lastPoint.X y = geom.lastPoint.Y del row, rows row_values = [(x, y, (x, y), AddressID)] cursor = arcpy.da.InsertCursor(fcTarget, ["X_Coord", "Y_Coord", "SHAPE@XY", "ADDRESSID"]) for row in row_values: cursor.insertRow(row) #del cursor Parcellyr = "testParcelsAdmit" #maxValue = arcpy.SearchCursor(fcTarget, "", "", "", 'AddressID D').next().getValue("AddressID") #Get 1st row in descending cursor sort #arcpy.SelectLayerByAttribute_management(fcTarget, "NEW_SELECTION", "\"AddressID\"= " + maxValue) Par_lyr = arcpy.MakeFeatureLayer_management(Parcellyr, "Parcel layer") entries = int(arcpy.GetCount_management(fcTarget).getOutput(0)) for i in xrange(entries): arcpy.MakeFeatureLayer_management(fcTarget, "point layer", "\"OBJECTID\"={}".format(str(i))) arcpy.SelectLayerByLocation_management(Par_lyr, "INTERSECT", fcTarget, "", "NEW_SELECTION") #if arcpy.Exists(pt_lyr): arcpy.Delete_management(pt_lyr) #### populates fields add_fields = ["ACCOUNT","SiteNum","OwnerName","SiteAddres","SiteNumSfx","SiteStreet","predir","StreetType","SubName"] # fix args if not isinstance(add_fields, list): # from script tool add_fields = add_fields.split(';') # do not need this scratch file fcOutput = r'in_memory\temp_join' arcpy.SpatialJoin_analysis(Par_lyr, fcTarget, fcOutput, 'JOIN_ONE_TO_MANY', 'KEEP_COMMON') # grab oid field from points oid_t = arcpy.Describe(fcTarget).OIDFieldName # init rowW and rowR curR = arcpy.SearchCursor(fcOutput, query) join_dict = dict([(r.JOIN_FID,[r.getValue(f) for f in add_fields]) for r in curR]) del curR # Now update the new target curW = arcpy.UpdateCursor(fcTarget) for row in curW: t_oid = row.getValue(oid_t) if t_oid in join_dict: for f in add_fields: row.setValue(f, join_dict[t_oid][add_fields.index(f)]) curW.updateRow(row) del row, curW arcpy.Delete_management(r"in_memory\temp_join") arcpy.AddMessage('Updated all records sucussefully') arcpy.RefreshActiveView() # Stop the edit operation. edit.stopOperation() # Stop the edit session and save the changes edit.stopEditing(True)
I have a script that creates a point with a mouse click (onMouseDownMap). The feature class is in a SDE geodatabase which has about 80,000 features in it. An edit session and an edit operation is needed, creating the point work just fine but i need some code after stopping the edit session to select the point that was just created to be able to pass to another function. The problem with starting the an edit session and an edit operation is that it clears the selection.Any help would be awesome!Thanks.
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.