User Tools

Site Tools


gis:postgresql-postgis-notes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
gis:postgresql-postgis-notes [2022/03/21 09:07]
Ilias Iliopoulos [Get the nearest neighbours using spatial indexing]
gis:postgresql-postgis-notes [2024/01/23 12:48]
Ilias Iliopoulos [Locate the points of a Point layer that are outside polygons of a Polygon layer]
Line 94: Line 94:
 LIMIT 5 LIMIT 5
 </​code>​ </​code>​
 +
 +===== Identify the points of a Point layer that are outside polygons of a Polygon layer =====
 +
 +There are multiple queries that you can use to solve this problem. You can find an interesting discussion in [[https://​gis.stackexchange.com/​questions/​376234/​find-polygons-that-has-no-points-in-postgis|Find polygons that has no points in PostGIS]]. For big data sets, I have found that the query that executes in the shortest time is:
 +
 +<​code>​
 +SELECT polygons.id FROM polygons WHERE NOT EXISTS
 +(SELECT 1 FROM points WHERE ST_Intersects(polygons.geom,​ points.geom))
 +</​code>​
 +
 +For comparison purposes, in a data set with 45.000 points and 45.000 buildings, this query took approximately 4 minutes, while other queries took more than 14 minutes!
 +
 +**WARNING:​** You need to pay particular attention on how much is exactly "​outside"​. You may encounter cases where the point is considered to be at exactly the perimeter of the polygon, because it has been "​snapped"​ at the side of the polygon, using the snapping features of your GIS software. Yet, there is always a tolerance in snapping and the point might be geometrically within a few tenths of a millimeter inside or outside the polygon. A very small buffer area should be considered around the point to account for this ambiguity. ​
  
 ===== Import an SHP file manually ===== ===== Import an SHP file manually =====
gis/postgresql-postgis-notes.txt ยท Last modified: 2024/02/02 21:49 by Ilias Iliopoulos