2

I have a point feature that I would like to buffer to select segments that are within 15 meters of the point. The code I have is working but it's influenced by the map scale. Zooming in or out changes the buffer size. This is what I am using.

pntGeom = feature.geometry()
pntBuf = pntGeom.buffer(canvas.mapUnitsPerPixel()*15, 0)

is there a way to consistently buffer the point regardless of zoom level?

6
  • 1
    What language is that? It sort of looks like ArcObjects in VB... ITopologicalOperator.Buffer is the one I usually use. Commented Apr 21, 2015 at 3:24
  • Python. I can't remember where I learned about this code. github.com/cugos/qgisworkshop_org/blob/master/docs/source/… states that it is scale dependent. I am looking for something that is scale independent.
    – Terry
    Commented Apr 21, 2015 at 3:54
  • Um, what API? that's for QGIS.. but I suppose that both Esri and QGIS use the term 'feature' for essentially the same thing. According to qgis.org/api/… QgsGeometry.Buffer(distance,segments) isn't scale dependent... though you might want to use a value like 20 or 100 for 'segments'. What is the spatial reference units? is it metres, feet, inches or geographic? It gets a little more complicated if you're in geographic and want a 15' buffer. Commented Apr 21, 2015 at 4:00
  • Spatial reference is EPSG:4326 - WGS 84, so it is a bit tricky. I just tried different distances until I got about 15m which is good enough. I will boost up the segments to round it out as well. Thanks
    – Terry
    Commented Apr 21, 2015 at 4:48
  • 1
    The "correct" way is to use project to an appropriate projected coordinate system, buffer, then project back to WGS.. if you're happy with the results then that's all that matters. If you try this in a different part of the world you might need to adjust the buffer slightly to get it correct. Commented Apr 21, 2015 at 5:02

1 Answer 1

2

It looks like the answer was easier than I thought. All that needed to be done was take out mapUnitsPerPixel and and then find the correct distance (.00015)

pntBuf = pntGeom.buffer(.00015,0)

This works great without being affected by scale.

2
  • That number is quite small Terry, I think you're in geographic coordinates.. is that the case? Commented Apr 21, 2015 at 4:47
  • Yes, I am using an SQLite database point table which I load into QGIS using WGS84. Even though the buffer number is small, it seems to capture feature segments at the correct distance within about 15m from a point without getting features that were about 25m from the point. This worked at different scales as well. Not sure if there will be other issues.
    – Terry
    Commented Apr 21, 2015 at 5:05

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.