【发布时间】:2014-02-28 16:23:05
【问题描述】:
我想在 Python 中从 SRTM 图像生成轮廓线。它似乎在计算,但如果我想添加我的轮廓线,什么都不会显示,并且属性表也是空的。请看我的代码:
from osgeo import gdal, gdal_array
from osgeo.gdalconst import *
from numpy import *
from osgeo import ogr
#Read in SRTM data
indataset1 = gdal.Open( src_filename_1, GA_ReadOnly)
in1 = indataset1.GetRasterBand(1)
#Generate layer to save Contourlines in
ogr_ds = ogr.GetDriverByName("ESRI Shapefile").CreateDataSource(dst_filename)
contour_shp = ogr_ds.CreateLayer('contour')
field_defn = ogr.FieldDefn("ID", ogr.OFTInteger)
contour_shp.CreateField(field_defn)
field_defn = ogr.FieldDefn("elev", ogr.OFTReal)
contour_shp.CreateField(field_defn)
#Generate Contourlines
gdal.ContourGenerate(in1, 100, 0, [], 0, 0, contour_shp, 0, 1)
ogr_ds.Destroy()
字段 ID 和字段高度似乎为空,但 contour_shape 文件相当大 ~ 100MB。
知道可能出了什么问题吗?
更新:我明白了!我忘了关闭数据源:ogr_ds.Destroy()
【问题讨论】:
-
解决了 - 我忘了用 .Destroy 关闭数据源!
-
你这里用的是什么版本的gdal?