0

I have the MSA/CMSA shapefile which contains 274 metropolitan areas. How do I have to obtain the maximum/minimum longitude and latitude for an area?

So, it's like drawing a box right outside and getting the 4 corner points in the lon/lat format.

Can we do this using Python to iterate the process for all the cities and to export the coordinates to a text file as follows?:

msa     min_lon   max_lon   min_lat  max_lat
6162   -76.XXXX  -74.XXXX   38.XXXX  40.XXXX
9094   -97.XXXX  -96.XXXX   37.XXXX  38.XXXX
....
....
5

Unless I'm misunderstanding the question, the shape's .extent property is all you need.

with open('out.txt', 'wb') as out_text_file, arcpy.da.SearchCursor('path_to_data', ('msa', 'SHAPE@')) as cur:
    print >>out_text_file, "msa     min_lon   max_lon   min_lat  max_lat"
    for row in cur:
        msa, ext = row[0], row[1].extent
        print >>out_text_file, "{0:5}   {1:2.4}   {2:2.4}   {3:2.4}   {4:2.4}".format(msa, ext.XMin, ext.XMax, ext.YMin, ext.YMax)
  • Thanks. I did like "{0:4} {1:2.10} {2:2.10} {3:2.10} {4:2.10}". Sorry but how to print things line by line? It looks like: sacmsa min_lon max_lon min_lat max_lat 3605 1648730.629 1706965.272 -179218.143 -120887.8656 4880 -260536.0373 -187164.4402 -1272776.399 -1190140.498 7920 208472.9416 291854.6719 -73215.75796 2990.560084 6280 1288788.431 1425130.378 364249.6568 527714.2303 3362 -18462.7105 159514.9954 -967557.6621 -767405.1027 1602 579024.2094 753153.3687 417992.4495 ......... – Bill TP Apr 8 '14 at 2:29
  • Try putting \n on the last line immediately before the second double quote. – PolyGeo Apr 8 '14 at 2:58
  • Adding \n does not work. Another question: The liner unit is in meters as you see the numbers I posted earlier. How can I change them to decimal degrees in ArcGIS? The current projection is USA_Contiguous_Albers_Equal_Area_Conic. And its unit is meter. – Bill TP Apr 8 '14 at 3:47
  • Read the help for arcpy.da.SearchCursor. You can pass a geographic spatial reference and the coordinates will be output in lon/lat. – user2856 Apr 8 '14 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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