I'm interested in updating a field in geodatabase feature classes based on their location in relation to another feature class in the geodatabase, but without having to perform a join (and therefore creating another feature class).
I've got a polygon feature class ("boundaries") and then multiple point and line features that fall within those boundaries ("fieldData," "streams," "origins"). All of the features, once loaded to the database, have a common field labeled "siteCode" that I would like to populate programmatically rather than manually doing a Select by Location and calculating the fields (or creating extra files like performing a join). Better yet, I would like this to occur as the point and line files are loaded to the geodatabase, but that's not necessary. None of the files have this information stored in their attributes prior to being loaded to the database, but the siteCode is the first two letters in the name of each source shapefile.
As it stands now, I select a feature in the "boundaries" feature class, Select by Location on each of the other files one at a time, and populate the fields using Calculate Field.
I am open to any suggestions for workflow improvement here! My experience is limited with Python but I am interested in learning. If people respond with Python suggestions I would just ask that they include as much information as possible! I feel like this must have been answered a million times but I'm seeing a lot about using a join and not many ways to avoid it.
Also: There is this posting that appears to be accomplishing something similar but I'm too much of a novice to understand exactly what it's doing and if it will do what I need. If someone can confirm that some variation on that code will work for me I will dive in and figure it out!
#Make a feature layer for the neighourhoods arcpy.MakeFeatureLayer_management(neighbourhood, "neighbourhoodLayer") arcpy.MakeFeatureLayer_management(parcel, "parcelLayerTest1") #Setup cursor to update new NBHD field with arcpy.da.UpdateCursor(parcel, (parcelIDField,nbhdField)) as parRows: for par in parRows: # Create a query string for the current patrol zone #parcelIDstring = par #queryString = '"' + str(parcelIDField) + '" =' + "'" + str(parcelIDstring) + "'" #Select parcels based on location contained within neighbourhood arcpy.SelectLayerByLocation_management("parcelLayerTest1", "HAVE_THEIR_CENTER_IN", neighbourhood) nbhdTable = arcpy.SearchCursor(neighbourhood) for nbhd in nbhdTable: nbhdValue = nbhd.getValue("Neighbourh") if nbhdValue: par = nbhdValue parRows.updateRow(par)
Thanks in advance for any assistance.