1

I have a set of polygons that are rectangles (10 km by 1 km dimension), and I'm using Fishnet to create smaller polygons (which I'll call "boxes"). The boxes need to be equal area, so I am working in a projected datum and defining the cell sizes in Fishnet. I'm doing test run with 100 meters by 100 meters, but I'll ultimately being looping through a bunch of sizes. The test case here is also only for one polygon, but finale shapefile for analysis will have multiple polygons.

For some reason, Fishnet is not fitting the boxes in my polygon as I expected. It's overshooting on the north side by 5 boxes (500 m) and undershooting the east side by 100 meters (screenshot below; north is up.) I don't understand why this is happening? There must be something about how Fishnet works that I am missing.

In the code below, I first extracted the polygon vertices ABCD to define the Y axis for the Fishnet. This was done because I'll ultimately have many polygons with different Y axis orientations.

NOTE: this question is edited from an earlier question. Earlier question has been deleted and this question has been cleaned up, because commenters complained about defining variables. So, code below is cleaned up with fewer objects.

enter image description here

import arcpy
arcpy.env.overwriteOutput = True

mainBox2 = r'C:\Users\X\_temp working\box.shp'
centerLine2 = r'C:\Users\X\_temp working\center_line.shp'
working_epsg = 26911
outpath = r'C:\Users\X\_temp working'

############################################################

arcpy.FeatureVerticesToPoints_management(mainBox2, outpath + '\\' + 'temp_mainBox_vertices.shp', "ALL")

# Define polygon vertices to match vertices as shown in screenshot
with arcpy.da.SearchCursor(outpath + '\\' + 'temp_mainBox_vertices.shp', ['OID@', 'SHAPE@XY']) as rows:
    temp = dict(r for r in rows)

D = temp[0]
A = temp[1]
B = temp[2]
C = temp[3]

############################################################

### Set local variables
outFeatureClass = outpath + '\\' + 'TempTest.shp'
cellSizeWidth = '100'
cellSizeHeight = '100'
originCoordinate = '%s %s' %(A[0], A[1])
yAxisCoordinate = '%s %s' %(B[0], B[1])
oppositeCorner = '%s %s' %(D[0], D[1])

### Execute CreateFishnet
from arcpy import env
env.outputCoordinateSystem = arcpy.SpatialReference(working_epsg)
arcpy.CreateFishnet_management(outFeatureClass, originCoordinate, yAxisCoordinate, cellSizeWidth, cellSizeHeight, "", "", oppositeCorner, 'NO_LABELS', '#', 'POLYGON')

#
  • Side issue: 26911 (NAD83 UTM zone 11 North) does not use an equal area projection. – mkennedy Sep 18 '18 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.