1

I have a large set of data points which are falling away from my study area(Which is not required)Pls see image attached. I need to filter points which are falling within a radius of say 2km from the red line (POINT A AND B). How should I do in one command? As I have lot more files with a similar problem.

enter image description here

After I enter:

layer = iface.activeLayer()
for line in layer.selectedFeatures():
    print line.geometry().exportToWkt()

in python console, nothing is seen.

enter image description here

Where do i see the output?

Here is a link to the data.

2
  • 1
    Is your red line actually a line layer or is it points from the same layer?
    – Joseph
    Commented Jan 9, 2018 at 10:43
  • It's a Line layer. Points also exists on that line..
    – Amar Cr
    Commented Jan 10, 2018 at 10:47

1 Answer 1

1

Select your red line and type the following into the Python Console to get its coordinates in WKT (Well-Known Text) format:

layer = iface.activeLayer()
for line in layer.selectedFeatures():
    print line.geometry().exportToWkt()

It should print something like:

LineString (-0.35817092 2.07212114, 0.01439589 0.14525215)

Copy this then select your point layer and run the Select by expression tool either from the menubar (View > Select) or from the Processing Toolbox.

Then use an expression like (assuming your CRS units are in metres):

distance(geom_from_wkt('LineString (-0.35817092 2.07212114, 0.01439589 0.14525215)'), $geometry) <= 2000

This should select all points within 2 km of your line. You can filter them in whatever way you want (e.g. save them in a new shapefile, give them a new attribute which you can use for styling etc.).


Example of selecting points (highlighted in yellow) within 500 m from the red line (using marker points):

Example


I don't think there is a single command to achieve this other than creating a script.

17
  • When I type layer = iface.activeLayer() for line in layer.selectedFeatures(): print line.geometry().exportToWkt() and run, nothing happens in python console.. its not printing anything
    – Amar Cr
    Commented Jan 10, 2018 at 22:39
  • I have not worked with Python console before... Please bear with me...
    – Amar Cr
    Commented Jan 10, 2018 at 23:14
  • Don't worry about it :). You need to select the line layer from the Layers Panel and the line your interested in, they type the above in the Python Console :)
    – Joseph
    Commented Jan 11, 2018 at 10:12
  • I did... Nothing happened... It's not printing anything...
    – Amar Cr
    Commented Jan 11, 2018 at 12:18
  • @AmarCr - Would it be possible for you to share your line layer and a point layer?
    – Joseph
    Commented Jan 11, 2018 at 16:07

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.