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")
joechoj
  • 443
  • 3
  • 15
  • 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
  • See if this http://gis.stackexchange.com/questions/121632/determining-y-coordinate-for-create-fishnet-from-desired-angle-of-rotation-in-py helps – FelixIP Aug 21 '16 at 23:54
  • 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 00:46
  • @PolyGeo: I'm seeking to build this into a tool (automate it) rather than do it interactively each time I do the operation. Is the short answer that it's not possible to autofill these fields using Arcpy, and that particular behavior is limited to running the built-in tool? – joechoj Aug 22 '16 at 04:17
  • I think the answer is http://gis.stackexchange.com/a/113470/115 If that is not it can you perhaps use that code as your starting point to describe why it seems unsuitable for you. – PolyGeo Aug 22 '16 at 04:32
  • 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 05:38
  • @Midavalo: Thanks for the helpful suggestion. Here's what that looks like:

    arcpy.CreateFishnet_management(out_feature_class="[filepath]/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")

    Which suggests to me I can't use Template Extent as a shortcut, that I have to find each param with Describe, and input those. Would you agree?

    – joechoj Sep 05 '16 at 22:54
  • @ PolyGeo: Thanks; I'd seen the link and would have asked there, but I don't have enough reputation to do that. – joechoj Sep 05 '16 at 23:12
  • @PolyGeo: I remain unclear why this 'Template Extent' parameter would be included in the CreateFishnet method. If the only way to make use of it is to explicitly find and enter all the other parameters, why include 'Template Extent' as an option at all? Is it just so that it matches the listed parameters in the Tool?

    That's what my question asks that the other post doesn't address.

    – joechoj Sep 06 '16 at 00:47
  • 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 06 '16 at 00:55
  • @PolyGeo: Thanks for the guidance; revised. Also, I keep attempting to tag the post 'fishnet', but it keeps saving as 'vector-grid' for some reason. – joechoj Sep 06 '16 at 23:28
  • 1
    [tag:fishnet] is a synonym of [tag:vector-grid] and so gets remapped to the latter. For background about why/when that synonymy was made see http://meta.gis.stackexchange.com/questions/3810/grid-related-tag-confusion – PolyGeo Sep 06 '16 at 23:33

1 Answers1

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.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
  • 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 07 '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 08 '16 at 06: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 04:27