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")
GDAL/OGR이 Canopy Enthought와 함께 제공되며 다운로드하지 않았습니다. –