2017-04-04 23 views
1

lm 책을 읽고 예제 코드를 입력했지만 실행할 때 Enthought Canopy을 사용하여 이러한 오류가 발생했습니다. 필요한 모든 패키지가 포함되어 있습니다. 이 문제를 어떻게 풀 수 있습니까? 다른 패키지를 사용하고 싶지 않습니다. ogr을 사용해야합니다. Enthought Canopy을 입력해야합니다. ogr을 업데이트했지만 도움이되지 않았습니다.PROJ.4 라이브러리를로드 할 수 없습니다.

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

답변

1

가 올바르게 환경 변수를 설정 했 : 여기

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

은 예제 코드이다? proj.dll은 일반적으로 C:\Program Files (x86)\GDAL에 있습니다. 이 경로로 환경 변수를 설정해야합니다.

Windows OS에 GDAL/OGR을 올바르게 설치하는 과정을 설명하는 this installation guide을 따르는 것이 좋습니다.

다른 안내서 : here.

+0

GDAL/OGR이 Canopy Enthought와 함께 제공되며 다운로드하지 않았습니다. –