I have a layer of a csv file with around 700k rows and a polygon layer, both are in wgs84.

I'm trying with the spatial query to calculate what point are in the polygons.

The problem is that the spatial query doesn't count all the points when it's finished, as in the attached picture.

It should mark all points within the polygon.

enter image description here

  • can you try the spatial query plugin from the processing toolbox? the plugin has been deprecated in favor of the processing tool.
    – SaultDon
    Dec 13, 2017 at 3:40

2 Answers 2


Try to use Select Within Plugin instead of Spatial Query. It is useful mainly within the selections between two polygon layers, but it should work to select points located within polygon layer.

Another advice is to save the CSV points as a shapefile. Try not to use CSV directly to select points located within polygon layer and use shapefile with a CRS of WGS 84 to keep it consistent with the CRS of the polygon layer. Sometimes working with CSV directly in QGIS can produce undesirable result.


Agree that csv might cause problems. Another hint would be to check if your polygon layer has no topological inconsistencies (invalid geometries, i.e. duplicate consecutive points, self intersections, ...) You can check this under Vector > Topology Checker (under Plugins, active the Topology Checker Plugin). This shows you in the map where possible topo issues occur.

For further reading about repairing invalid geometries i.e. cp.


Fixing geometry validity errors in QGIS?


It's not totally clear to me, whether you only want to select (or extract) the points WITHIN your polygon, or if you want to calculate statistics for the points within your polygons (counting them would be such statistics). In the first case you can use Select by location or Extract by location algorithms in the processing toolbox, in the latter case you can use algorithms like GRASS 7 v.vect.stats (cp. Populating polygon with most frequent point attribute using QGIS?) or SAGA point statistics for polygons (each found in the processing toolbox). I observed, that QGIS Join attributes by location algorithm produces weird results in some situations (cp. QGIS 'join attributes by location' algorithm produces strange results for min, max), but this might have been fixed meanwhile.

Here is a screenshot where to find the algorithms, in each you can select 'Save to file', where you can even choose csv format:

enter image description here

enter image description here

  • Hi. I want to make a selection of the points within the polygons and then save the selected ones to a csv file.
    – Tobbe
    Dec 13, 2017 at 8:25
  • I think in this case Extract by location is the tool for you. This generates a new layer or can save directly to csv. But be aware to 1. do the topo check 2. convert your points to shp before your analysis. Dec 13, 2017 at 8:29
  • I've used the extract by location now and i get the exact same problem. Also used the topology checker and no problems where found
    – Tobbe
    Dec 13, 2017 at 10:47
  • Can you upload and provide your datasets somwhere to have a closer look at? Dec 13, 2017 at 10:49
  • I ran the Topology checker again and it finds 273 invalid geometry. Is there a way to automatically correct these?
    – Tobbe
    Dec 13, 2017 at 10:57

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.