306 | | '''ST_Intersects(raster|geometry, raster|geometry)''' |
| 306 | '''ST_Intersects(raster, geometry) -> boolean''' - Returns TRUE if the geometry and the raster "spatially intersect" - (share any portion of space) and FALSE if they don't (they are Disjoint). |
| 307 | |
| 308 | Variant 1: ST_Intersects(geometry, raster) -> boolean |
| 309 | |
| 310 | Variant 2: ST_Intersects(raster, raster) -> boolean |
| 311 | |
| 312 | This function permform a full intersection test and proceed in three steps to determine if the raster intersects with the geometry: |
| 313 | |
| 314 | 1) It first checks if the bounding box of the raster intersects with the bounding box of the geometry using the && operator. This test if very quick. |
| 315 | |
| 316 | 2) If the first test returns TRUE, it checks if the geometry returned by ST_ConvexHull(raster, 'WITHNODATA') intersects with the geometry. This test is slower since it might involve the geometry shape. |
| 317 | |
| 318 | 3) If the second test returns TRUE, it checks if the geometry returned by ST_Shape(raster) intersects with the geometry. This test is slower since it involve the computation of the raster shape and it might involve the geometry shape. |
| 319 | |
| 320 | Variant 2 proceeds in a very similar way except that convex hulls of both rasters are computed and compared in step 2) and both shape of raster are computed and compared in step 3). |
| 321 | |
| 322 | If you want to limit the intersection test to the first condition, simply use the && operator: |
| 323 | |
| 324 | raster && geometry |
| 325 | |
| 326 | If you want to limit the intersection test to the second condition you can write: |
| 327 | |
| 328 | ST_Intersects(ST_ConvexHull(raster, 'WITHNODATA'), geometry) |
| 329 | |
| 330 | '''Implementation details''' |
| 331 | |
| 332 | This function should be implemented as a pl/pgSQL function performing the three test described one after and conditionally to the other. |
| 333 | |
| 334 | It might be faster to skip test 2) if this test is not signicantly faster than test 3). |