Problem in Creating Envelope Polygon using Python

6525
4
Jump to solution
12-14-2014 10:43 AM
AhsanAbbas
New Contributor III

I need a script that makes an envelope polygon feature class for the Hawaii.shp (Multi-part polygon) feature class. There is actually a tool that accomplishes this called Minimum Bounding Geometry. But i have to do it using python script which directly deals with the geometry properties. how can i do it, i have tried it without using any geometry property, but facing problem doing it though Geometry , Shape file is attached.

 

env.workspace = r"D:\Python Exercise\Exercise08-2014-12-05\Exercise08"

inFeatures = "Hawaii.shp"

outFeatureClass = "Hawaii_Profile.shp"

arcpy.MinimumBoundingGeometry_management(inFeatures, outFeatureClass, "ENVELOPE", "NONE")

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor

At the risk of doing your homework for you (you're only hurting yourself, but I figure the assignment must be in by now), here's the answer:

>>> with arcpy.da.SearchCursor("Hawaii","SHAPE@") as cursor:
...    for row in cursor:
...        print row[0].extent
...        polygon = [arcpy.Polygon(arcpy.Array([arcpy.Point(row[0].extent.XMin,row[0].extent.YMin),arcpy.Point(row[0].extent.XMax, row[0].extent.YMin),arcpy.Point(row[0].extent.XMax,row[0].extent.YMax),arcpy.Point(row[0].extent.XMin,row[0].extent.YMax)]))]
...       
372236.642923135 2094769.12137791 941120.12366655 2458884.21017432 NaN NaN NaN NaN
>>> arcpy.CopyFeatures_management(polygon,'in_memory\extent')
<Result 'in_memory\\extent'>

hawaii.png

View solution in original post

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

I will refer you to arcpy's Polygon class for the required inputs.... extent .... should provide the clues

0 Kudos
AndrewChapkowski
Esri Regular Contributor

Do you need the extent of every geometry? or the whole feature class?

0 Kudos
AhsanAbbas
New Contributor III

whole feature class

0 Kudos
DarrenWiens2
MVP Honored Contributor

At the risk of doing your homework for you (you're only hurting yourself, but I figure the assignment must be in by now), here's the answer:

>>> with arcpy.da.SearchCursor("Hawaii","SHAPE@") as cursor:
...    for row in cursor:
...        print row[0].extent
...        polygon = [arcpy.Polygon(arcpy.Array([arcpy.Point(row[0].extent.XMin,row[0].extent.YMin),arcpy.Point(row[0].extent.XMax, row[0].extent.YMin),arcpy.Point(row[0].extent.XMax,row[0].extent.YMax),arcpy.Point(row[0].extent.XMin,row[0].extent.YMax)]))]
...       
372236.642923135 2094769.12137791 941120.12366655 2458884.21017432 NaN NaN NaN NaN
>>> arcpy.CopyFeatures_management(polygon,'in_memory\extent')
<Result 'in_memory\\extent'>

hawaii.png

0 Kudos