0

How do I create a bounding box of Hawaii.shp using the minimum X, maximum X, minimum Y, and maximum Y and store it in a polygon shapefile?

xmin: 372236.642923 
xmax: 941120.123667 
ymin: 2094769.12138 
ymax: 2458884.21017
import arcpy
arcpy.env.workspace = r"F:\Labs\Original\Lab8\Lab08"

fc = "newpolygon.shp"
arcpy.CreateFeatureclass_management(arcpy.env.workspace,fc,"Polygon")
array = arcpy.Array()
coordinates = 
for x,y in coordinates:
    point = arcpy.Point()
    array.add(point)
polygon=arcpy.Polygon(array)
cursor = arcpy.da.InsertCursor(fc,["SHAPE@"])
cursor.insertRow([polygon])

print "Done"
del cursor
3

1 Answer 1

1

This page has a bunch of relevant examples: https://pro.arcgis.com/en/pro-app/arcpy/get-started/writing-geometries.htm. I modified the final example on the page to match your coords. Though I've no idea what projection (coordinate system) those values are in, so I just picked 26904 out of a hat (you'll need to correct that)

I didn't test it, but I think it's close.

import arcpy
import os

# Create a feature class with a spatial reference of NAD83 / UTM zone 4N
result = arcpy.management.CreateFeatureclass(arcpy.env.scratchGDB, 
                  "esri_square", "POLYGON", spatial_reference=26904)[0]

# hawaii extent
extent = {'xmin': 372236.642923,
          'xmax': 941120.123667,
          'ymin': 2094769.12138,
          'ymax': 2458884.21017,}

# verts walk around counterclockwise, and 
#  repeat the first/last point to close to poly
coords = [(coords["minx", coords["miny"]),
          (coords["maxx", coords["miny"]),
          (coords["maxx", coords["maxy"]),
          (coords["minx", coords["maxy"]),
          (coords["minx", coords["miny"])]

# Write feature to new feature class
with arcpy.da.InsertCursor(feature_class, ['SHAPE@']) as cursor:
    cursor.insertRow([coords])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.