Select to view content in your preferred language

Fishnet nor following input layer outline/boundary

514
2
01-19-2024 03:48 PM
TonyAlmeida
Occasional Contributor III

I am trying to create a fishnet that is created orientated or built incorrectly. Why does the create fishnet do this?

 

I have the following code, but I am not sure why it's not creating it with the boundary of the input layer.

 

import arcpy

# Set the workspace (replace with the path to your data)
arcpy.env.workspace = r"C:\temp\Test.gdb"

# Input county PLSS grid feature class
county_plss_grid = r"C:\temp\Test.gdb\SEC_231N3W"

# Output grid feature class
output_grid = "SEC_231N3W_Grid_New2"

# Specify the coordinate system (NAD 1983 HARN StatePlane Oregon North FIPS 3601)
coordinate_system = arcpy.SpatialReference("NAD 1983 HARN StatePlane Oregon North FIPS 3601 (US Feet)")

# Get the extent of the county PLSS grid
extent = arcpy.Describe(county_plss_grid).extent

# Calculate the overall length and width of the input layer
length = extent.width
width = extent.height

# Determine the cell size based on the overall length and width
cell_size = min(length, width) / 10  # You can adjust the denominator for the desired number of cells

# Set the number of rows and columns
num_rows = 10
num_columns = 10

# Set the output coordinate system
arcpy.env.outputCoordinateSystem = coordinate_system

# Create a fishnet with 10 rows and 10 columns using the input layer width and height
fishnet_path = arcpy.management.CreateFishnet(
    out_feature_class=output_grid,
    origin_coord=f"{extent.XMin} {extent.YMin}",
    y_axis_coord=f"{extent.XMin} {extent.YMin + cell_size}",  # Move south to north
    cell_width=cell_size,
    cell_height=cell_size,
    number_rows=num_rows,
    number_columns=num_columns,
    labels="NO_LABELS",
    geometry_type="POLYGON",
    template=county_plss_grid  # Use the original shape as a template
)[0]

print(f"Fishnet created: {output_grid}")

 

0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

What do you get if you let the tool calculate the cell size, keeping the LL and UR coordinates the same and the same number of rows and columns?

Create Fishnet (Data Management)—ArcGIS Pro | Documentation


... sort of retired...
0 Kudos
TonyAlmeida
Occasional Contributor III

It appears that the fishnet shifted, there is now a gap at the bottom right corner. This time I ran it in the tool, see attached. I mad sure the coordinate system and the extent were the same as the input, as well as the maps coordinate system.

0 Kudos