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
`
Answer
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:
- define both input fc as parameter variables
- convert both fc to feature layers
- define two search cursors/for loops on fc1 adn fc2 against the ID field
- 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
- use the append method to append the erased feature to a result fc
- 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.
No comments:
Post a Comment