Monday, 29 April 2019

Is there a way in arcpy to convert map units from feet to decimal degrees?


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?



Answer




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

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...