7

I would like to assign a unique ID to polygons in a dataset. The catch to my issue is that I would like polygons that fall within a polygon to have the same unique ID. My example is related to buildings. I have many buildings in a dataset. Each building should have a unique ID, however, buildings that are comprised of multiple polygons (see graphic) should have the same unique ID. I know of a way to do this through a series of dissolves, and spatial joins, but I would like to do this in a calculation.

My preference is to do this in ArcMap.

enter image description here

Here is a graphic of what I am hoping to resolve. All touching polygons have the same ID. This is unique in the entire dataset, not with the building that is shown.

enter image description here

0

1 Answer 1

2

I would assume you would need to write a Python script that will parse through all features within that shapefile.

Each time it comes to a new feature, it would need to check for a unique id. If it doesn't exist, it would create one.

Next, it would run a query to check for features that... either share a boundary, common line segment, etc. There are options in the Select By Location tool in ArcMap. They should be accessible in Python, too. With those features, it copies over the unique id to those features and moves on.

Eventually, it should get to the point where all features that meet the spatial query you are using share a common unique id.

I am assuming that the topology isn't incorrect, and that there aren't small spaces in between polygons too.


The way I would try going about this is using the Select by Attributes tool/script to select a feature based on the FID (just a way to work yourself through the features.. start low and move up) and if it lacks a unique id.

From there, I would use the Select By Location tool/script to add to current selected features within the same layer that either touch a boundary or intersect. Here I would check what version of ArcMap you have and what options are available. The Esri documentation has some decent information for each version.

Now to actually work with the selected features seems a bit tricky. Check out this post (http://forums.arcgis.com/threads/43214-select-by-location-and-calculate-field-from-update-cursor-row-help) since it has details on ways to access the selected features and other suggestions. There is also another suggestion from Using selection of features in ArcMap in Python script?. Each of these does it in a different way, but they should provide you an idea of how to go about doing it.

From there, you use the Update Cursor to update the unique id field to whatever you'd like and loop until there are no more features that need updating.

I am sure there are some things I am missing and some features that may not be selected in this process. I would suggest trying it out and seeing what the results are then adjusting the selection process in the select by location part. A couple of tweaks and maybe an hour or so of coding/reading should get you on the right track.

It might be easier to try building this visually in ModelBuilder since you can just drag and drop tools and use the 'magic wand' to connect them. It might make flow easier to visually see.

For the Select By Attribute, Select By Location, and Update Cursor information, just Google “arcpy” and the name to find the Esri documentation.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.