| 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 a 3x3 search pattern, 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 A's columns and B's rows in a 3x3 search pattern, 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: |
| 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 | The ST_Intersects(raster, geometry) functions may need to be adapted to use ST_Intersects(raster, raster). The difficulty will be for the functions to decide whether or not converting the raster to a geometry or converting the geometry to a raster is faster. |
| 71 | |