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?

Terry
  • 135
  • 1
  • 9
  • 1
    What language is that? It sort of looks like ArcObjects in VB... ITopologicalOperator.Buffer is the one I usually use. – Michael Stimson Apr 21 '15 at 03:24
  • Python. I can't remember where I learned about this code. https://github.com/cugos/qgisworkshop_org/blob/master/docs/source/_static/activate_click_1.py states that it is scale dependent. I am looking for something that is scale independent. – Terry Apr 21 '15 at 03: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 http://qgis.org/api/classQgsGeometry.html#a98208752e1beb1a5d3a7eedffbfdb2e4 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. – Michael Stimson Apr 21 '15 at 04: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 Apr 21 '15 at 04: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. – Michael Stimson Apr 21 '15 at 05:02
  • Makes sense. This will only be used by one person in house. re-projecting to a coordinate system may be better if this doesn't hold up. I will keep that in mind. – Terry Apr 21 '15 at 05:15

1 Answers1

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.

Terry
  • 135
  • 1
  • 9
  • That number is quite small Terry, I think you're in geographic coordinates.. is that the case? – Michael Stimson Apr 21 '15 at 04: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 Apr 21 '15 at 05:05