2

I am trying to make a buffer from a line using gdal.

I use the example in the gdal Cookbook

import ogr, os
def createBuffer(inputfn, outputBufferfn, bufferDist):
 inputds = ogr.Open(inputfn)
 inputlyr = inputds.GetLayer()
 shpdriver = ogr.GetDriverByName('ESRI Shapefile')
 if os.path.exists(outputBufferfn):
 shpdriver.DeleteDataSource(outputBufferfn)
 outputBufferds = shpdriver.CreateDataSource(outputBufferfn)
 bufferlyr = outputBufferds.CreateLayer(outputBufferfn, geom_type=ogr.wkbPolygon)
 featureDefn = bufferlyr.GetLayerDefn()
 for feature in inputlyr:
 ingeom = feature.GetGeometryRef()
 geomBuffer = ingeom.Buffer(bufferDist)
 outFeature = ogr.Feature(featureDefn)
 outFeature.SetGeometry(geomBuffer)
 bufferlyr.CreateFeature(outFeature)
 def main(inputfn, outputBufferfn, bufferDist):
 createBuffer(inputfn, outputBufferfn, bufferDist)
 if __name__ == "__main__":
 inputfn = 'obli.shp'
 outputBufferfn = 'oblibuffer001.shp'
 bufferDist = 0.01
 main(inputfn, outputBufferfn, bufferDist)
 # creating the projection file. Not included in the cookbook
 prj = open('oblibuffer001.prj', 'w')
 proyeccion = 'GEOGCS["GCS_WGS_1984",
 DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],' \
 'PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]'
 prj.write(proyeccion)
 prj.close()

It works fine

http://pcjericks.github.io/py-gdalogr-cookbook/vector_layers.html?highlight=buffer

But I can not understand exactly what kind of units I must use in the bufferDist

Ussing 0.01 I think it was a kilometre but the result is different depending the direction of the line. For example Using a parallel_direction_line using bufferDist = 0.01 meassured in the map the buffer is 1,1 km a meridiam_direction_line using bufferDist = 0.01 meassured in the map the buffer is 0.456 km

but a oblicual_direction_line using bufferDist = 0.01 meassured in the map the buffer is 0,57 km

How can I find the value for the bufferDist variable I think depends on the latitude and the direction of the line?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Nov 19, 2014 at 17:29

1 Answer 1

1

Your buffer distance is given in the units of your dataset. Your coordinate system is lon/lat geographic. Thus 0.01 = 0.01 decimal degrees. To be able to buffer by 1 km (1000 m) you need to reproject your dataset to a projected coordinate system which has units in metres.

There are examples in the Python GDAL/OGR Cookbook of how to reproject layers and geometries.

answered Nov 19, 2014 at 21:26
3
  • Then, Is it posible to buffer ussing milles ? or is a stupid thing Commented Nov 20, 2014 at 17:46
  • Then, Is it posible to buffer using miles ? or is a stupid thing. 1º = 60' then 1 mille = 0.00166 in the buffer. I am working with some shapes in WGS84 without protection, then I try to maintain the whole shapes without project. What do you think about Commented Nov 20, 2014 at 17:52
  • You can buffer in miles if you reproject your layer to a coordinate system that uses metres (1 mile = 1609.34 m) or feet (1 mile = 5280 ft) as the units. Commented Nov 20, 2014 at 18:56

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.