initGEOS(lwnotice, lwgeom_geos_error);
/* get LWMPOLY of each band */
- surface1 = rt_raster_surface(rast1, nband1, &rtn);
- if (!rtn) {
+ if (rt_raster_surface(rast1, nband1, &surface1) != ES_NONE) {
rterror("rt_raster_geos_spatial_relationship: Unable to get surface of the specified band from the first raster");
return ES_ERROR;
}
- surface2 = rt_raster_surface(rast2, nband2, &rtn);
- if (!rtn) {
+ if (rt_raster_surface(rast2, nband2, &surface2) != ES_NONE) {
rterror("rt_raster_geos_spatial_relationship: Unable to get surface of the specified band from the second raster");
lwmpoly_free(surface1);
return ES_ERROR;
double distance,
int *dwithin
) {
+ LWMPOLY *surface = NULL;
LWGEOM *surface1 = NULL;
LWGEOM *surface2 = NULL;
double mindist = 0;
- int rtn = 0;
RASTER_DEBUG(3, "Starting");
}
/* get LWMPOLY of each band */
- surface1 = lwmpoly_as_lwgeom(rt_raster_surface(rast1, nband1, &rtn));
- if (!rtn) {
+ if (rt_raster_surface(rast1, nband1, &surface) != ES_NONE) {
rterror("rt_raster_distance_within: Unable to get surface of the specified band from the first raster");
return ES_ERROR;
}
- surface2 = lwmpoly_as_lwgeom(rt_raster_surface(rast2, nband2, &rtn));
- if (!rtn) {
+ surface1 = lwmpoly_as_lwgeom(surface);
+
+ if (rt_raster_surface(rast2, nband2, &surface) != ES_NONE) {
rterror("rt_raster_distance_within: Unable to get surface of the specified band from the second raster");
lwgeom_free(surface1);
return ES_ERROR;
}
+ surface2 = lwmpoly_as_lwgeom(surface);
/* either surface is NULL, test is false */
if (surface1 == NULL || surface2 == NULL) {
double distance,
int *dfwithin
) {
+ LWMPOLY *surface = NULL;
LWGEOM *surface1 = NULL;
LWGEOM *surface2 = NULL;
double maxdist = 0;
- int rtn = 0;
RASTER_DEBUG(3, "Starting");
/* same srid */
if (rt_raster_get_srid(rast1) != rt_raster_get_srid(rast2)) {
- rterror("rt_raster_distance_within: The two rasters provided have different SRIDs");
+ rterror("rt_raster_fully_within_distance: The two rasters provided have different SRIDs");
return ES_ERROR;
}
/* distance cannot be less than zero */
if (distance < 0) {
- rterror("rt_raster_distance_within: Distance cannot be less than zero");
+ rterror("rt_raster_fully_within_distance: Distance cannot be less than zero");
return ES_ERROR;
}
/* get LWMPOLY of each band */
- surface1 = lwmpoly_as_lwgeom(rt_raster_surface(rast1, nband1, &rtn));
- if (!rtn) {
- rterror("rt_raster_distance_within: Unable to get surface of the specified band from the first raster");
+ if (rt_raster_surface(rast1, nband1, &surface) != ES_NONE) {
+ rterror("rt_raster_fully_within_distance: Unable to get surface of the specified band from the first raster");
return ES_ERROR;
}
- surface2 = lwmpoly_as_lwgeom(rt_raster_surface(rast2, nband2, &rtn));
- if (!rtn) {
- rterror("rt_raster_distance_within: Unable to get surface of the specified band from the second raster");
+ surface1 = lwmpoly_as_lwgeom(surface);
+
+ if (rt_raster_surface(rast2, nband2, &surface) != ES_NONE) {
+ rterror("rt_raster_fully_within_distance: Unable to get surface of the specified band from the second raster");
lwgeom_free(surface1);
return ES_ERROR;
}
+ surface2 = lwmpoly_as_lwgeom(surface);
/* either surface is NULL, test is false */
if (surface1 == NULL || surface2 == NULL) {
* @param raster : the raster to convert to a multipolygon
* @param nband : the 0-based band of raster rast to use
* if value is less than zero, bands are ignored.
- * @param noerr : if 0, error occurred
+ * @param *surface : raster as a surface (multipolygon).
+ * if all pixels are NODATA, NULL is set
*
- * @return the raster surface or NULL
+ * @return ES_NONE on success, ES_ERROR on error
*/
-LWMPOLY* rt_raster_surface(rt_raster raster, int nband, int *noerr) {
+rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface) {
rt_band band = NULL;
LWGEOM *mpoly = NULL;
LWGEOM *tmp = NULL;
int geomscount = 0;
int i = 0;
- /* initialize to 0, error occurred */
- *noerr = 0;
+ assert(surface != NULL);
- /* raster is empty, return NULL */
- if (rt_raster_is_empty(raster))
- return NULL;
+ /* init *surface to NULL */
+ *surface = NULL;
+
+ /* raster is empty, surface = NULL */
+ if (rt_raster_is_empty(raster)) {
+ return ES_NONE;
+ }
/* if nband < 0, return the convex hull as a multipolygon */
if (nband < 0) {
lwgeom_free(tmp);
lwgeom_free(mpoly);
- *noerr = 1;
- return lwgeom_as_lwmpoly(clone);
+ *surface = lwgeom_as_lwmpoly(clone);
+ return ES_NONE;
}
/* check that nband is valid */
else if (nband >= rt_raster_get_num_bands(raster)) {
rterror("rt_raster_surface: The band index %d is invalid", nband);
- return NULL;
+ return ES_ERROR;
}
/* get band */
band = rt_raster_get_band(raster, nband);
if (band == NULL) {
rterror("rt_raster_surface: Error getting band %d from raster", nband);
- return NULL;
+ return ES_ERROR;
}
/* band does not have a NODATA flag, return convex hull */
lwgeom_free(tmp);
lwgeom_free(mpoly);
- *noerr = 1;
- return lwgeom_as_lwmpoly(clone);
+ *surface = lwgeom_as_lwmpoly(clone);
+ return ES_NONE;
}
/* band is NODATA, return NULL */
else if (rt_band_get_isnodata_flag(band)) {
RASTER_DEBUG(3, "Band is NODATA. Returning NULL");
- *noerr = 1;
- return NULL;
+ return ES_NONE;
}
/* initialize GEOS */
if (gvcount < 1) {
RASTER_DEBUG(3, "All pixels of band are NODATA. Returning NULL");
if (gv != NULL) rtdealloc(gv);
- *noerr = 1;
- return NULL;
+ return ES_NONE;
}
/* more than 1 polygon */
else if (gvcount > 1) {
rterror("rt_raster_surface: Unable to allocate memory for pixel polygons as GEOSGeometry");
for (i = 0; i < gvcount; i++) lwpoly_free(gv[i].geom);
rtdealloc(gv);
- return NULL;
+ return ES_ERROR;
}
for (i = 0; i < gvcount; i++) {
#if POSTGIS_DEBUG_LEVEL > 3
for (i = 0; i < geomscount; i++)
GEOSGeom_destroy(geoms[i]);
rtdealloc(geoms);
- return NULL;
+ return ES_ERROR;
}
/* run the union */
#else
rterror("rt_raster_surface: Unable to union the pixel polygons using GEOSUnionCascaded()");
#endif
- return NULL;
+ return ES_ERROR;
}
/* convert union result from GEOSGeometry to LWGEOM */
}
#endif
- *noerr = 1;
- return lwgeom_as_lwmpoly(mpoly);
+ *surface = lwgeom_as_lwmpoly(mpoly);
+ return ES_NONE;
}
- *noerr = 1;
- return NULL;
+ return ES_NONE;
}
/******************************************************************************
* @param raster : the raster to convert to a multipolygon
* @param nband : the 0-based band of raster rast to use
* if value is less than zero, bands are ignored.
- * @param noerr : if 0, error occurred
+ * @param **surface : raster as a surface (multipolygon).
+ * if all pixels are NODATA, NULL is set
*
- * @return the raster surface or NULL
+ * @return ES_NONE on success, ES_ERROR on error
*/
-LWMPOLY* rt_raster_surface(rt_raster raster, int nband, int *noerr);
+rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface);
/**
* Returns a set of "geomval" value, one for each group of pixel
}
/* get band surface */
- surface = rt_raster_surface(raster, nband - 1, &err);
+ err = rt_raster_surface(raster, nband - 1, &surface);
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
- if (!err) {
+ if (err != ES_NONE) {
elog(ERROR, "RASTER_getPolygon: Could not get raster band's surface");
PG_RETURN_NULL();
}
}
}
- mpoly = rt_raster_surface(rast, 0, &err);
- CHECK(err);
+ err = rt_raster_surface(rast, 0, &mpoly);
+ CHECK(err == ES_NONE);
CHECK((mpoly != NULL));
wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
CHECK(!strcmp(wkt, "MULTIPOLYGON(((0 0,0 -5,5 -5,5 0,0 0)))"));
/* 0,0 NODATA */
rt_band_set_pixel(band, 0, 0, 0, NULL);
- mpoly = rt_raster_surface(rast, 0, &err);
- CHECK(err);
+ err = rt_raster_surface(rast, 0, &mpoly);
+ CHECK(err == ES_NONE);
CHECK((mpoly != NULL));
wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
CHECK(!strcmp(wkt, "MULTIPOLYGON(((1 0,1 -1,0 -1,0 -5,4 -5,5 -5,5 0,1 0)))"));
/* plus 1,1 NODATA */
rt_band_set_pixel(band, 1, 1, 0, NULL);
- mpoly = rt_raster_surface(rast, 0, &err);
- CHECK(err);
+ err = rt_raster_surface(rast, 0, &mpoly);
+ CHECK(err == ES_NONE);
CHECK((mpoly != NULL));
wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
CHECK(!strcmp(wkt, "MULTIPOLYGON(((1 0,1 -1,0 -1,0 -5,4 -5,5 -5,5 0,1 0),(1 -1,1 -2,2 -2,2 -1,1 -1)))"));
/* plus 2,2 NODATA */
rt_band_set_pixel(band, 2, 2, 0, NULL);
- mpoly = rt_raster_surface(rast, 0, &err);
- CHECK(err);
+ err = rt_raster_surface(rast, 0, &mpoly);
+ CHECK(err == ES_NONE);
CHECK((mpoly != NULL));
wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
#if POSTGIS_GEOS_VERSION >= 33
/* plus 3,3 NODATA */
rt_band_set_pixel(band, 3, 3, 0, NULL);
- mpoly = rt_raster_surface(rast, 0, &err);
- CHECK(err);
+ err = rt_raster_surface(rast, 0, &mpoly);
+ CHECK(err == ES_NONE);
CHECK((mpoly != NULL));
wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
#if POSTGIS_GEOS_VERSION >= 33
/* plus 4,4 NODATA */
rt_band_set_pixel(band, 4, 4, 0, NULL);
- mpoly = rt_raster_surface(rast, 0, &err);
- CHECK(err);
+ err = rt_raster_surface(rast, 0, &mpoly);
+ CHECK(err == ES_NONE);
CHECK((mpoly != NULL));
wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
CHECK(!strcmp(wkt, "MULTIPOLYGON(((4 -4,4 -5,0 -5,0 -1,1 -1,1 -2,2 -2,2 -3,3 -3,3 -4,4 -4)),((1 -1,1 0,5 0,5 -4,4 -4,4 -3,3 -3,3 -2,2 -2,2 -1,1 -1)))"));
rt_band_set_pixel(band, 1, 3, 0, NULL);
rt_band_set_pixel(band, 0, 4, 0, NULL);
- mpoly = rt_raster_surface(rast, 0, &err);
- CHECK(err);
+ err = rt_raster_surface(rast, 0, &mpoly);
+ CHECK(err == ES_NONE);
CHECK((mpoly != NULL));
wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
CHECK(!strcmp(wkt, "MULTIPOLYGON(((1 -4,2 -4,2 -3,3 -3,3 -4,4 -4,4 -5,3 -5,1 -5,1 -4)),((1 -4,0 -4,0 -1,1 -1,1 -2,2 -2,2 -3,1 -3,1 -4)),((3 -2,4 -2,4 -1,5 -1,5 -4,4 -4,4 -3,3 -3,3 -2)),((3 -2,2 -2,2 -1,1 -1,1 0,4 0,4 -1,3 -1,3 -2)))"));