[gdal-dev] prj to proj.4

Robert Coup robert.coup at onetrackmind.co.nz
Wed Mar 25 06:49:12 EDT 2009


Hi Hermann,
On Wed, Mar 25, 2009 at 9:06 PM, Hermann Peifer <peifer at gmx.eu> wrote:

>
> I am looking for a convenient way to convert the SRS parameters from a
> random shapefile.prj into proj.4 format. A command line interface would be
> most helpful for a non-programmer, like me.
>
>
If you have python on your system (likely), then you can create a python
script (eg. prj2proj.py) with the following code in it, then run "python
prj2proj.py my.prj" and it'll print the proj4 equivalent of the my.prj file.

HTH,

Rob :)


#!/usr/bin/env python

import osr
import sys

def main(prj_file):
    prj_text = open(prj_file, 'r').read()
    srs = osr.SpatialReference()
    if srs.ImportFromWkt(prj_text):
        raise ValueError("Error importing PRJ information from: %s" %
prj_file)
    print srs.ExportToProj4()

if __name__=="__main__":
    main(*sys.argv[1])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20090325/48f30913/attachment.html


More information about the gdal-dev mailing list