已知一个GeoTiff,得到其边界矢量的方法
来源:互联网 发布:淘宝流量卫士 编辑:程序博客网 时间:2024/06/07 09:40
在制作GeoTiff的样本时,经常需要知道它的边界矢量,原因如下:
- 没有原始的裁切矢量;
- 裁切它的矢量栅格化后与影像相差一个像素;
代码摘要:
- 制作一个与原影像同坐标系但是值全部为0的中间影像A;
- 将A矢量化
不足:
- 没有坐标系,需要手动添加
附代码
import gdalimport ogrimport sysimport cv2import numpy as npimport osimport osrdef main(argv): if len(argv) < 2: print('[target image] [shpfile name]') sys.exit(0) # this allows GDAL to throw Python Exceptions gdal.UseExceptions() # get raster datasource src_DS = gdal.Open(argv[1]) if src_DS is None: print('Unable to open %s' % src_filename) sys.exit(1) # create a temp tif file to simplify polygonize xsize = src_DS.RasterXSize ysize = src_DS.RasterYSize arr = np.zeros([ysize, xsize]) # in case of 'tif' or 'tiff' if argv[1][-5] == '.': temp_tif_fn = argv[1][0:-5] + '_temp.tif' else: temp_tif_fn = argv[1][0:-4] + '_temp.tif' cv2.imwrite(temp_tif_fn, arr) # add geo info geoTrans = src_DS.GetGeoTransform() srcPro = src_DS.GetProjection() target_ds = gdal.Open(temp_tif_fn,gdal.GA_Update) target_ds.SetGeoTransform(geoTrans) target_ds.SetProjection(srcPro) target_ds.FlushCache() target_ds = None src_DS = gdal.Open(temp_tif_fn) srcband = src_DS.GetRasterBand(1) # create output datasource # output datasource file name if argv[1][-5] == '.': dst_layername = argv[1][0:-5] else: dst_layername = argv[1][0:-4] drv = ogr.GetDriverByName("ESRI Shapefile") dst_ds = drv.CreateDataSource(dst_layername + ".shp") dst_layer = dst_ds.CreateLayer(dst_layername, srs = None ) gdal.Polygonize( srcband, None, dst_layer, -1, [], callback=None ) # TODO: add geo info to shpfile del src_DS os.remove(temp_tif_fn)if __name__ == "__main__": main(sys.argv)
阅读全文
0 0
- 已知一个GeoTiff,得到其边界矢量的方法
- 一种快速得到点云近似边界球的方法
- 一种得到点云精确边界球的方法
- 反编译apk文件,得到其源代码的方法
- 反编译apk文件,得到其源代码的方法
- 反编译apk文件,得到其源代码的方法!
- 反编译apk文件,得到其源代码的方法
- 反编译apk文件,得到其源代码的方法!!
- 反编译apk文件,得到其源代码和资源的方法
- 反编译apk文件,得到其源代码的方法!!
- 反编译apk文件,得到其源代码的方法
- 反编译apk文件,得到其源代码的方法
- 反编译apk文件,得到其源代码的方法!!
- 反编译apk文件,得到其源代码的方法!!
- c调用程序并得到其输出的方法
- rplidar使用hector_slam的hector_mapping geotiff创建地图方法
- rplidar使用hector_slam的hector_mapping geotiff创建地图方法(2)
- 下载矢量行政边界
- SpringBoot非官方教程 | 第十篇: 用spring Restdocs创建API文档
- JAVA List<Map>结果集处理方法集合
- 对datatable对象参数进行部分配置以及说明
- Voxel Space:不到20行代码实现地形渲染
- 【Scikit-Learn 中文文档】神经网络模块(监督的)- 监督学习
- 已知一个GeoTiff,得到其边界矢量的方法
- Problem J 小鑫need help
- 从高性能计算(HPC)技术演变解析方案、生态和行业发展趋势
- (二)大型互联网分布式企业微服务云架构
- C# 获取某月的第一天和最后一天
- SAP 全球产品营销总监:产品营销驱动 B2B 企业爆发式增长的 6 大要点
- 从0到1教你设计业务系统
- “The import XXX cannot be resolved” (跨工程引用类)
- 【Scikit-Learn 中文文档】高斯混合模型