create buffer using gdal in python


/ Published in: Python
Save to your folder(s)

create buffer polygon from shapefile


Copy this code and paste it in your HTML
  1. #now open the shapefile
  2. shp = ogr.Open(shpfile)
  3.  
  4. drv = shp.GetDriver()
  5. drv.CopyDataSource(shp, buffile)
  6.  
  7. shp.Destroy()
  8.  
  9. buf = ogr.Open(buffile, 1)
  10. lyr = buf.GetLayer(0)
  11.  
  12. for i in range(0, lyr.GetFeatureCount()):
  13. feat = lyr.GetFeature(i)
  14. lyr.DeleteFeature(i)
  15. geom = feat.GetGeometryRef()
  16. feat.SetGeometry(geom.Buffer(1000.0))
  17. lyr.CreateFeature(feat)
  18.  
  19. buf.Destroy()

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.