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
-
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")user5956986– user59569862018年07月27日 15:14:10 +00:00Commented 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 ReviewDan C– Dan C2018年07月27日 16:11:00 +00:00Commented Jul 27, 2018 at 16:11
3 Answers 3
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")
-
1@@radouxju, what is the purpose of
+ 10
instr(desc.extent.YMax + 10)
?maycca– maycca2019年10月04日 07:49:09 +00:00Commented Oct 4, 2019 at 7:49 -
1good 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.radouxju– radouxju2019年10月04日 12:11:44 +00:00Commented Oct 4, 2019 at 12:11
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"))
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")