1

While running the standalone tool in ArcMap, the optional parameter TemplateExtent is a wonderful shortcut, as it autofills 10 other parameters. However, I need to run it in a standalone script, and have been unsuccessful in using the parameter as it's used in the tool: leaving these fields to be autofilled using the TemplateExtent layer's info. Instead, as seen in Creating fishnet from template feature class using ArcPy? (courtesy of radouxju), the best solution seems to involve using Describe to find and enter each parameter explicitly:

desc = arcpy.Describe(fc)
arcpy.CreateFishnet_management(fc[:-4]+"_c200.shp",str(desc.extent.lowerLeft),str(desc.extent.XMin) + " " + str(desc.extent.YMax + 10),"200","200","0","0",str(desc.extent.upperRight),"NO_LABELS","#","POLYGON")

That approach squares with the fact that the first of these parameters are required. If I'm understanding it correctly, when run in ArcPy it has no utility since all other fields are required.

Question: So should I always ignore this paramter in the ArcPy environment, just using '#' as a placeholder; or is there some other utility?

Following PolyGeo's and Midavalo's suggestions below, here's the Python snippet that results from running CreateFishnet as a tool:

arcpy.CreateFishnet_management(out_feature_class="[path]/test_fishnet", origin_coord="447677.5 3111557.5", y_axis_coord="447677.5 3111567.5", cell_width="50", cell_height="50", number_rows="0", number_columns="0", corner_coord="482222.5 3142082.5", labels="LABELS", template="mid_5m", geometry_type="POLYLINE")
  • 1
    the # is a placeholder used in optional parameters instead of giving a value. Basically you're saying that you're not providing a value for that parameter. – Midavalo Aug 21 '16 at 22:58
  • 2
    Do it interactively and use Copy As Python Snippet from the Geoprocessing | Results window as your starting code snippet. – PolyGeo Aug 22 '16 at 0:46
  • 1
    @joechoj you don't need to do it interactively each time, just do it once or twice to see how ArcMap generates the arcpy snippet, and use that to start your script – Midavalo Aug 22 '16 at 5:38
  • 1
    Perhaps revise your question so that it includes this information and only a single question mark to make what you are asking clearer. The template parameter expects an extent to be provided - see its syntax in the tool documentation. When using the tool from its dialog it provides an additional bit of functionality that enables a feature class to be chosen to set the value of that extent, but it is the extent not the feature class that gets submitted to the underlying ArcObjects. – PolyGeo Sep 6 '16 at 0:55
  • 1
    fishnet is a synonym of vector-grid and so gets remapped to the latter. For background about why/when that synonymy was made see meta.gis.stackexchange.com/questions/3810/… – PolyGeo Sep 6 '16 at 23:33
2

I agree that the template parameter of CreateFishnet when used in ArcPy and from the Create Fishnet tool dialog can be confusing but I would not go as far as to endorse you saying:

when run in ArcPy it's useless; or worse, a source of ambiguity since best practice seems to require "#"

The template parameter expects an extent to be provided - see its syntax in the tool documentation:

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

where, when it describes the template parameter, it gives its Data Type as being an Extent (not a Feature Class).

When using the tool from its dialog it provides an additional bit of functionality that enables a feature class to be chosen to set the value of that extent, but it is the extent not the feature class that gets submitted to the underlying ArcObjects.

As can be seen in Creating fishnet from template feature class using ArcPy? the way to bring the additional piece of functionality that you seek into a Python script using ArcPy is to use Describe to determine the extent of a feature class prior to submitting that extent to arcpy.CreateFishnet_management().

If you want the way this tool works to be changed you could look for or submit an ArcGIS Idea to have an additional parameter template_feature_class added which supplements the current template parameter which requires an extent. An ArcGIS Idea to have this confusing difference between using the tool in ArcPy and from its tool dialog better documented will probably have a better chance of happening.

With a bit of experimenting I think I can now illustrate a circumstance in which the number of rows, the number of columns and the corner coordinate are not specified, and the tool is using the template Extent to help determine how many cells to create. It does not seem to be able to create any cells southwest of the origin coordinate, and I do not know if this is by design.

arcpy.CreateFishnet_management(out_feature_class="C:/Temp/test.gdb/testFishnet", origin_coord="0 0", y_axis_coord="0 1", cell_width="1", cell_height="1", number_rows="", number_columns="", corner_coord="", labels="NO_LABELS", template="0 0 3 3", geometry_type="POLYGON")

Reconciling the Create Fishnet tool dialog, the arcpy.CreateFishnet_management() syntax and the online help which is supposed to cover both is something that I think you need to take up with Esri via ArcGIS Ideas and/or their technical support.

|improve this answer|||||
  • Thanks, that's helpful insight that data type is Extent. I appreciate that the functionality can be replicated - just not using template. Isn't template in the ArcPy context useless if it can only be used to enter redundant information? In each example I've found (~10), either '#' is used, or extents are entered - the same extents which are defined by the other parameters. It doesn't seem helpful in any way (in ArcPy). I wonder if ESRI made the decision that all parameters in tools and ArcPy methods have to mirror one another. This would at least explain the inclusion. – joechoj Sep 7 '16 at 19:16
  • I believe I've found a use for template within ArcPy. If you haven't already explicitly defined your spatial reference, using just "#" for template will leave spatial reference undefined; whereas providing a layer with defined spatial reference will extend the definition to the fishnet layers created. Correct me if I'm wrong. – joechoj Sep 8 '16 at 6:51
  • Thanks, I only just noticed your addition. Thanks for taking the time to look into this. At your suggestion I'll try to submit this idea to ESRI. – joechoj Sep 13 '16 at 4:27

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.