无法加载PROJ.4程序库
问题描述:
lm后面的书和l键入示例代码,但是当我运行它时,它给出了这些errors.l m使用Enthought Canopy
以及所有必要的软件包。我该如何解决这个问题?我不想使用另一个软件包,因为有一些其他步骤需要使用ogr
。在Enthought Canopy
,升级了ogr
,但它没有帮助。无法加载PROJ.4程序库
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。
GDAL/OGR随着Canopy Enthought和我没有下载它们。 –