I will try to be as detailed as I can with the purpose and walkthrough of the situation.

I have 2 Feature Classes (fc1 and fc2).

fc1 is a polygon shapefile with no overlapping polygons and an id for each polygon on field code (Int)

fc2 is a polygon shapefile with overlapping polygons and an id for each polygon on field pcode (String)

I want to find for each polygon in fc1 the pcode that covers it the most. If more than one pcodes covers it the most, then I pick the pcode that is sorted FIRST.

In order to find a way through this, I wrote a code with the following steps and it produces the result that I want.

from collections import OrderedDict
F = OrderedDict([])
arcpy.MakeFeatureLayer_management('Test1','Test2','"code" <> -1')
with arcpy.da.UpdateCursor('Test3',['SHAPE@AREA','area']) as cursor:
    for row in cursor:
        row[1] = row[0]
arcpy.Sort_management('Test3','Test4','code ASCENDING;area DESCENDING;pcode ASCENDING')
with arcpy.da.SearchCursor('Test5',['FIRST_pcode','code']) as cursor:
    for row in cursor:
with arcpy.da.UpdateCursor(fc1,['code','pcode']) as cursor:
    for row in cursor:
        row[1] = F[row[0]]

The previous version of my question was posted because I was looking for a faster way because the above code takes about 6 minutes to finish.

From my search here and in other websites, I didn't find anything that can alter Dissolve with sth else unless someone has sth to suggest (it is the most time consuming process here).

For the rest, I didn't manage to find anything, so I hope you can help me out with this.

Supplemental for @radouxju comment:

I used the Tabulated Intersection tool but for some reason it miscalculates the area and the results are not correct. The polygon with code "4" is completely covered by the polygons with pcode 45194229099040 and 45194229099039 but the tool understands that it is partly covered. See the image below:

Miscalculation of Tabulated Intersection tool

As you can see there is a difference on the 3rd decimal and because of this the Summary Statistics selects the incorrect pcode (in this case 45194229099040 instead of 45194229099039).

  • Have you looked at the Summary Statistics tool? – PolyGeo Jun 2 '16 at 11:25
  • Yes, but I don't know if am using it correctly. How would you use it? – Panos Jun 2 '16 at 11:45
  • Without seeing some sample records as part of your question it is not possible to advise. I recommend experimenting with your data to see what different summary and case fields can do for you. – PolyGeo Jun 2 '16 at 11:49
  • The case field must be one the code and nothing else. When I put anything else it produces a table with more records than the wanted one. The statistics fields are the other two. I put them one by one, together, I changed the order of them with no luck. – Panos Jun 2 '16 at 11:59
  • I made a zip file with the sample you asked and the result that I want. Sample. I hope that will help! – Panos Jun 2 '16 at 12:22

I think that there is a simple way to achieve this :

Create a new fild to concatenate code and pcode ( str(!code!) + "_" + !pcode!)

Use summary statistics to get the maximum area value for each unique code_pcode

Join this value to the initial table (based on code field)

if necessary, select the rows where area = max_area

  • Unfortunately, it does not work either. Any other ideas? – Panos Jun 2 '16 at 12:38
  • this should definitely work, or I don't understand what you want to achieve. What step is not working ? – radouxju Jun 3 '16 at 5:45
  • All steps are working but the final result is not the wanted one. – Panos Jun 3 '16 at 5:47
  • It would be easier to understand with an example. In my case with A A 300, A B 400, A B 500 you find A B 500. Isn't it what you need ? – radouxju Jun 3 '16 at 5:51
  • On my last comment above I have a zip file with 2 tables. The sample is what I have and the result is what I want. When I implemented what you have suggested, I don't get the result I want. – Panos Jun 3 '16 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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