1

I'm digitizing some of our sewer assets and need to be able to measure distance and create points.

So, for instance, I have a sewer main that is 65m long. I need to mark a point at the 32m mark, then a further 6.2m.

The main is represented by a polyline and already exists. I want to be able to create the points in a separate layer. In my innocence, I'm imagining something like a ruler tool where I can click to drop a point at the distance locations I need.

I have read the examples where a regular pattern of points are created, and have tried using the v.to.points tool in GRASS, but none of these give me the result that I want.

I can do something like this in MapInfo, but would like to see if I can do it in QGIS.

1

I reconstructed Nathans code from Creating equidistant points in QGIS? for your convenience.

qgis pix

Open the Python Console and show the editor. Paste the code into the editor. A feature from the sewer layer need to be selected when the code is run.

Code change:

Line 3 and 4: The name of the sewer line and sewer point layers must be set.

Line 11: The distance in coordinate system units is set here.

Save the script with the second top button. Run the script with the blue triangle button.

Here is the code for copy paste:

import qgis.core
import qgis.utils
layerSewer = QgsMapLayerRegistry.instance().mapLayersByName('Sewer')[0]
layerPoint = QgsMapLayerRegistry.instance().mapLayersByName('SewerPoint')[0]
if layerSewer.selectedFeatureCount() != 1:
    print 'Exactly one feature must selected from sewer table'
else:
    ftSelectedSewer = layerSewer.selectedFeatures()[0]
    geomSewer = ftSelectedSewer.geometry()
    sewerLength = geomSewer.length()
    distance = 100
    if distance > sewerLength:
        print 'Distance can not be greater than selected line length'
    else:
        point = geomSewer.interpolate(distance)
        ftPoint = QgsFeature()
        ftPoint.setGeometry(point)
        ftPoint.setAttributes([distance])
        layerPoint.dataProvider().addFeatures([ftPoint])
        layerPoint.commitChanges()
        qgis.utils.iface.mapCanvas().refresh()

Error message is printed in the console output.

  • Thank you for the effort that you have gone to for me. I will test it out on my installation and provide feedback. – Johanna Feb 7 '14 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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