Select to view content in your preferred language

Generate ID from grid using centroid

3211
4
09-24-2014 08:00 AM
GeorgeMiddlebrook
Emerging Contributor

I am trying to auto generate tract numbers based upon where they fall in a grid system (actually abstracts in Texas).  My problem is that where a tract joins a grid boundary (very common in this dataset), I get the first value it finds, even though it may be completely contained within the the second grid.  I have used the Intersection Features tool with the centroid option in the past, but I manually had to update the ID. 

Is there any way to use the GENERATE_ID_BY_INTERSECT method with centroids?  Is it possible to edit the code to change this to centroid (all the time would be fine for me) like the INTERSECTING_FEATURE method?

Or is there a way to do this as a two step process, INTERSECTING_FEATURE to pull the gridID first, and then GENERATE_ID (or some other method) to pull an ID from the GenerateID table from the row for that GridID

I am running ArcGIS Standard 10.2.2 with the AA 10.2.0.4

George

0 Kudos
4 Replies
GeoffOlson
Regular Contributor

Have you tried the option "Have Their Centroid In?"

arcpy.SelectLayerByLocation_management("Grid", "HAVE_THEIR_CENTER_IN", "Tract", "0 FEET", "NEW_SELECTION")

0 Kudos
GeorgeMiddlebrook
Emerging Contributor

I really want to use the Attribute Assistant to do this, as we will be adding new tracts all the time.  Is there a way customize AA with ArcPy?

0 Kudos
GeorgeMiddlebrook
Emerging Contributor

EDIT:  Attribute Assistant 10.2.0.4

0 Kudos
GeoffOlson
Regular Contributor

My use of Attribute Assistance is very limited.  My knowledge of Python is relatively small, but one thing I've done several times is customizing a script to move attribute data from one feature class to another based on spatial selection.  I use a search cursor to loop through the layer of data I need extracted, then I query that layer in the loop, followed by a select by location and field calculation.  Then I remove the definition query at the end of the loop.  This is what I'm using right now to do something similar - I think.

mxd = arcpy.mapping.MapDocument("Current")# Define mxd to current file.

townships = arcpy.da.SearchCursor("Townships", "name")

for township in townships:

  tName = township[0]

  cName = '''"{0}"'''.format(tName)

  mapLyr1.definitionQuery = """"name" = '{0}'""".format(tName)

  arcpy.SelectLayerByLocation_management("Layer2", "INTERSECT", "Townships", "0 FEET", "NEW_SELECTION")

  arcpy.CalculateField_management("Layer2", "Jurisdicti", cName, "PYTHON")

  mapLyr1.definitionQuery = None

This takes the township name and places in Layer2's field.  You can do many things with this basic setup, though it can take some time to run when there are hundreds or thousands of features.