How can I get Proj4 details from the shapefile's .prj file?
Asked Answered
D

6

5

I am using mapdotnet services for our gis application to load the shapefiles, and this mapdotnet service wants the proj4 details. I'm getting them from spatialreference.org, but for this projection the proj4 details are blank. How can I get the proj4 details from the .prj file or from the shapefile?

Below is the shapefile's .prj:

PROJCS["NAD_1983_HARN_WISCRS_EauClaire_County_Feet",GEOGCS["GCS_North_American_1983_HARN",DATUM["D_North_American_1983_HARN",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",394000.0],PARAMETER["False_Northing",300812.797],PARAMETER["Central_Meridian",-91.28888888888889],PARAMETER["Standard_Parallel_1",45.87228112638889],PARAMETER["Scale_Factor",1.000035079],PARAMETER["Latitude_Of_Origin",45.87228112638889],UNIT["Foot_US",0.3048006096012192]]
Diathesis answered 30/6, 2010 at 12:13 Comment(1)
GIS heavy questions like this might get a higher level of expert attention over at GIS Stack Exchange.Retaliate
E
6

You can also use this Python script (seen elsewhere on the Internet):

#!/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()
    #print srs.ExportToWkt()

if __name__=="__main__":
    main(sys.argv[1])
Ensnare answered 5/10, 2011 at 23:33 Comment(1)
In case you cannot "import osr", try installing the GDAL python module (pip install gdal) and then "from osgeo import osr".Gurrola
V
2

Alternative using and the rgdal library:

library(rgdal)
# read the .shp file - layer is the same name but without the .shp
mymap <- readOGR("CA_tract_2000.shp", layer="CA_tract_2000") 
# proj4 info is located in the layer's proj4string slot
mymap@proj4string
Viera answered 14/2, 2011 at 4:42 Comment(0)
A
2

Another solution using a perl script (requires Geo::GDAL):

#!/usr/bin/perl -w
use strict;
use Geo::OSR;
my $srs = Geo::OSR::SpatialReference->new;
my $prj_text = do { open my $fh, shift or die $!; local $/; <$fh> };
$srs->ImportFromWkt($prj_text);
print $srs->ExportToProj4, "\n";
Assimilable answered 9/1, 2012 at 9:38 Comment(0)
C
0

It should be possible to work it out from the individual components. Proj.4 allows everything to be specified. You will need the ESRI documentation for their PRJ files. This will include their definitions (eg. what is the difference between NAD83_HARN and normal NAD83? they migth be the same but I don't know)

another approach might be to look at the GDAL/OGR library and utilities. These are capable of reading most PRJ files.

Casabonne answered 18/11, 2010 at 22:55 Comment(0)
N
0

I used PyCRS and the Address APN shapefile from San Diego's GIS portal.

Python console in PyCharm:

import pycrs
crs = pycrs.load.from_file("C:\GIS\Address_APN\Address_APN.prj")
crs.to_proj4()

Output:

> '+proj=lcc +datum=NAD83 +ellps=GRS80 +a=6378137.0 +rf=298.257222101
> +pm=0 +x_0=6561666.666666666 +y_0=1640416.666666667 +lon_0=-116.25 +lat_1=32.78333333333333 +lat_2=33.88333333333333 +lat_0=32.16666666666666 +units=us-ft +axis=enu +no_defs'
Nicolanicolai answered 3/7, 2020 at 22:39 Comment(0)
R
0

Install GDAL

conda install -c conda-forge python gdal 

For python 3

from osgeo import osr
import sys

prj_text = open('some.prj', 'r').read()
srs = osr.SpatialReference()
srs.ImportFromWkt(prj_text)

print(srs.ExportToProj4())
Romansh answered 10/2, 2023 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.