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.

some shapefiles have a .prj file associated with it. and the .prj file contains the projection info of the shapefile in the format of WKT. Sometimes I need to convert WKT to proj4 string, and sometimes I need to convert it back.

Is there any ready-made library to do this?

Thanks in advance.

share|improve this question

2 Answers 2

The OGR Spatial Reference part of GDAL should do the trick. capooti provided an excellent answer to another question which demonstrates how to peform the translation from a shapefile to WKT. You may also want to check out the class reference. The reverse is simply:

from osgeo import osr

srs = osr.SpatialReference()
wkt_text = 'GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",' \
           'SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],'\
           'UNIT["Degree",0.017453292519943295]]'

srs.importFromWkt(wkt_text)
srs.morphToESRI() # converts the WKT to an ESRI-compatible format
print "ESRI compatible WKT for use as .prj:" % srs.ExportToWkt()
share|improve this answer

I don't know any library, but you can use this site to get the translations: http://spatialreference.org/

EDIT: I found a python script that works with ogr python bindings to do that. Here it is.

share|improve this answer
    
thanks, but i need to do that programmatically. –  CuiPengFei Apr 14 '11 at 16:11
1  
After some googling: spatialreference.org is powered by GDAL as well & uses the same code path (more or less), it seems. –  Dan S. Apr 14 '11 at 17:11
    
That's interesting –  Pablo Apr 14 '11 at 18:33

Your Answer

 
discard

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.