GDAL Python创建轮廓线
我想从Python中的SRTM图像生成轮廓线。它似乎在计算,但如果我想添加轮廓线,则不会显示任何内容,并且属性表也是空的。请看一下我的代码:GDAL Python创建轮廓线,python,gis,gdal,Python,Gis,Gdal,我想从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_
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和字段高程似乎为空,但等高线形状文件相当大~100MB
知道哪里出了问题吗
更新:我明白了!我忘了用:ogr_ds.Destroy()关闭数据源不要使用
Destroy()
方法
要保存和关闭数据集,请取消引用该变量,并可以选择将其删除
我通常在结束时使用它来保存/关闭GDAL或OGR数据集:
ogr_ds = None
del ogr_ds
解决了-我忘了用关闭数据源。销毁!您在这里使用的是什么版本的gdal?