【问题标题】:How can I get Proj4 details from the shapefile's .prj file?如何从 shapefile 的 .prj 文件中获取 Proj4 详细信息?
【发布时间】:2010-06-30 12:13:11
【问题描述】:

我正在为我们的 gis 应用程序使用 mapdotnet 服务来加载 shapefile,而这个 mapdotnet 服务需要 proj4 详细信息。我从spatialreference.org 获得它们,但对于this projection,proj4 的详细信息是blank。如何从 .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]]

【问题讨论】:

  • 像这样的 GIS 重大问题可能会在 GIS Stack Exchange 上引起更高级别的专家关注。

标签: map gis shapefile map-projections


【解决方案1】:

您也可以使用这个 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])

【讨论】:

  • 如果您无法“导入 osr”,请尝试安装 GDAL python 模块(pip install gdal),然后“从 osgeo 导入 o​​sr”。
【解决方案2】:

使用 和 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

【讨论】:

    【解决方案3】:

    另一种使用 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";
    

    【讨论】:

      【解决方案4】:

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

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

      【讨论】:

        【解决方案5】:

        我使用了来自圣地亚哥 GIS 门户的 PyCRSAddress 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'
        

        【讨论】:

          猜你喜欢
          • 2014-10-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-12-07
          • 2012-03-22
          • 1970-01-01
          • 1970-01-01
          • 2015-11-14
          相关资源
          最近更新 更多