如何从 shapefile 的 .prj 文件获取 Proj4 详细信息?

发布于 2024-09-07 19:39:12 字数 965 浏览 11 评论 0原文

我正在为 GIS 应用程序使用 Mapdotnet 服务来加载 shapefile,并且此 Mapdotnet 服务需要 proj4 详细信息。我从 Spatialreference.org 获取它们,但对于 此投影 proj4 详细信息是空白。如何从 .prj 文件或 shapefile 获取 proj4 详细信息?

以下是 shapefile 的 .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]]

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

花伊自在美 2024-09-14 19:39:12

您还可以使用此 Python 脚本(可以在 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])

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])
幸福%小乖 2024-09-14 19:39:12

使用 和 rgdal 库的替代方案:

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

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
别挽留 2024-09-14 19:39:12

另一个使用 perl 脚本的解决方案(需要 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";

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";
嘦怹 2024-09-14 19:39:12

应该可以从各个组件中计算出来。 Proj.4 允许指定所有内容。您将需要 ESRI 文档来获取其 PRJ 文件。这将包括它们的定义(例如,NAD83_HARN 和普通 NAD83 之间有什么区别?它们可能相同,但我不知道)

另一种方法可能是查看 GDAL/OGR 库和实用程序。它们能够读取大多数 PRJ 文件。

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.

贪了杯 2024-09-14 19:39:12

我使用了 PyCRS来自圣地亚哥 GIS 门户的 APN shapefile 地址

PyCharm 中的 Python 控制台:

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

输出:

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

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'
枫以 2024-09-14 19:39:12

安装 GDAL

conda install -c conda-forge python gdal 

为 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())

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())
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文