[gdal-dev] Re: prj to proj.4

Hermann Peifer peifer at gmx.eu
Wed Mar 25 13:31:07 EDT 2009


Howard Butler wrote:
> Looking at the .prj file and searching http://spatialreference.org might 
> also be productive.
> 
> Another option is to upload it to spatialreference.org, and you can then 
> get it in a number of formats.  This approach isn't recommended for a 
> lot of SRS's, but for a quick one-off sort of thing, it's pretty handy.
> 
> Howard
> 

Thanks for the hint, but I have 1000's of shapefiles which have all 
kinds of SRS's. So spatialreference.org doesn't seem to be the best 
option in my case. Rob's python script below actually looks like what I
was looking for. Python is available on my system. I am however not root 
there. I still have to convince the system admin to install the gdal 
site-package, so that I can: import osr

Hermann

> On Mar 25, 2009, at 5:49 AM, Robert Coup wrote:
> 
>> 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])
>>
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev



More information about the gdal-dev mailing list