GDAL具有到PROJ4库的很好的便捷接口。
如果您对Python很有信心,请使用GDAL Python绑定,如果导入osr类,您将有非常方便的方法来读取和导出投影表示形式,并将其转换为各种格式,例如PROJ4,WKT,Esri .PRJ。
例如,此脚本会将您的shapefile的.PRJ文件转换为WKT和PROJ4(最后一个用于PostGIS):
#! /usr/bin/env python
import sys
from osgeo import osr
def esriprj2standards(shapeprj_path):
prj_file = open(shapeprj_path, 'r')
prj_txt = prj_file.read()
srs = osr.SpatialReference()
srs.ImportFromESRI([prj_txt])
print 'Shape prj is: %s' % prj_txt
print 'WKT is: %s' % srs.ExportToWkt()
print 'Proj4 is: %s' % srs.ExportToProj4()
srs.AutoIdentifyEPSG()
print 'EPSG is: %s' % srs.GetAuthorityCode(None)
esriprj2standards(sys.argv[1])
在命令行上运行此命令:
$ python esriprj2standards.py /home/pcorti/data/shapefile/country.prj
Shape prj is: GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
WKT is: GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Proj4 is: +proj=longlat +datum=WGS84 +no_defs
EPSG is: 4326