Skip to main content
added 1225 characters in body
Source Link
SharonB
  • 725
  • 1
  • 6
  • 19

Please help resolveThis is the following 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.

EDITLATEST EDITS: The following is a draft of I've replaced the useless code I'm having trouble editing. I'mfrom before with this revised snippet below, but now I need a novice Pythonbit of guidance -ista and my issue is I can't find where in developing/managing two SearchCursors athere that I am over-writing the same time? .output. It works! However the script leaves me with a single donut feature output.any takers to Can you help me get this rollingspot 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")):#buffbits=buff
       # buffersd4.splitappend('_'buff)
        #print buffersd4
   #inputfc4 =   print buff
       buffbits4=buff.endswithsplit("d4"'_')
       print buffbits4[2]
      inputfc4bit=inputfc4 buffersd4.splitappend('_'buff)
 
        inputfc3field = buff.endswith("d3")['APR16_ID']
       APR16_ID inputfc3bit=inputfc3= [row[0] for row in arcpy.splitda.SearchCursor('_'workspace+"buffer.gdb\\"+buff,(field))]
       print APR16_ID
       for ifID4 inputfc4bit[2]==in inputfc3bit[2]APR16_ID:
           ID4split #convert= inputfc4ID4.split('_')
 and inputfc3 to feature layers
      selectID4 = ID4split[1]
    #MakeFeatureLayer_management(in_feat, out_layer, [where_clause}, {workspace},{field_infp})
    #print selectID4

    if buff.endswith(str("d3")):
  in_feat4 = buffs+inputfc4   # buffersd4.append(buff)
        #print buffersd4
   out_feat4 = in_feat4+"_lyr"  print buff
       buffbits3=buff.split('_')
      in_feat3 =print buffs+inputfc3buffbits3[2]
       buffersd3.append(buff)
     out_feat3  field = in_feat3+"_lyr"['APR16_ID']
       APR16_ID = [row[0] for row in arcpy.MakeFeatureLayer_managementda.SearchCursor(in_feat4workspace+"buffer.gdb\\"+buff,out_feat4(field))]
       print APR16_ID
    arcpy   for ID3 in APR16_ID:
           ID3split = ID3.MakeFeatureLayer_managementsplit(in_feat3,out_feat3'_')
 
           selectID3 #searchcursor= forID3split[1]
 APR16ID in inputfc4 to match APR16Id in inputfc3
  # print selectID3
print selectID4
print selectID3
if selectID4 == selectID3:
   #SearchCursor(in_table, field_names,{where_clause},"","","")
print "yay they match!"
     
    #make feature layer #where_clause=of """feature "APR16_ID"d4 =for """FCs +in 
 buffersd4:
    for fc in buffersd4:
     record_fc4 = arcpy in_feat=workspace+"buffer.SearchCursor(out_feat4,gdb\\"+fc
 "APR16_ID", "","","")
      out_layer4= fc+"_lyr"
     record_fc3 =  arcpy.SearchCursorMakeFeatureLayer_management(out_feat3, "APR16_ID","",""in_feat,""out_layer4)
        print arcpy.GetMessages()
   if record_fc3.APR16_ID#select ==record record_fc4.APR16_ID:
