2
Hej人,我想從Python中的SRTM圖像生成等高線。它似乎計算,但如果我想添加我的輪廓線沒有出現,屬性表也是空的。請看看我的代碼:GDAL Python創建等高線
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關閉數據源! –