10

I can’t use the tool arcpy.CreateFishnet_management because define the parameter "templateExtent" with a shapefile it is not filling automatically the parameters "originCoordinate" and "yAxisCoordinate".

import arcpy
from arcpy import env
env.overwriteOutput = True
env.workspace = r"D:\Users\julia\erste_aufg"
#Process: Create Fishnet
outFeatureClass = r"D:\Users\julia\erste_aufg\at001l_wien\at001l_wien\wien.shp"
cellSizeWidth = '200'
cellSizeHeight = '200'
templateExtent = r"D:\Users\julia\erste_aufg\at001l_wien\at001l_wien\at001l_wien.shp"
arcpy.CreateFishnet_management(outFeatureClass, "", "", cellSizeWidth, cellSizeHeight, '0', '0', "", "NO_LABELS", templateExtent, "POLYGON")

enter image description here

It is working in the ModelBulider, so something is running in the background of the ModelBulider that it could create the parameters "originCoordinate" and "yAxisCoordinate" when it has a "templateExtent". How can I get this tool running in ArcPy by having just the parameter "templateExtent"?

I would be really happy if someone has a solution because I need the Fishnet in a scripttool and cannot go one without because in the end there is a loop so the values of the extent are always different. the first part of the whole script

Pang
2151 silver badge8 bronze badges
asked Sep 11, 2014 at 8:27
2
  • Does someone know why we add a 10 to the part of the solution above? 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") Commented Jul 27, 2018 at 15:14
  • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review Commented Jul 27, 2018 at 16:11

3 Answers 3

15

here is an example. You need to extract the bounding box from a describe object.

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")
answered Sep 11, 2014 at 8:37
2
  • 1
    @@radouxju, what is the purpose of + 10 in str(desc.extent.YMax + 10)? Commented Oct 4, 2019 at 7:49
  • 1
    good question. Actually not necessary in this case. I've got the habit to add an arbitrary value on the Ymin to build a vertical axis, but here I used Ymax, therefore it is overkill. Commented Oct 4, 2019 at 12:11
4

Here is an alternate approach that I used to create multiple fishnets within the extents of each feature within a feature class. The search_extents variable defines the path to that feature class defining the extents of each fishnet I wanted to create. There was no rotation of the fishnet.

search_extents = "path to extents" 
rows = arcpy.SearchCursor(search_extents)
shapeName = arcpy.Describe(search_extents).shapeFieldName
for row in rows:
 print("Starting Extent" + row.getValue("Extent_Num"))
 feat = row.getValue(shapeName)
 extent = feat.extent
 arcpy.CreateFishnet_management(arcpy.env.workspace + "/extents/extentgrid" + row.getValue("Extent_Num"),str(extent.lowerLeft), str(extent.upperLeft),"0","0","200","200",str(extent.upperRight),"NO_LABELS","#","POLYGON")
 print("Finishing Extent" + row.getValue("Extent_Num"))
answered Jun 22, 2016 at 18:47
1

Here is the code that I finally successfully got working (with help from the examples above) to solve the problem described here:

 env.workspace = "C:/Holly/Work/Projects/NavigationStudy2019/Data"
 # Fetch each feature from the cursor and examine the extent properties
 for row in arcpy.da.SearchCursor(feature_class, ['SHAPE@', 'id']):
 extent = row[0].extent
 print('Extent of home range {}:'.format(row[1]))
 print('XMin: {}, YMin: {}'.format(extent.XMin, extent.YMin))
 print('XMax: {}, YMax: {}'.format(extent.XMax, extent.YMax))
 arcpy.CreateFishnet_management("fishnet_temp.shp",
 str(extent.XMin) + " " + str(extent.YMax),
 str(extent.XMin) + " " + str(extent.YMax + 10),
 "100",
 "100",
 "",
 "",
 "",
 "LABELS",
 feature_class,
 "POLYGON")
answered Aug 16, 2019 at 22:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.