2

This is my problem: I have an arcpy script that finds the XMax, XMin, YMax, and YMin of a polygon. It shows the results in feet, but I want them to be in decimal degrees.

In ArcMap I can change the data frame's display units to decimal degrees. But every time I run my script it shows the numbers in feet again.

Is there a solution for this in arcpy?

2 Answers 2

4

You can define a SearchCursor on the layer holding the polygon, and specify a spatial reference:

When specified, features will be projected on the fly using the spatial_reference provided.

See the help file under Setting a cursor's spatial reference for more info on setting up the search cursor with a new coordinate system. Once you've defined the cursor, you can find the projected extent using:

rows = arcpy.SearchCursor(featureclass,query,spatialReference)
row = rows.next()
polygon = row.shape
extent = polygon.extent
2

If you can't get an answer by using a SearchCursor (as per @StephenLead 's answer above) you could look at downloading the pyproj library. As long as you know the relevant definition of your projection (which you can get from www.spatialreference.org), you can easily convert from one projection to another. For example:

import numpy as np
import pyproj

lonlat = np.array[[135.5, 135.4], [-47.5, -47.6]] #replace with your own data

vicgrid94 = pyproj.Proj(init='epsg:3111') #replace this with your own projection
gda94 = pyproj.Proj(init='epsg:4283') #Australian geographic coordinate system
                                      #WGS84 = epsg:4326 for comparison

#first option
xy = pyproj.transform(gda94, vicgrid94, lonlat[0], lonlat[1])

#first option
print vicgrid94(xy[0], xy[1], inverse=True) #With inverse=True transforms coordinates
                                            #in projection to lat long
                                            #Note: floating point error will be obvious

Your Answer

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

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