2

When running the following script, I get the error saying that I need a value for “origin_coord” and for “y_axis_coord”. So is it not enough to define a template dataset? But how can I fill the “origin_coord” and “y_axis_coord” parameters with Arcpy working with ArcMap 10.0? Because in the loop are a lot of shapefiles from different cities, so I need a loop.

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

Is there someone who can help me? I’m trying it without the Iteration but it is not working even if I add a layer before? Why?

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")
2

From the help for Create Fishnet (Data Management) the usage is:

CreateFishnet_management (out_feature_class, origin_coord, y_axis_coord, cell_width, cell_height, number_rows, number_columns, {corner_coord}, {labels}, {template}, {geometry_type})

Compare this with what you are supplying and there are a number of errors.

As one example, the values expected for cell_width and cell_height are expected to be of type Double (e.g. 200 and 200) but you are providing them with strings (i.e. "200" and "200").

I recommend that you run the tool from its dialog once and then use Copy As Python Snippet from the Geoprocessing | Results window to copy the syntax into your script so that you can just substitute in your variables and values.

I would put the rest of your script aside until you can get this part working in a few line test script.

  • Creating a fishnet in the ModleBulider without an iteration is working. When I export this in a python script the parameter “ originCoordinate” and “yAxisCoordinate” got written by the “templateExtent”. Because doing the same in Arcpy it is not running because it does not fill the parameter “originCoordinate” and “yAxisCoordinate” with the given “templateExtent” as it does in the ModelBulider. How is arcpy automatically filling the parameter “originCoordinate” and “yAxisCoordinate” by define the parameter “templateExtent” with a shapefile? It works with the ModelBuilder but not in arcpy. – Nora Sep 10 '14 at 12:46
  • 1
    @Nora there must be some tool validation built into that system tool to handle choosing a template for the extent. As a Python script I think you will need to work it out by using arcpy.Describe on the feature class and then processing the returned Extent object's properties to write the arcpy.CreateFishnet parameters. I think this would be worth you writing up as a separate question so that it can be answered more cleanly than commenting can allow. – PolyGeo Sep 10 '14 at 23:05
  • thanks, here it is gis.stackexchange.com/questions/113469/… – Nora Sep 11 '14 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.