Select to view content in your preferred language

Creating fishnet using a template

1081
5
Jump to solution
10-04-2023 07:41 PM
JasmineSpring
Occasional Contributor

Hello

I need some help to work out how to configure create fishnet using a template specified in the parameter of a script tool to create a 2m grid. Im not sure how to get the x and Y values from the template. Thank you for your help its very apprecaited

Output1 = arcpy.GetParameterAsText(0)
Input1 = arcpy.GetParameterAsText(1)

arcpy.management.CreateFishnet(Output1,"","" , '2', '2',None,None,"", "NO_LABELS", Input 1, "POLYGON")

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JasmineSpring
Occasional Contributor

This is the solution I used in the end

desc = arcpy.Describe(Templatelayer)
arcpy.CreateFishnet_management(Grid_layer,str(desc.extent.lowerLeft),str(desc.extent.XMin) + " " + str(desc.extent.YMax),"2","2",None,None,str(desc.extent.upperRight),"NO_LABELS","#","POLYGON")

. Thank you for your help 

View solution in original post

0 Kudos
5 Replies
DanPatterson
MVP Esteemed Contributor

why not add another parameter and set its default value

size - arcpy.GetParameterAsText(2)

arcpy.management.CreateFishnet(Output1,"","" , size, size,None,None,"", "NO_LABELS", Input 1, "POLYGON")

 


... sort of retired...
0 Kudos
JasmineSpring
Occasional Contributor

The size is ok because it is always 2m. It is using the template (another layer) set as a parameter that is the issue when its scripted in python.  I get the following error.

JasmineSpring_0-1696562434765.png

thank you so much!

 

0 Kudos
DanPatterson
MVP Esteemed Contributor

It looks like you have to get the origin from the template featureclass then


... sort of retired...
0 Kudos
JasmineSpring
Occasional Contributor

This is the solution I used in the end

desc = arcpy.Describe(Templatelayer)
arcpy.CreateFishnet_management(Grid_layer,str(desc.extent.lowerLeft),str(desc.extent.XMin) + " " + str(desc.extent.YMax),"2","2",None,None,str(desc.extent.upperRight),"NO_LABELS","#","POLYGON")

. Thank you for your help 

0 Kudos
NickAtEsriAU
Emerging Contributor

Hi @JasmineSpring ,

Sorry I am very late to this and know its solved but a similar solution from me.  I am only interested in making 2 rows and 4 columns but here is the code for what it is worth.

import arcpy
import os

wksp = r"Insert workspace here"
in_md = "Insert name of input dataset"
out_fc = "Insert name output feature class"

arcpy.env.workspace = wksp

# Create a fishnet grid
desc = arcpy.Describe(in_md)
xmin = desc.extent.XMin
xmax = desc.extent.XMax
ymin = desc.extent.YMin
ymax = desc.extent.YMax

point_origin = f'{xmin} {ymin}'
point_yaxis = f'{xmin} {ymax}'

arcpy.CreateFishnet_management(out_feature_class=out_fc,
                               origin_coord=point_origin,
                               y_axis_coord=point_yaxis,
                               number_rows="2",
                               number_columns="4",
                               labels="NO_LABELS",
                               template=in_md,
                               geometry_type="POLYGON")

 

Cheers,

Nick

 

0 Kudos