2

I have a large set of points (481,308) in single QGIS layer with the attribute table(ID, LAT, LONG,..ETC). But I only need points which fall inside particular area or polygon, I have fixed the extents of the polygon, as shown below:

1)North of Point1 12.978649° 77 .603701°

2)East of point1 12.952451° 77.633003°

3)East of point2 12.930359° 77.647210°

4)South of point2 12.893661° 77.636665°

5)West of point2 12.906764° 77.597081°

6)West of point1 12.952262° 77.577471°

What expression should I use to filter out points which come inside my polygon area?

2 Answers 2

3

Assuming coordinates are Lat/Long, an example layer from Random points in extent:

enter image description here

enter image description here

Use Select by expression with intersects() function between point's geometry and desired polygon:

intersects( $geometry, geom_from_wkt( 'POLYGON((77.603701 12.978649, 77.633003 12.952451, 77.647210 12.930359, 77.636665 12.893661, 77.597081 12.90676, 77.577471 12.952262, 77.603701 12.978649))' ))

Don't forget to close the polygon

The result:

enter image description here


Step by step procedure for this reproducible example:

enter image description here

11
  • 1
    And add spatial index to your point layer to seed up selection.
    – Zoltan
    Commented Jan 17, 2018 at 12:49
  • @Zoltan yes, thanks for your contribution. With Processing Toolbox / QGIS geoalgorithms / Vector general tools / Create spatial index
    – aldo_tapia
    Commented Jan 17, 2018 at 12:54
  • Thank you@aldo_tapia for your time. I used this expression as u mentioned intersects( $geometry, geom_from_wkt( 'POLYGON((77.603701 12.978649, 77.633003 12.952451, 77.647210 12.930359, 77.636665 12.893661, 77.597081 12.90676, 77.577471 12.952262, 77.603701 12.978649))' )), am getting output error, unexpected '(', expecting COMMA or ')'
    – Amar Cr
    Commented Jan 17, 2018 at 21:35
  • I am using QGIS 2.18, I didn't find Create spatial index under Vector general tools
    – Amar Cr
    Commented Jan 17, 2018 at 21:37
  • @AmarCr Do you have , as decimal separator in your computer?
    – aldo_tapia
    Commented Jan 17, 2018 at 21:37
0

You could create a polygon with your extent (I dont really understand how you define the polygon extent, the number of point is unclear...) then use the select by location fonction (in the vector menu or in the processing toolbox) to select your point.

enter image description here

Depending if you need to reuse the selection polygon you could create it in a temporary layer or in a more durable format.

You could also use the select by expression button with this expression (replace the X and Y by the vertices coordinate of your extent polygon)

within(  $geometry ,geom_from_wkt( 'POLYGON ((X1 Y1, X2 Y2, ... ...,Xn Yn ))'))

EDIT: if you want to filter your data you could try to adapt the previous expression to SQL in the query builder (I tried, but can't get it to work...)

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.