开发者

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

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.8722开发者_StackOverflow8112638889],PARAMETER["Scale_Factor",1.000035079],PARAMETER["Latitude_Of_Origin",45.87228112638889],UNIT["Foot_US",0.3048006096012192]]


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])


Alternative using r 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


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";


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.


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'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