26 | | '''ST_Intersects(raster, raster)'''[[BR]] |
27 | | |
28 | | This function uses the same tests as the two geometry version of ST_Intersects where tests see if two rasters overlap, touches or has one within the other. If any condition is true, the two rasters intersect. |
29 | | |
30 | | For this description, the rasters are called A and B and the bands tested are assumed to be 1. |
31 | | |
32 | | Preliminary criteria before the real work begins: |
33 | | |
34 | | 1. make sure that rasters A and B have the same SRID. if not, return false. |
35 | | |
36 | | 2. make sure that the convex hulls of A and B intersect. if not, return false. |
37 | | |
38 | | Special case where a raster may be fully contained within another raster's cell (the entirety of A within a cell of B): |
39 | | |
40 | | 1. using every third pixel by row and column, test each selected cell's geopoint (excluding no data by default unless exclude_nodata_value = FALSE) of A to that of B for overlap. |
41 | | |
42 | | 2. if a cell of A does overlap a cell of B, return true. |
43 | | |
44 | | 3. if no cell of A overlaps with B, continue to additional testing |
45 | | |
46 | | Actual testing involves the use of calculating the intersection of grid lines between A and B |
47 | | |
48 | | 1. Using every third A's column and B's row, calculate the intersection point of each pair of grid lines. |
49 | | |
50 | | 2. If intersection point doesn't exist or is outside the bounds of the end points comprising each grid line used, go back to step 1. |
51 | | |
52 | | 3. If intersection point exists and within bounds, sample the area around the intersection point by offset the intersection point by a small amount (1/10th of the smaller scale of A and B) for 360 degrees starting from 00:00. sampled points are 0, 45, 90, 135, 180, 225, 270 and 315 degrees. |
53 | | |
54 | | 4. At each sample point, test to see if the geopoint has non-nodata (unless including nodata) values in both A and B. if so, return true. |
55 | | |
56 | | 5. At the same time as step 4, build an adjacency matrix for the intersection to see if two non-overlapping pixels from A and B touch. |
57 | | |
58 | | 6. Once all sample points have been tested and no overlapping pixels found, the adjacency matrix is checked to see if any sampled pixel of A touched a sampled pixel of B. If two pixels touched, return true. |
59 | | |
60 | | 7. If after all the searching and testing, nothing intersects or touches, return false. |
61 | | |
62 | | A set of ST_Intersects functions for rasters: |
63 | | |
64 | | 1. ST_Intersects(raster rastA, raster rastB, integer bandA DEFAULT NULL, integer bandB DEFAULT NULL) -> boolean |
65 | | |
66 | | If bandA and bandB are NULL, only the convex hulls of the rasters will be tested. If bandA or bandB are provided, both parameters must be provided and not NULL. |
67 | | |
68 | | 2. ST_Intersects(raster rastA, integer bandA, raster rastB, integer bandB) -> boolean |
69 | | |
70 | | A refactored set of St_Intersects() for testing a raster and a geometry. The first set converts the geometry to a raster to see if the two rasters intersect. |
71 | | |
72 | | 3. ST_Intersects(rast raster, geom geometry, nband integer DEFAULT NULL) -> boolean |
73 | | |
74 | | 4. ST_Intersects(rast raster, nband integer, geom geometry) -> boolean |
75 | | |
76 | | The second set of ST_Intersects() for testing a raster and a geometry converts the raster to a geometry and sees if the geometries intersect. |
77 | | |
78 | | 5. ST_Intersects(geom geometry, rast raster, nband DEFAULT NULL) -> boolean |
79 | | |
80 | | The order in which the geometry and raster are passed into ST_Intersects determines which method of testing is used. If geometry is first, the raster is converted to a set of geometries. If raster is first, the geometry is converted to a raster. |
81 | | |
82 | | These set of functions are required because there are cases where ST_Intersects(raster, geometry) != ST_Intersects(geometry, raster). |
83 | | |
84 | | [[Image(st_intersects_triangle.png)]] |
85 | | |
86 | | In the image above, the black border denotes the boundary of a triangle polygon and the red within is the raster version of the geometry. The polygon touches the raster in blue while the red raster does not. |
| 26 | '''ST_Intersects(raster, raster) -> boolean - done see below'''[[BR]] |
| 1186 | '''ST_Intersects(raster, raster) -> boolean'''[[BR]] |
| 1187 | |
| 1188 | This function uses the same tests as the two geometry version of ST_Intersects where tests see if two rasters overlap, touches or has one within the other. If any condition is true, the two rasters intersect. |
| 1189 | |
| 1190 | For this description, the rasters are called A and B and the bands tested are assumed to be 1. |
| 1191 | |
| 1192 | Preliminary criteria before the real work begins: |
| 1193 | |
| 1194 | 1. make sure that rasters A and B have the same SRID. if not, return false. |
| 1195 | |
| 1196 | 2. make sure that the convex hulls of A and B intersect. if not, return false. |
| 1197 | |
| 1198 | Special case where a raster may be fully contained within another raster's cell (the entirety of A within a cell of B): |
| 1199 | |
| 1200 | 1. using every third pixel by row and column, test each selected cell's geopoint (excluding no data by default unless exclude_nodata_value = FALSE) of A to that of B for overlap. |
| 1201 | |
| 1202 | 2. if a cell of A does overlap a cell of B, return true. |
| 1203 | |
| 1204 | 3. if no cell of A overlaps with B, continue to additional testing |
| 1205 | |
| 1206 | Actual testing involves the use of calculating the intersection of grid lines between A and B |
| 1207 | |
| 1208 | 1. Using every third A's column and B's row, calculate the intersection point of each pair of grid lines. |
| 1209 | |
| 1210 | 2. If intersection point doesn't exist or is outside the bounds of the end points comprising each grid line used, go back to step 1. |
| 1211 | |
| 1212 | 3. If intersection point exists and within bounds, sample the area around the intersection point by offset the intersection point by a small amount (1/10th of the smaller scale of A and B) for 360 degrees starting from 00:00. sampled points are 0, 45, 90, 135, 180, 225, 270 and 315 degrees. |
| 1213 | |
| 1214 | 4. At each sample point, test to see if the geopoint has non-nodata (unless including nodata) values in both A and B. if so, return true. |
| 1215 | |
| 1216 | 5. At the same time as step 4, build an adjacency matrix for the intersection to see if two non-overlapping pixels from A and B touch. |
| 1217 | |
| 1218 | 6. Once all sample points have been tested and no overlapping pixels found, the adjacency matrix is checked to see if any sampled pixel of A touched a sampled pixel of B. If two pixels touched, return true. |
| 1219 | |
| 1220 | 7. If after all the searching and testing, nothing intersects or touches, return false. |
| 1221 | |
| 1222 | A set of ST_Intersects functions for rasters: |
| 1223 | |
| 1224 | 1. ST_Intersects(raster rastA, raster rastB, integer bandA DEFAULT NULL, integer bandB DEFAULT NULL) -> boolean |
| 1225 | |
| 1226 | If bandA and bandB are NULL, only the convex hulls of the rasters will be tested. If bandA or bandB are provided, both parameters must be provided and not NULL. |
| 1227 | |
| 1228 | 2. ST_Intersects(raster rastA, integer bandA, raster rastB, integer bandB) -> boolean |
| 1229 | |
| 1230 | A refactored set of St_Intersects() for testing a raster and a geometry. The first set converts the geometry to a raster to see if the two rasters intersect. |
| 1231 | |
| 1232 | 3. ST_Intersects(rast raster, geom geometry, nband integer DEFAULT NULL) -> boolean |
| 1233 | |
| 1234 | 4. ST_Intersects(rast raster, nband integer, geom geometry) -> boolean |
| 1235 | |
| 1236 | The second set of ST_Intersects() for testing a raster and a geometry converts the raster to a geometry and sees if the geometries intersect. |
| 1237 | |
| 1238 | 5. ST_Intersects(geom geometry, rast raster, nband DEFAULT NULL) -> boolean |
| 1239 | |
| 1240 | The order in which the geometry and raster are passed into ST_Intersects determines which method of testing is used. If geometry is first, the raster is converted to a set of geometries. If raster is first, the geometry is converted to a raster. |
| 1241 | |
| 1242 | These set of functions are required because there are cases where ST_Intersects(raster, geometry) != ST_Intersects(geometry, raster). |
| 1243 | |
| 1244 | [[Image(st_intersects_triangle.png)]] |
| 1245 | |
| 1246 | In the image above, the black border denotes the boundary of a triangle polygon and the red within is the raster version of the geometry. The polygon touches the raster in blue while the red raster does not. |
| 1247 | |