Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I want a python script that tells me the Xmin, Xmax, Ymin, and Ymax of a polygon. (I guess this is finding the extent of a polygon?)

My current script gives me the correct the Xmin and Xmax, but it gives me the Ymin and Ymax of the data frame. I want the Ymin and Ymax of a polygon.

Here is my current code:

# Specify the shapefile
shapeFile = "C:/Big_Creek_MapUnits.shp"

# Use the describe function
desc = arcpy.Describe(shapeFile)

# Print stuff out

Anyone have any solutions or tips?

share|improve this question
For a shapefile or for each polygon in a shapefile? Looks like you're talking about two separate things here. –  Rayner Sep 18 '12 at 7:14
Thank you. I mean polygon. –  jabeoogie Sep 18 '12 at 7:16
is there only one polygon object in your shapefile? if not, use for loop for your objects extent. –  Aragon Sep 18 '12 at 7:43

2 Answers 2

up vote 8 down vote accepted

Answered here: How to get the extent of each polygon in a shapefile?

rows = arcpy.SearchCursor(inFeatures)
shapeName = arcpy.Describe(inFeatures).shapeFieldName
for row in rows:
    feat = row.getValue(shapeName)
    extent = feat.extent
    print extent.XMin,extent.YMin,extent.XMax,extent.YMax
share|improve this answer

As covered in this previous question you can get get the vertices of a polygon and then add the x and y coordinates of each vertex as fields in the attribute table. This has the limitation of not attaching the max/min coordinates directly to each polygon but this can be achieved in a few ways.

The method I am most familiar with is to read the x and y fields into python lists using the pyshp module, which can then be sorted to find maximum and minimum values for each polygon. Pyshp can then be used to open a writer class to add new fields to the original polygons and write these max and min values to the correct polygon.

I believe this can be done using the arcpy, but I had a lot of problems with writing to shapefiles in 9.3 using the geoprocessor, so I prefer the pyshp method, however I am unsure if the arcpy module has solved these issues.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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