File tree 1 file changed +22
-5
lines changed
1 file changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ Is LIMIT 1 needed?
24
24
25
25
## Delete
26
26
27
- ### Delete Lines Contained in Polygons
27
+ ### Delete Geometries Contained in Polygons
28
28
< https://gis.stackexchange.com/questions/372549/delete-lines-within-polygon >
29
29
30
30
Use an ` EXISTS ` expression.
@@ -33,11 +33,28 @@ This is an efficient way when traversing a table by row (as in an `UPDATE`/`DELE
33
33
or otherwise comparing against a pre-selection (e.g. of ids).
34
34
35
35
``` sql
36
- DELETE FROM < lines> AS ln
37
- WHERE EXISTS (
36
+ DELETE FROM < geom_tbl> AS g
37
+ WHERE EXISTS (
38
+ SELECT 1
39
+ FROM < poly_tbl> AS p
40
+ WHERE ST_Within(g .geom , p .geom )
41
+ );
42
+ ```
43
+
44
+ ### Delete Geometries NOT Contained in Polygons
45
+ < https://gis.stackexchange.com/questions/471587/delete-points-in-in-a-certain-area-using-postgis >
46
+
47
+ Use an ` NOT EXISTS ` expression.
48
+ ` NOT EXISTS ` terminates the subquery as soon as a single row satisfying the ` ST_Within ` condition is found.
49
+ This is an efficient way when traversing a table by row (as in an ` UPDATE ` /` DELETE ` ),
50
+ or otherwise comparing against a pre-selection (e.g. of ids).
51
+
52
+ ``` sql
53
+ DELETE FROM < geom_tbl> AS g
54
+ WHERE NOT EXISTS (
38
55
SELECT 1
39
- FROM < poly > AS pl
40
- WHERE ST_Within(ln .geom , pl .geom )
56
+ FROM < poly_tbl > AS p
57
+ WHERE ST_Within(g .geom , p .geom )
41
58
);
42
59
```
43
60
You can’t perform that action at this time.
0 commit comments