2

This is the challenge: I have two feature classes, which have the same number of polygon features, that when overlaid form concentric "rings." I need to erase the inner circle from the outer circle for each feature, matching them by their record ID. So, if both feature classes 1 and 2 have records A, B, and C, I want to erase the polygon of Record A in FC2 from Record A in FC1, RecordB in FC2 from Record B in FC1, etc.

ArcGIS' Erase function will only take the entirety of the feature class and erase from them - I can't find a way to link up records by their feature ID. I'm working with Arc10.1 with all licenses.

LATEST EDITS: I've replaced the useless code from before with this revised snippet below, but now I need a bit of guidance - I can't find where in here that I am over-writing the output. It works! However the script leaves me with a single donut feature output. Can you help me spot my error?

#Test script: select record from a VTR and erase it from another, matching selected record

import os
import sys
import arcpy
from arcpy import env
import time

#Set overwrote output
arcpy.env.overwriteOutput = True
print arcpy.env.overwriteOutput

workspace = "C:\\BOEM\\pt_buff3\\"


fileList = []
buffersd4 = []
buffersd3 = []
recordID3 = []
recordID4 = []

buffs = workspace+"buffer.gdb"
directorypath = buffs

#create new results_feature class

for dirpath, dirnames, buffs in arcpy.da.Walk(directorypath,
                                              datatype="FeatureClass",
                                              type="Polygon"):
for buff in buffs:

    if buff.endswith(str("d4")):
       # buffersd4.append(buff)
        #print buffersd4
       print buff
       buffbits4=buff.split('_')
       print buffbits4[2]
       buffersd4.append(buff)
       field = ['APR16_ID']
       APR16_ID = [row[0] for row in arcpy.da.SearchCursor(workspace+"buffer.gdb\\"+buff,(field))]
       print APR16_ID
       for ID4 in APR16_ID:
           ID4split = ID4.split('_')
           selectID4 = ID4split[1]
           #print selectID4

    if buff.endswith(str("d3")):
       # buffersd4.append(buff)
        #print buffersd4
       print buff
       buffbits3=buff.split('_')
       print buffbits3[2]
       buffersd3.append(buff)
       field = ['APR16_ID']
       APR16_ID = [row[0] for row in arcpy.da.SearchCursor(workspace+"buffer.gdb\\"+buff,(field))]
       print APR16_ID
       for ID3 in APR16_ID:
           ID3split = ID3.split('_')
           selectID3 = ID3split[1]
          # print selectID3
print selectID4
print selectID3
if selectID4 == selectID3:
    print "yay they match!"

    #make feature layer of feature d4 for FCs in buffersd4:
    for fc in buffersd4:
        in_feat=workspace+"buffer.gdb\\"+fc
        out_layer4= fc+"_lyr"
        arcpy.MakeFeatureLayer_management(in_feat,out_layer4)
        print arcpy.GetMessages()
    #select record in fc_layer
        #where_clause4=""" "APR16_ID" = """ + str(selectID4)
        where_clause4=""" "APR16_ID" = """ + "'"+ID4+"'"
        arcpy.SelectLayerByAttribute_management(out_layer4,"NEW_SELECTION",where_clause4)
        print arcpy.GetMessages()

    #make feature layer of feature d3
    for fc in buffersd3:
        in_feat=workspace+"buffer.gdb\\"+fc
        out_layer3= fc+"_lyr"
        arcpy.MakeFeatureLayer_management(in_feat,out_layer3)
        print arcpy.GetMessages()
    #select record in fc_layer
        #where_clause3=""" "APR16_ID" = """ + str(selectID3)
        where_clause3=""" "APR16_ID" = """ + "'"+ID3+"'"
        arcpy.SelectLayerByAttribute_management(out_layer3,"NEW_SELECTION",where_clause3)
        print arcpy.GetMessages()

 #execute Erase function(erase d3 from d4)
        out_feat = "C:\\BOEM\\Donuts\\donuts_output.gdb\\"+"donut_d4_"+ID4
        arcpy.Erase_analysis(out_layer4, out_layer3,out_feat,"")
        print arcpy.GetMessages()

    print "done rolling through records in this feature class."

    print "done going through the buffers in the fGDB"


    #celebrate





            `

I hope this handy diagram will help illustrate what the heck I'm trying to do...

4
  • 2
    I'm a little confused, but I'm thinking you could "select by attributes" if you want to select by their record ID, or to select the polygon inside the other by using "select by location". Or I could be missing the point by a mile, a screenshot would help (me at least).
    – Pete
    Commented Jun 18, 2013 at 21:00
  • I agree with @Pete - perhaps a diagram could explain your requirement better - the tool I think you may want to consider is Select_analysis.
    – PolyGeo
    Commented Jun 18, 2013 at 21:35
  • @SharonB, Once you get the first ID value from the first cursor you can embed another cursor within that cursor, or better yet write a separate function that is called within the first cursor to search within the second fc that compares ID values.
    – artwork21
    Commented Jun 19, 2013 at 17:07
  • @artwork21 - Would you mind pointing towards good resources for writing these functions? I'm a little stuck on actually implementing your suggestion to "write a separate function that is called within the first cursor to search within the second fc" - but that is the I'm pretty sure best way to do it....
    – SharonB
    Commented Jun 19, 2013 at 17:14

2 Answers 2

2

This is a bit more complex than the out of the box geoprocessing tools. I would suggest for you to write python script/tool to achieve this. The script workflow would go something like this:

  1. define both input fc as parameter variables
  2. convert both fc to feature layers
  3. define two search cursors/for loops on fc1 adn fc2 against the ID field
  4. use conditional logic to find the common ID values, e.g. if fc1 ID == fc2 ID then select both records using select layer by attribute method, followed by the erase method
  5. use the append method to append the erased feature to a result fc
  6. continue looping until all features are appended to the same result fc

If you are not familar with python you could use ModelBuilder to perform these same geoprocessing tasks using conditional logic to check the selection cases.

4
  • I'm still hoping to see diagram from @sharonb because your pseudo code looks like something Union followed by Select might be able to accomplish.
    – PolyGeo
    Commented Jun 19, 2013 at 1:41
  • Hi all, thanks for the great comments. and really well thought out answers. Sorry for not including a diagram initially, but sleeping on it helped me realize that @artwork21 has exactly the right concept here. I will be developing a python script for this and will be glad to post it here when I get it running. Thanks again all!
    – SharonB
    Commented Jun 19, 2013 at 12:58
  • 1
    Seems like using an output featurecursor to write individual polygons resulting from the Polygon Difference method would be easier than doing the erase. Commented Jun 19, 2013 at 14:26
  • Kirk - this is a good option I didn't know about. I will explore and see if this works for my situation - thank you.
    – SharonB
    Commented Jun 19, 2013 at 14:36
0

Please check out the link to the follow up from this question, where I answer the question with a complete, functional script.

Improve Python script logic/structure for erasing features with arcpy

Your Answer

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

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