def spatialsort (inlayer, outfc, nutsvalue):
# (temp FC, spatial sort, add field, calc OID, atribuir valor join, ...)
# temp fc Nome
tempfcnome = tempfd + "\\SORT" + nutsvalue
tempfcnome2 = "SORT" + nutsvalue
if gp.Exists(tempfcnome):
gp.Delete_management(tempfcnome, "")
gp.Sort_management(inlayer, tempfcnome, "SHAPE ASCENDING", "PEANO")
# Adicionar campo SORT
gp.AddField_management(tempfcnome, "SORT_TEMP_ID", "LONG", 6)
# Calcular campo
# nao seria necessario pode fazer o calculate a partir OBJECTID original
gp.CalculateField_management(tempfcnome, "SORT_TEMP_ID", "!OBJECTID!","PYTHON")
# Adicionar Join
joinField = "GRD_NEWID"
fieldList = ["SORT_TEMP_ID"] # OBJECTID
# criar table view (alternative to using featurelayer):
theDesc = gp.Describe(inlayer)
gp.MakeTableView_management (theDesc.catalogPath, "temptableview")
theDesc = gp.Describe(tempfcnome)
gp.MakeTableView_management (theDesc.catalogPath, "temptableview2")
# Using tableviews
gp.JoinField_management ("temptableview", joinField, "temptableview2", joinField, fieldList) # tempfcnome # Without tableviews: gp.JoinField_management (inlayer, joinField, tempfcnome, joinField, fieldList) # tempfcnome # Calcular output campos laygrid gp.CalculateField_management(inlayer, nuts3field, nutsvalue,"PYTHON") # inlayer gp.CalculateField_management(inlayer, "SORT_ID", "!SORT_TEMP_ID!","PYTHON") gp.RemoveJoin_management (inlayer, tempfcnome)
# Using tableviews
gp.JoinField_management ("temptableview", joinField, "temptableview2", joinField, fieldList) # tempfcnome
# Calcular output campos laygrid
gp.CalculateField_management("temptableview", nuts3field, nutsvalue,"PYTHON") # inlayer
gp.CalculateField_management("temptableview", "SORT_ID", "!SORT_TEMP_ID!","PYTHON")
theDesc = gp.Describe("temptableview")
theDesc2 = gp.Describe("temptableview2")
gp.RemoveJoin_management (theDesc.catalogPath, theDesc2.catalogPath)
# remove tableviews
gp.Delete_management("temptableview")
gp.Delete_management("temptableview2")
gp.AddJoin_management ("temptableview", joinField, "temptableview2", joinField, fieldList)
gp.JoinField_management (inlayer, joinField, tempfcnome, joinField, fieldList) # tempfcnome
-- snip --
gp.RemoveJoin_management (inlayer, tempfcnome) # will not work!
Solid information