samedi 24 janvier 2015

Overwriting layers in a geodatabase maintaining its position in a feature class list [on hold]


I'm working with ArcGIS 10. I work on ecological habitat mapping. I have some features classes inside a geodatabase which represent years of data on a specific area. Each has a reliability field with a value from 0 to 10. What I want to do is getting a map of the most accurate habitat data without overlaps. To do so, I'm looping through the layers of the geodatabase couple by couple. For each couple, I test intersection, and if there is some, depending on the reliability value, I perform an erase task where the layer with the lowest reliability value is erased by the layer with the higher reliability value.


The problem is that each time a layer is erased, I want to replace the previous non erased layer by the new erased layer at the same place in the list of layers. Indeed, I need to reuse the last erased layer if there is a new erase task to perform. But in the code below, I don't succeed at replacing the obsolete layer by the erased one.


I have differents errors : 1. I have a "same name error" while I authorize overwriting. 2.If I change the name, the output is at the end of the list and I don't succeed at moving it at the right place in the list.


Here is the code :



import arcpy, os
arcpy.env.overwriteOutput = True
arcpy.env.workspace = arcpy.GetParameterAsText(0)
fcList = arcpy.ListFeatureClasses()
count = 0 #help select the a feature class
cnt = 1 #help select the b feature class
tList = len(fcList) #Count the number of elements in the list
for count in range(tList - 1):
for cnt in range(cnt,tList):
desca = arcpy.Describe(fcList[count])
descb = arcpy.Describe(fcList[cnt])
namea = desca.baseName # Get the name of the a feature to name the out_poly
nameb = descb.baseName # Get the name of the b feature to name the out_poly
arcpy.MakeFeatureLayer_management(os.path.join(arcpy.env.workspace, fcList[count]), "fca")
arcpy.MakeFeatureLayer_management(os.path.join(arcpy.env.workspace, fcList[cnt]), "fcb")
arcpy.SelectLayerByAttribute_management("fca","NEW_SELECTION")
arcpy.SelectLayerByLocation_management("fcb","INTERSECT","fca")


if arcpy.Describe("fcb").FIDSet: #Check for selection
rowa = arcpy.SearchCursor("fca")
rowb = arcpy.SearchCursor("fcb")
for row in rowa:
fiabia = row.fiabilite #get the int value of reliability (all entities of a layer have the same)
for rows in rowb:
fiabib = rows.fiabilite

if fiabia > fiabib:
out_poly = nameb
fcList[cnt] = arcpy.Erase_analysis("fcb","fca", out_poly) #the new fc is added to the end of the list while it should be at the "count" level of the list.

fcList = arcpy.ListFeatureClasses()
#arcpy.Delete_management(fcList[cnt])
#arcpy.FeatureClassToGeodatabase_conversion("fcb",fcList[cnt])
#arcpy.Rename_management(out_poly, fcList[cnt])



if fiabia < fiabib:
out_poly = namea
fcList[count] = arcpy.Erase_analysis("fca","fcb", out_poly)
arcpy.Delete_management(fcList[count])
fcList = arcpy.ListFeatureClasses()
#arcpy.FeatureClassToGeodatabase_conversion("fca",fcList[count])
#arcpy.Rename_management(out_poly, fcList[count])

else:
count = count + 1
cnt = cnt + 1


I don't understand why I can't proper update the fcList. If I try with a random list, for example, I can easily change any element of the list :



rlist = [a,b,c,d]
rlist[0] = z
print rlist
[z,b,c,d]


Why is it different with my layers ?





Aucun commentaire:

Enregistrer un commentaire