1 votos

Uso de listas para trabajar con clases de características que tienen diferentes referencias espaciales en ArcPy?

Este es mi primer script arcpy intentando usar listas.

Entrada: 4 archivos Excel diferentes, cada uno con una referencia espacial diferente

Salida: 4 clases de características diferentes (en la misma geodatabase), cada una con su referencia espacial original convertida a NAD 1983.

Asunto: Puedo hacer 4 scripts diferentes (pero similares) y hacer que Python trabaje para cada entrada PERO ¿hay alguna forma de hacer que Python pase por mi entrada ¿Lista? El problema es que para el segundo paso, arcpy.MakeXYEventLayer_management No sé cómo rotar por las referencias espaciales según el archivo Excel que esté utilizando. Intento utilizar la idea de las sublistas sugerida por el usuario.

Actualizado Script pegado desde el Bloc de notas:

# Import arcpy module
import arcpy
from arcpy import env

# Set workspace
env.workspace = r"E:\GIS\1.gdb\\"

# Set the spatial reference
sr1 = arcpy.SpatialReference("WGS 1984")
sr2 = arcpy.SpatialReference("NAD 1927")
sr3 = arcpy.SpatialReference("NAD 1983")

# Set variables
textPath1 = r"E:\GIS\Excel_files_by_datum\\"                                            
textPath2 = r"E:\GIS\2015Q1\\"
textPath3 = r"E:\GIS\1.gdb\\"
input = [["WGS84.xlsx", sr1],["NAD27.xlsx",sr2],["NAD83.xlsx",sr3],["Long_0_or_blank.xlsx",sr3]]
out_Layer = "XY_Temp"
Layername = input[0:5]

#Run processes

for ss in input:
    try:
        print "Converting Excel file to table"
        # Convert Excel to table
        Table1 = arcpy.ExcelToTable_conversion(textPath1+ ss[0],textPath3 + Layername)

        print "Making XY event layer"
        # This is to take the xy values of the table and transform to points
        # Description: Creates an XY layer and exports it to a layer file
        XY_event = arcpy.MakeXYEventLayer_management(Table1,"LONGITUDE","LATITUDE",out_Layer, ss[0])

        print "Copying features"
        # Description: Creates geodatabase feature class from the xy layer
        FeatureCopy = arcpy.CopyFeatures_management(XY_event, Layername + "_temp")

        print "Making feature layer"
        # Description: Transforms xy event layer into feature layer so I can select from it
        FeatureLayer = arcpy.MakeFeatureLayer_management(FeatureCopy, Layername + "_temp2")

        print "Converting from original datum to NAD83"
        # Converts file from input datum to NAD83
        Transformed = arcpy.Project_management(FeatureLayer,textPath3 + Layername + "_to_NAD83",ss[2])

        print "Adding xy coordinates to feature layer table"
        # Adds new NAD83 xy coordinates to feature layer table
        arcpy.AddXY_management(Transformed)

        print "Deleting temp file"
        # Deletes temp FeatureCopy file
        arcpy.Delete_management(FeatureCopy)

        print "Deleting original table"
        # Deletes table from before the NAD 83 xy coordinates were added
        arcpy.Delete_management(Table1)

        print "Project complete"

    except:
        print arcpy.GetMessages()

3voto

john Puntos 11

Sinceramente, hay bastantes cosas mal. Traté de hacer una limpieza rápida, pero admito que no lo probé:

# Import arcpy module
import arcpy
import os

# Set workspace
arcpy.env.workspace = "E:\\GIS\\1.gdb"

# Set the spatial reference
sr1 = arcpy.SpatialReference("WGS 1984")
sr2 = arcpy.SpatialReference("NAD 1927")
sr3 = arcpy.SpatialReference("NAD 1983")

# Set variables
textPath1 = "E:\\GIS\\Excel_files_by_datum"
textPath2 = "E:\\GIS\\2015Q1"
textPath3 = "E:\\GIS\\1.gdb"

input_data = [["WGS84.xlsx", sr1],["NAD27.xlsx", sr2],["NAD83.xlsx", sr3],["Long_0_or_blank.xlsx", sr3]]

#Run processes
for data in input_data:
    try:
        layer_name = data[0].split(".")[0]
        out_layer = str(layer_name) + "_XY_Temp"

        print "Converting Excel file to table"
        # Convert Excel to table
        Table1 = arcpy.ExcelToTable_conversion(os.path.join(textPath1, str(data[0])), os.path.join(textPath3, layer_name))

        print "Making XY event layer"
        # This is to take the xy values of the table and transform to points
        # Description: Creates an XY layer and exports it to a layer file
        XY_event = arcpy.MakeXYEventLayer_management(Table1, "LONGITUDE", "LATITUDE", out_layer, data[1])

        print "Copying features"
        # Description: Creates geodatabase feature class from the xy layer
        FeatureCopy = arcpy.CopyFeatures_management(XY_event, layer_name + "_temp")

        print "Making feature layer"
        # Description: Transforms xy event layer into feature layer so I can select from it
        FeatureLayer = arcpy.MakeFeatureLayer_management(FeatureCopy, layer_name + "_temp2")

        print "Converting from original datum to NAD83"
        # Converts file from input datum to NAD83
        Transformed = arcpy.Project_management(FeatureLayer, os.path.join(textPath3, layer_name + "_to_NAD83"), sr3)

        print "Adding xy coordinates to feature layer table"
        # Adds new NAD83 xy coordinates to feature layer table
        arcpy.AddXY_management(Transformed)

        print "Deleting temp file"
        # Deletes temp FeatureCopy file
        arcpy.Delete_management(FeatureCopy)

        print "Deleting original table"
        # Deletes table from before the NAD 83 xy coordinates were added
        arcpy.Delete_management(Table1)

        print "Project complete"

    except:
        arcpy.GetMessages()

2voto

felix Puntos 223

Creo que la mejor manera sería incrustar sus referencias espaciales en su lista como sub-listas, es decir:

input = [["WGS84.xlsx",sr1],["NAD83.xlsx",sr2],["WGS84.xlsx",sr3],["Long_0_or_blank.xlsx",sr1]]

A continuación, actualice su secuencia de comandos para (tenga en cuenta el uso de ss[]):

for ss in input:
    try:
        # ...
        Table1 = arcpy.ExcelToTable_conversion(textPath1 + ss[0], textPath3 + Layername)
        # ...
        Transformed = arcpy.Project_management(FeatureLayer, textPath3 + Layername + "_to_NAD83", ss[1])

i-Ciencias.com

I-Ciencias es una comunidad de estudiantes y amantes de la ciencia en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X