in fc_layer
        #where_clause4=""" "APR16_ID" = """ + str(selectID4)
  #select layer by attribute
   where_clause4=""" "APR16_ID" = """ + "'"+ID4+"'"
        #SelectLayerByAttribute_managementarcpy.SelectLayerByAttribute_management(in_layerout_layer4, {selection_type}"NEW_SELECTION", {where_clause}where_clause4)
        print arcpy.GetMessages()
       
 in_layer3 = out_feat3
 #make feature layer of feature d3
    for fc in buffersd3:
   in_layer4 = out_feat4   in_feat=workspace+"buffer.gdb\\"+fc
        out_layer3= fc+"_lyr"
        arcpy.SelectLayerByAttribute_managementMakeFeatureLayer_management(in_layer3in_feat,out_layer3)
 "NEW_SELECTION","",""       print arcpy.GetMessages()
    #select record in fc_layer
        #where_clause3=""" "APR16_ID" = """ + str(selectID3)
        where_clause3=""" "APR16_ID" = """ + "'"+ID3+"'"
        arcpy.SelectLayerByAttrbiute_managementSelectLayerByAttribute_management(in_layer4out_layer3, "NEW_SELECTION","",""where_clause3)
        print arcpy.GetMessages()
   #erase funtion
 #execute Erase function(erase d3 from d4)
      erase_from  out_feat = in_layer4"C:\\BOEM\\Donuts\\donuts_output.gdb\\"+"donut_d4_"+ID4
        arcpy.Erase_analysis(out_layer4, out_layer3,out_feat,"")
   erase_feat = in_layer3   print arcpy.GetMessages()
         
    results_fcprint ="done workspace+"donuts_outputrolling through records in this feature class.gdb""

    print "done going through the buffers in the arcpy.Erase_analysis(erase_from,fGDB"
 erase_feat, results_fc,'')   

    #celebrate
   
         
    
      
        
            
            `

Please help resolve the following 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.

EDIT: The following is a draft of code I'm having trouble editing. I'm a novice Python-ista and my issue is in developing/managing two SearchCursors at the same time? ...any takers to help me get this rolling?

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

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


fileList = []
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("d4"):#buffbits=buff.split('_')
            #inputfc4 = buff.endswith("d4")
            inputfc4bit=inputfc4.split('_')
 
        inputfc3 = buff.endswith("d3")
        inputfc3bit=inputfc3.split('_')

        if inputfc4bit[2]== inputfc3bit[2]:
            #convert inputfc4 and inputfc3 to feature layers
            #MakeFeatureLayer_management(in_feat, out_layer, [where_clause}, {workspace},{field_infp})
            in_feat4 = buffs+inputfc4
            out_feat4 = in_feat4+"_lyr"
            in_feat3 = buffs+inputfc3
            out_feat3 = in_feat3+"_lyr"
            arcpy.MakeFeatureLayer_management(in_feat4,out_feat4)
            arcpy.MakeFeatureLayer_management(in_feat3,out_feat3)
 
            #searchcursor for APR16ID in inputfc4 to match APR16Id in inputfc3
            #SearchCursor(in_table, field_names,{where_clause},"","","")
            #where_clause= """ "APR16_ID" = """ + 
 
            record_fc4 = arcpy.SearchCursor(out_feat4, "APR16_ID", "","","")
            record_fc3 = arcpy.SearchCursor(out_feat3, "APR16_ID","","","")
            if record_fc3.APR16_ID == record_fc4.APR16_ID:
                #select layer by attribute
                #SelectLayerByAttribute_management(in_layer, {selection_type}, {where_clause})
                in_layer3 = out_feat3
                in_layer4 = out_feat4
                arcpy.SelectLayerByAttribute_management(in_layer3, "NEW_SELECTION","","")
                arcpy.SelectLayerByAttrbiute_management(in_layer4, "NEW_SELECTION","","")
            #erase funtion
            erase_from = in_layer4
            erase_feat = in_layer3
            results_fc = workspace+"donuts_output.gdb"

            arcpy.Erase_analysis(erase_from, erase_feat, results_fc,'')                    
             
            
            `

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
   
         
         
        
           
            `
added 2839 characters in body
Source Link
SharonB
  • 725
  • 1
  • 6
  • 19

Any suggestions are very much appreciated. I'm working with Arc10.1 with all licenses.

EDIT: The following is a draft of code I'm having trouble editing. I'm a novice Python-ista and my issue is in developing/managing two SearchCursors at the same time? ...any takers to help me get this rolling?

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

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


fileList = []
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("d4"):#buffbits=buff.split('_')
            #inputfc4 = buff.endswith("d4")
            inputfc4bit=inputfc4.split('_')

        inputfc3 = buff.endswith("d3")
        inputfc3bit=inputfc3.split('_')

        if inputfc4bit[2]== inputfc3bit[2]:
            #convert inputfc4 and inputfc3 to feature layers
            #MakeFeatureLayer_management(in_feat, out_layer, [where_clause}, {workspace},{field_infp})
            in_feat4 = buffs+inputfc4
            out_feat4 = in_feat4+"_lyr"
            in_feat3 = buffs+inputfc3
            out_feat3 = in_feat3+"_lyr"
            arcpy.MakeFeatureLayer_management(in_feat4,out_feat4)
            arcpy.MakeFeatureLayer_management(in_feat3,out_feat3)

            #searchcursor for APR16ID in inputfc4 to match APR16Id in inputfc3
            #SearchCursor(in_table, field_names,{where_clause},"","","")
            #where_clause= """ "APR16_ID" = """ + 

            record_fc4 = arcpy.SearchCursor(out_feat4, "APR16_ID", "","","")
            record_fc3 = arcpy.SearchCursor(out_feat3, "APR16_ID","","","")
            if record_fc3.APR16_ID == record_fc4.APR16_ID:
                #select layer by attribute
                #SelectLayerByAttribute_management(in_layer, {selection_type}, {where_clause})
                in_layer3 = out_feat3
                in_layer4 = out_feat4
                arcpy.SelectLayerByAttribute_management(in_layer3, "NEW_SELECTION","","")
                arcpy.SelectLayerByAttrbiute_management(in_layer4, "NEW_SELECTION","","")
            #erase funtion
            erase_from = in_layer4
            erase_feat = in_layer3
            results_fc = workspace+"donuts_output.gdb"

            arcpy.Erase_analysis(erase_from, erase_feat, results_fc,'')                    
            
            
            `

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

