Hello
I want to make a script in ArcGis desktop 10.8 for a simple procedure, write for each zone the province that intersects.
The desired result is for the zone layer to have a text field with the names of the province(s) it intersects.
- The zone layer has 1008 records
- the province layer has 51 records.
So far, the options have not been optimal, I detail them below
These are my questions:
- Is there an optimal way to perform this procedure and to program it?
- Does the evaluation of the spatial relations for example: polygon.contains(polygon) use the spatial index or should I activate it?
- How can I perform this process using the spatial index?
For this I am writing two scripts, the first attempt was:
- create a cursor on the zones layer
- select the feature with using its ID with arcpy.SelectLayerByAttribute_management
- then select by location with the provinces
- apply a cursor over the selected to get the list of provinces that will write in the attribute
The problem: this takes too long
Second attempt:
- I create an empty dictionary
- apply a cursor on zones getting the shape field and OBJECTID
- Iterate with a for
- for each case I create a province cursor
- iterate on the provinces
- I evaluate which provinces intersect the zone, in the dictionary I store the id of the zone as a key with a list of the provinces. For this I evaluate if the geometry of zones intersects the province geometry, For example: zona.overlap(province)
The problem: it still takes a long time, 1.8 minutes for 40 zone and they are 1008