from osgeo import gdal, ogr import sys # this allows GDAL to throw Python Exceptions gdal.UseExceptions() # # get raster datasource # src_ds = gdal.Open( "INPUT.tif" ) if src_ds is None: print 'Unable to open %s' % src_filename sys.exit(1) try: srcband = src_ds.GetRasterBand(3) except RuntimeError, e: # for example, try GetRasterBand(10) print 'Band ( %i ) not found' % band_num print e sys.exit(1) # # create output datasource # dst_layername = "POLYGONIZED_STUFF" 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 )
把一个单一的栅格带变成一个矢量多边形!
如果你以前没有,请注意一些GDAL又实际上是Python脚本。在你的电脑上找到他们,阅读源代码和我的他们的原料药的技巧。原来,gdal_polygonize效用只是把电话gdalfpolygonize所以自己写hacky多边形化的Python脚本是很容易的。
我们将多边形化栅格:
Copyright © Since 2014.
开源地理空间基金会中文分会
吉ICP备05002032号
Powered by TorCMS