Any suggestions are very much appreciated. I'm working with Arc10.1 with all licenses.

I'm working with Arc10.1 with all licenses.

EDIT: The following is a draft of code I'm having trouble editing. I'm a novice Python-ista and my issue is in developing/managing two SearchCursors at the same time? ...any takers to help me get this rolling?

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

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


fileList = []
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("d4"):#buffbits=buff.split('_')
            #inputfc4 = buff.endswith("d4")
            inputfc4bit=inputfc4.split('_')

        inputfc3 = buff.endswith("d3")
        inputfc3bit=inputfc3.split('_')

        if inputfc4bit[2]== inputfc3bit[2]:
            #convert inputfc4 and inputfc3 to feature layers
            #MakeFeatureLayer_management(in_feat, out_layer, [where_clause}, {workspace},{field_infp})
            in_feat4 = buffs+inputfc4
            out_feat4 = in_feat4+"_lyr"
            in_feat3 = buffs+inputfc3
            out_feat3 = in_feat3+"_lyr"
            arcpy.MakeFeatureLayer_management(in_feat4,out_feat4)
            arcpy.MakeFeatureLayer_management(in_feat3,out_feat3)

            #searchcursor for APR16ID in inputfc4 to match APR16Id in inputfc3
            #SearchCursor(in_table, field_names,{where_clause},"","","")
            #where_clause= """ "APR16_ID" = """ + 

            record_fc4 = arcpy.SearchCursor(out_feat4, "APR16_ID", "","","")
            record_fc3 = arcpy.SearchCursor(out_feat3, "APR16_ID","","","")
            if record_fc3.APR16_ID == record_fc4.APR16_ID:
                #select layer by attribute
                #SelectLayerByAttribute_management(in_layer, {selection_type}, {where_clause})
                in_layer3 = out_feat3
                in_layer4 = out_feat4
                arcpy.SelectLayerByAttribute_management(in_layer3, "NEW_SELECTION","","")
                arcpy.SelectLayerByAttrbiute_management(in_layer4, "NEW_SELECTION","","")
            #erase funtion
            erase_from = in_layer4
            erase_feat = in_layer3
            results_fc = workspace+"donuts_output.gdb"

            arcpy.Erase_analysis(erase_from, erase_feat, results_fc,'')                    
            
            
            `

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

edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Source Link
SharonB
  • 725
  • 1
  • 6
  • 19
Loading