The second data label production

1. House adds value255

2. Raster edge to vector

from osgeo import gdal,ogr,osr
import fnmatch
import os
ogr.RegisterAll()
img_path="D:/Two/valid/" #影像所在的文件夹
shape_path="D:/Two/shp_house" #shape输出位置
if not os.path.exists(shape_path):
    os.mkdir(shape_path)
img_list = fnmatch.filter(os.listdir(img_path), '*.tif')
for img in img_list:
    p_img=img_path+'/'+img
    outfilename = shape_path+'/'+img[:-4]+".shp"
    dataset = gdal.Open(p_img)
    oDriver = ogr.GetDriverByName('ESRI Shapefile')
    oDS = oDriver.CreateDataSource(outfilename)
    srs = osr.SpatialReference(wkt=dataset.GetProjection())
    geocd = dataset.GetGeoTransform()
    oLayer = oDS.CreateLayer("polygon", srs, ogr.wkbPolygon)
    oDefn = oLayer.GetLayerDefn()
    row = dataset.RasterXSize
    line = dataset.RasterYSize
    geoxmin = geocd[0]
    geoymin = geocd[3]
    geoxmax = geocd[0] + (row) * geocd[1] + (line) * geocd[2]
    geoymax = geocd[3] + (row) * geocd[4] + (line) * geocd[5]
    ring = ogr.Geometry(ogr.wkbLinearRing)
    ring.AddPoint(geoxmin, geoymin)
    ring.AddPoint(geoxmax, geoymin)
    ring.AddPoint(geoxmax, geoymax)
    ring.AddPoint(geoxmin, geoymax)
    ring.CloseRings()
    poly = ogr.Geometry(ogr.wkbPolygon)
    poly.AddGeometry(ring)
    outfeat = ogr.Feature(oDefn)
    outfeat.SetGeometry(poly)
    oLayer.CreateFeature(outfeat)
    outfeat = None
    oDS.Destroy()

3、

second step

Element plus layer field 255

G:\iData\layer\tmp\%name%.shp

A_A 

A_B

4 0.2 19
B 4 0.0916073
C

0.101986

Guess you like

Origin blog.csdn.net/weixin_61235989/article/details/129836346