2 votos

Crear una red de pesca en un bucle 'for' con Arcpy

Al ejecutar el siguiente script, me da el error de que necesito un valor para "origin_coord" y para "y_axis_coord". Entonces, ¿no es suficiente con definir un conjunto de datos de plantilla? Pero, ¿cómo puedo llenar el "origin_coord" y "y_axis_coord" parámetros con Arcpy trabajando con ArcMap 10.0? Porque en el bucle son un montón de shapefiles de diferentes ciudades, así que necesito un bucle.

import arcpy
import os
from arcpy import env

env.overwriteOutput = True
env.workspace = r"D:\Users\julia\out_09_09\urbanA"
env.qualifiedFieldNames = False
#make a list with input cities as shapefiles.

fcList = arcpy.ListFeatureClasses()

for shpFile in fcList:
    shpFileName= os.path.splitext (shpFile) [0]
    print shpFileName # works
    # Process: Make Feature Layer
    arcpy.MakeFeatureLayer_management(env.workspace + "\\" + shpFile, "shpFile_ly")
    # join the city with the reclasstable
    jointable = r"D:\Users\julia\out_09_09\reclass.dbf"
    arcpy.AddJoin_management("shpFile_ly", "CODE", jointable, "joinCODE", "KEEP_ALL")
    # Process: Copy Features
    outFeatureClass = shpFileName + "_join.shp"
    arcpy.CopyFeatures_management("shpFile_ly", outFeatureClass)
    # Process: Polygon to Raster
    outraster = shpFileName + "_join.img"
    cellSize = 200
    arcpy.PolygonToRaster_conversion(outFeatureClass, "CODE", outraster, "CELL_CENTER", "NONE", cellSize)
    # Process: Make Raster Layer
    arcpy.MakeRasterLayer_management(outraster, "outraster_ly")#works
    # Process: Add Join 
    arcpy.AddJoin_management("outraster_ly", "Value", jointable, "code", "KEEP_ALL")
    # Process: Copy Raster
    outraster2 = shpFileName + "_join2.img"
    arcpy.CopyRaster_management("outraster_ly",outraster2) #works
    # Process: Raster to Polygon
    outPolygons = shpFileName + "reclass.shp"
    arcpy.RasterToPolygon_conversion(outraster2, outPolygons, "NO_SIMPLIFY", "Value")#works

    # Process: Create Fishnet
    cellSizeWidth = "200"
    cellSizeHeight = "200"
    outFishnet = shpFileName + "_net.shp"
    arcpy.CreateFishnet_management(outFishnet, "", "", cellSizeWidth, cellSizeHeight, "0", "0", "", "NO_LABELS", outPolygons, "POLYGON")

enter image description here

¿Hay alguien que pueda ayudarme? Lo estoy intentando sin la Iteración pero no funciona aunque añada una capa antes? ¿Por qué?

import arcpy
from arcpy import env
env.overwriteOutput = True
env.workspace = r"D:\Users\julia\erste_aufg"

# Process: Make Feature Layer
#arcpy.MakeFeatureLayer_management(r"D:\Users\julia\erste_aufg\de013l_hannover    \de013l_hannover\de013l_hannover.shp", "hannover_ly")

#Process: Create Fishnet
outFeatureClass = r"D:\Users\ju\ers\result\hannover_fisch.shp"
cellSizeWidth = '200'
cellSizeHeight = '200'
templateExtent = r"D:\Users\ju\ers\de013l_hannover\de013l_hannover\de013l_hannover.shp"

arcpy.CreateFishnet_management(outFeatureClass, "", "", cellSizeWidth, cellSizeHeight, '0', '0', "", "NO_LABELS", templateExtent, "POLYGON")

2voto

UnkwnTech Puntos 21942

De la ayuda para Creación de la red de pesca (gestión de datos) el uso es:

CreateFishnet_management (out_feature_class, origin_coord, y_axis_coord, cell_width, cell_height, number_rows, number_columns, {coordenada_de_esquina}, {etiquetas}, {plantilla}, {tipo_de_geometría})

Compárelo con lo que está suministrando y hay una serie de errores.

Por ejemplo, los valores previstos para cell_width y cell_height se espera que sean de tipo Double (por ejemplo, 200 y 200) pero se les está proporcionando cadenas (por ejemplo, "200" y "200").

Te recomiendo que ejecutes la herramienta desde su cuadro de diálogo una vez y luego utilices Copy As Python Snippet desde la ventana Geoprocessing | Results para copiar la sintaxis en tu script para que sólo tengas que sustituirlo por tus variables y valores.

Yo pondría el resto de tu script a un lado hasta que puedas conseguir que esta parte funcione en un script de prueba de pocas líneas.

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