Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Extract bounding rectangle coordinates from feature class using Python

21 views
Skip to first unread message

Richard Lent

unread,
Feb 23, 2009, 12:35:39 PM2/23/09
to
I am trying to write a Python script that will clip raster layers
using a vector polygon. The function call to do so looks like this:

gp.clip_management("gtopo_1km","-2.40438436932573 39.6271900031164
3.95492080927664
44.4723749010991","clip_test","spain.shp","-255","ClippingGeometry")

Is there a way to extract the bounding rectangle coordinates from the
clipping polygon from within the Python script? Having to specify
both the bounding rectangle coordinates and the clipping layer seems
redundant. I'm looking for a function that does this kind of thing:

maxX = getMax_X(spain.shp)

etc. This seems like it should be a simple thing to do. Does
anything like this exist for Python in ArcGIS 9.3?

Thanks. If I have missed something that is obvious, I will accept the
consequences.

Niklas Norrthon

unread,
Feb 26, 2009, 4:35:48 PM2/26/09
to
On 23 Feb, 18:35, Richard Lent <richardl...@gmail.com> wrote:
>
> Is there a way to extract the bounding rectangle coordinates from the
> clipping polygon from within the Python script?  

Lookup the Describe method of the geoprocessor:

>>> import arcgisscripting
>>> gp = arcgisscripting.create()
>>> gp.Describe('spain.shp').Extent
'356703.851202011 6161837.25290108 388919.895200729 6180982.37260246'

If you want the individual coordinates either use the 9.3 version of
creating the geoprocessor (with all its consecvenses), or just split
the returned string:
>>> gp.Describe('spain.shp').Extent.split()
['356703.851202011', '6161837.25290108', '388919.895200729', '
6180982.37260246']

And finally if you want the coordinates as floats and not strings, use
map and float:
>>> map(float, gp.Describe('spain.shp').Extent.split())
[356703.851202011, 6161837.25290108, 388919.895200729,
6180982.37260246]

/Niklas Norrthon

0 new messages