python - 无法加载 PROJ.4 库

标签 python ogr

我正在阅读一本书并输入示例代码,但是当我运行它时,它给出了这些错误。我使用Enthought Canopy以及所有必要的包。我该如何解决这个问题?我不想使用另一个包,因为还有一些其他步骤我需要使用 ogr。在 Enthought Canopy 上,我更新了 ogr 但它没有帮助。

ERROR 6: Unable to load PROJ.4 library (proj.dll), creation of
OGRCoordinateTransformation failed.

这里是示例代码:

from    __future__  import  print_function
import ogr
import osr

def open_shape_file(file_path):
    #Open   the shapefile,  get the first   layer   and returns
    #the    ogr datasource.

    datasource=ogr.Open(file_path)
    layer=datasource.GetLayerByIndex(0)
    print ("opening {}".format(file_path))
    print ("Number of feature:{}".format(layer.GetFeatureCount()))
    return datasource
def transform_geometries(datasource,    src_epsg,   dst_epsg):
#Transform  the coordinates of  all geometries  in  the
#first  layer.

#   Part    1
    src_srs =   osr.SpatialReference()
    src_srs.ImportFromEPSG(src_epsg)
    dst_srs =   osr.SpatialReference()
    dst_srs.ImportFromEPSG(dst_epsg)
    transformation  =   osr.CoordinateTransformation(src_srs,   dst_srs)
    layer   =   datasource.GetLayerByIndex(0)
#   Part    2
    geoms   =   []
    layer.ResetReading()
    for feature in  layer:
        geom    =   feature.GetGeometryRef().Clone()
        geom.Transform(transformation)
        geoms.append(geom)
    return  geoms

datasource=open_shape_file("D:/python/python_geospe/exampledata/TM_WORLD_BORDERS/TM_WORLD_BORDERS-0.3.shp")
layer   =   datasource.GetLayerByIndex(0)
feature =   layer.GetFeature(0)
print("Before   transformation:")
print(feature.GetGeometryRef())
transformed_geoms   =   transform_geometries(datasource,    4326,   3395)
print("After    transformation:")
print(transformed_geoms[0])

open_shape_file("D:/python/python_geospe/exampledata/TM_WORLD_BORDERS/TM_WORLD_BORDERS-0.3.shp")

最佳答案

您的环境变量设置正确吗? proj.dll 通常位于 C:\Program Files (x86)\GDAL 中。您需要使用此路径设置环境变量。

建议您关注this installation guide解释了在 Windows 操作系统中正确安装 GDAL/OGR 的过程。

另一个指南:here .

关于python - 无法加载 PROJ.4 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43206742/

相关文章:

python - 如何将数据写入 h5py 数据集

python - 将多个键/值关联到 defaultdict(list)

gis - GDAL、FDO和OGR之间是什么关系?

readOGR(), "cannot open file"错误

python - 在图像分析中将阴影与其来源相关联

python - 如何检测字符串是否已更改

python - 如何在 Python 中设置架构以在 BigQuery 上使用 json 文件?

python - sqlalchemy,说小数没有定义?

c++ - 如何使用带有 C++ 的 ogr 库在 ESRI shapefile 中提取几何图形的顶点

sql-server-2008 - 使用 Ogr2ogr 从 SQL Server 创建形状文件