Return ES_ERROR if error occurred in function.
Return ES_ERROR if error occurred in function.
997 GEOSGeometry *ghull[2] = {NULL};
1009 uint16_t *widthS = NULL;
1010 uint16_t *heightS = NULL;
1011 uint16_t *widthL = NULL;
1012 uint16_t *heightL = NULL;
1017 int hasnodataS =
FALSE;
1018 int hasnodataL =
FALSE;
1023 double gtS[6] = {0};
1024 double igtL[6] = {0};
1031 enum line_points {X1, Y1, X2, Y2};
1032 enum point {pX, pY};
1040 assert(NULL != rast1);
1041 assert(NULL != rast2);
1042 assert(NULL != intersects);
1044 if (nband1 < 0 && nband2 < 0) {
1055 rterror(
"rt_raster_intersects: The two rasters provided have different SRIDs");
1071 ghull[0] = (GEOSGeometry *)
LWGEOM2GEOS(hull[0], 0);
1078 GEOSGeom_destroy(ghull[0]);
1082 ghull[1] = (GEOSGeometry *)
LWGEOM2GEOS(hull[1], 0);
1084 GEOSGeom_destroy(ghull[0]);
1092 if (GEOSWithin(ghull[0], ghull[1]) == 1)
1094 else if (GEOSWithin(ghull[1], ghull[0]) == 1)
1100 rtn = GEOSIntersects(ghull[0], ghull[1]);
1102 for (i = 0; i < 2; i++) {
1103 GEOSGeom_destroy(ghull[i]);
1108 RASTER_DEBUGF(4,
"convex hulls of rasters do %sintersect", rtn != 1 ?
"NOT " :
"");
1114 else if (nband1 < 0) {
1132 area1 = fabs(width1 * height1 * pixarea1);
1133 area2 = fabs(width2 * height2 * pixarea2);
1134 RASTER_DEBUGF(4,
"pixarea1, pixarea2, area1, area2 = %f, %f, %f, %f",
1135 pixarea1, pixarea2, area1, area2);
1140 (area1 < pixarea2) ||
1178 if (NULL == bandS) {
1179 rterror(
"rt_raster_intersects: Could not get band %d of the first raster", nbandS);
1185 if (hasnodataS !=
FALSE)
1190 if (NULL == bandL) {
1191 rterror(
"rt_raster_intersects: Could not get band %d of the first raster", nbandL);
1197 if (hasnodataL !=
FALSE)
1211 RASTER_DEBUG(3,
"One of the two raster bands is NODATA. The two rasters do not intersect");
1217 if (
within != 0 && ((pixarea1 > area2) || (pixarea2 > area1))) {
1218 RASTER_DEBUG(4,
"Using special case of raster fitting into another raster's pixel");
1220 for (coloffset = 0; coloffset < 3; coloffset++) {
1221 for (rowoffset = 0; rowoffset < 3; rowoffset++) {
1222 for (col = coloffset; col < *widthS; col += 3) {
1223 for (row = rowoffset; row < *heightS; row += 3) {
1224 if (hasnodataS ==
FALSE)
1229 if ((hasnodataS ==
FALSE) || !isnodataS) {
1233 &(lineS[X1]), &(lineS[Y1]),
1239 lineS[X1], lineS[Y1],
1240 &(Qr[pX]), &(Qr[pY]),
1246 if ((Qr[pX] < 0 || Qr[pX] >= *widthL) ||
1247 (Qr[pY] < 0 || Qr[pY] >= *heightL))
1252 if (hasnodataS ==
FALSE)
1257 if ((hasnodataL ==
FALSE) || !isnodataL) {
1267 RASTER_DEBUG(4,
"Smaller raster not in the other raster's pixel. Continuing");
1270 RASTER_DEBUG(4,
"Testing smaller raster vs larger raster");
1274 hasnodataS, hasnodataL,
1278 if (*intersects)
return ES_NONE;
1280 RASTER_DEBUG(4,
"Testing larger raster vs smaller raster");
1284 hasnodataL, hasnodataS,
1288 if (*intersects)
return ES_NONE;
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
void lwgeom_geos_error(const char *fmt,...)
void lwgeom_free(LWGEOM *geom)
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
#define RASTER_DEBUG(level, msg)
rt_errorstate rt_raster_cell_to_geopoint(rt_raster raster, double xr, double yr, double *xw, double *yw, double *gt)
Convert an xr, yr raster point to an xw, yw point on map.
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
#define RASTER_DEBUGF(level, msg,...)
void rtinfo(const char *fmt,...)
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
rt_errorstate rt_raster_geopoint_to_cell(rt_raster raster, double xw, double yw, double *xr, double *yr, double *igt)
Convert an xw, yw map point to a xr, yr raster point.
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
uint16_t rt_raster_get_num_bands(rt_raster raster)
rt_errorstate rt_raster_get_convex_hull(rt_raster raster, LWGEOM **hull)
Get raster's convex hull.
uint16_t rt_raster_get_height(rt_raster raster)
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
uint16_t rt_raster_get_width(rt_raster raster)
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Datum within(PG_FUNCTION_ARGS)
static int rt_raster_intersects_algorithm(rt_raster rast1, rt_raster rast2, rt_band band1, rt_band band2, int hasnodata1, int hasnodata2, double nodata1, double nodata2)