作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在 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()
方法,as described in the GDAL/OGR Python Gotchas .
要保存和关闭数据集,取消引用变量,并可选择删除它。
我通常在最后使用它来保存/关闭 GDAL 或 OGR 数据集:
ogr_ds = None
del ogr_ds
关于python - GDAL Python 创建轮廓线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22100453/
作为自学练习,我正在尝试从头开始对线性回归问题实现梯度下降,并将生成的迭代绘制在等高线图上。 我的梯度下降实现给出了正确的结果(使用 Sklearn 测试)但是梯度下降图似乎并不垂直到等高线。这是预期
我加载了一个 1000 万行文本文件,并将其作为字符串存储在变量“someString”中。我想生成一个数组,其中每一行都是一个项目。我知道要做到这一点,我会执行以下操作: var files = s
我是一名优秀的程序员,十分优秀!