# Name: GridCreation.py
# import system modules
import arcpy
# Set environment settings
arcpy.env.workspace = r"C:\data\City.gdb"
arcpy.env.outputCoordinateSystem = arcpy.Describe("roads").spatialReference
# Set local variables
in_features = "roads"
properties = "EXTENT"
length_unit = ""
area_unit = ""
coordinate_system = ""
# Generate the extent coordinates using Add Geometry Properties tool
arcpy.AddGeometryAttributes_management(in_features, properties, length_unit,
area_unit, coordinate_system)
# Use Search Cursor to walk through each feature and generate grids
with arcpy.da.SearchCursor(in_features, ["OID@", "EXT_MIN_X", "EXT_MIN_Y",
"EXT_MAX_X", "EXT_MAX_Y"]) as sCur:
for row in sCur:
minX, minY, maxX, maxY = row[1], row[2], row[3], row[4]
arcpy.CreateFishnet_management("fishnet_{0}".format(row[0]),
number_rows = 10,
number_columns = 10,
template = "{} {} {} {}".format(minX, maxX, minY, maxY),
origin_coord = "{} {}".format(minX, minY),
y_axis_coord = "{} {}".format(minX, maxY),
corner_coord = "{} {}".format(maxX, maxY),
geometry_type = "POLYGON",
labels = "NO_LABELS")