From: Bborie Park Date: Mon, 23 Jul 2012 22:57:05 +0000 (+0000) Subject: Added rt_raster_covered_by() and related tests X-Git-Tag: 2.1.0beta2~758 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=990cfb1c9d71d2c216db66e64db13295281df0df;p=postgis Added rt_raster_covered_by() and related tests git-svn-id: http://svn.osgeo.org/postgis/trunk@10106 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index fdc03ef27..ce5b22cc2 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -11565,6 +11565,9 @@ int rt_raster_geos_spatial_relationship( case GSR_COVERS: rtn = GEOSRelatePattern(geom1, geom2, "******FF*"); break; + case GSR_COVEREDBY: + rtn = GEOSRelatePattern(geom1, geom2, "**F**F***"); + break; default: rterror("rt_raster_geos_spatial_relationship: Unknown or unsupported GEOS spatial relationship test"); flag = -1; @@ -11665,7 +11668,7 @@ int rt_raster_touches( * @param nband2 : the 0-based band of raster rast2 to use * if value is less than zero, bands are ignored * if nband2 gte zero, nband1 must be gte zero - * @param touches : non-zero value if rast1 contains rast2 + * @param contains : non-zero value if rast1 contains rast2 * * @return if zero, an error occurred in function */ @@ -11696,7 +11699,7 @@ int rt_raster_contains( * @param nband2 : the 0-based band of raster rast2 to use * if value is less than zero, bands are ignored * if nband2 gte zero, nband1 must be gte zero - * @param touches : non-zero value if rast1 contains properly rast2 + * @param contains : non-zero value if rast1 contains properly rast2 * * @return if zero, an error occurred in function */ @@ -11727,7 +11730,7 @@ int rt_raster_contains_properly( * @param nband2 : the 0-based band of raster rast2 to use * if value is less than zero, bands are ignored * if nband2 gte zero, nband1 must be gte zero - * @param touches : non-zero value if rast1 covers rast2 + * @param covers : non-zero value if rast1 covers rast2 * * @return if zero, an error occurred in function */ @@ -11746,6 +11749,37 @@ int rt_raster_covers( ); } +/** + * Return zero if error occurred in function. + * Parameter contains returns non-zero if rast1 is covered by rast2 + * + * @param rast1 : the first raster whose band will be tested + * @param nband1 : the 0-based band of raster rast1 to use + * if value is less than zero, bands are ignored. + * if nband1 gte zero, nband2 must be gte zero + * @param rast2 : the second raster whose band will be tested + * @param nband2 : the 0-based band of raster rast2 to use + * if value is less than zero, bands are ignored + * if nband2 gte zero, nband1 must be gte zero + * @param coveredby : non-zero value if rast1 is covered by rast2 + * + * @return if zero, an error occurred in function + */ +int rt_raster_coveredby( + rt_raster rast1, int nband1, + rt_raster rast2, int nband2, + int *coveredby +) { + RASTER_DEBUG(3, "Starting"); + + return rt_raster_geos_spatial_relationship( + rast1, nband1, + rast2, nband2, + GSR_COVEREDBY, + coveredby + ); +} + /* * Return zero if error occurred in function. * Paramter aligned returns non-zero if two rasters are aligned diff --git a/raster/rt_core/rt_api.h b/raster/rt_core/rt_api.h index e84c40913..7ac3f76fe 100644 --- a/raster/rt_core/rt_api.h +++ b/raster/rt_core/rt_api.h @@ -187,7 +187,8 @@ typedef enum { GSR_TOUCHES, GSR_CONTAINS, GSR_CONTAINSPROPERLY, - GSR_COVERS + GSR_COVERS, + GSR_COVEREDBY } rt_geos_spatial_test; /** @@ -1495,7 +1496,7 @@ int rt_raster_overlaps( * @param nband2 : the 0-based band of raster rast2 to use * if value is less than zero, bands are ignored * if nband2 gte zero, nband1 must be gte zero - * @param touches : non-zero value if rast1 contains rast2 + * @param contains : non-zero value if rast1 contains rast2 * * @return if zero, an error occurred in function */ @@ -1517,7 +1518,7 @@ int rt_raster_contains( * @param nband2 : the 0-based band of raster rast2 to use * if value is less than zero, bands are ignored * if nband2 gte zero, nband1 must be gte zero - * @param touches : non-zero value if rast1 contains properly rast2 + * @param contains : non-zero value if rast1 contains properly rast2 * * @return if zero, an error occurred in function */ @@ -1561,7 +1562,7 @@ int rt_raster_touches( * @param nband2 : the 0-based band of raster rast2 to use * if value is less than zero, bands are ignored * if nband2 gte zero, nband1 must be gte zero - * @param touches : non-zero value if rast1 covers rast2 + * @param covers : non-zero value if rast1 covers rast2 * * @return if zero, an error occurred in function */ @@ -1571,6 +1572,28 @@ int rt_raster_covers( int *covers ); +/** + * Return zero if error occurred in function. + * Parameter contains returns non-zero if rast1 is covered by rast2 + * + * @param rast1 : the first raster whose band will be tested + * @param nband1 : the 0-based band of raster rast1 to use + * if value is less than zero, bands are ignored. + * if nband1 gte zero, nband2 must be gte zero + * @param rast2 : the second raster whose band will be tested + * @param nband2 : the 0-based band of raster rast2 to use + * if value is less than zero, bands are ignored + * if nband2 gte zero, nband1 must be gte zero + * @param coveredby : non-zero value if rast1 is covered by rast2 + * + * @return if zero, an error occurred in function + */ +int rt_raster_coveredby( + rt_raster rast1, int nband1, + rt_raster rast2, int nband2, + int *coveredby +); + /* * Return zero if error occurred in function. * Paramter aligned returns non-zero if two rasters are aligned diff --git a/raster/test/core/testapi.c b/raster/test/core/testapi.c index 6b3eb6a6f..56f85e667 100644 --- a/raster/test/core/testapi.c +++ b/raster/test/core/testapi.c @@ -4938,6 +4938,529 @@ static void testCovers() { deepRelease(rast1); } +static void testCoveredBy() { + rt_raster rast1; + rt_raster rast2; + rt_band band1; + rt_band band2; + double nodata; + int rtn; + int result; + + /* + rast1 + + (-1, -1) + +-+-+ + |1|1| + +-+-+ + |1|1| + +-+-+ + (1, 1) + */ + rast1 = rt_raster_new(2, 2); + assert(rast1); + rt_raster_set_offsets(rast1, -1, -1); + + band1 = addBand(rast1, PT_8BUI, 1, 0); + CHECK(band1); + rt_band_set_nodata(band1, 0); + rtn = rt_band_set_pixel(band1, 0, 0, 1); + rtn = rt_band_set_pixel(band1, 0, 1, 1); + rtn = rt_band_set_pixel(band1, 1, 0, 1); + rtn = rt_band_set_pixel(band1, 1, 1, 1); + + nodata = rt_band_get_nodata(band1); + CHECK_EQUALS(nodata, 0); + + rtn = rt_raster_coveredby( + rast1, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result == 1)); + + /* + rast2 + + (0, 0) + +-+-+ + |1|1| + +-+-+ + |1|1| + +-+-+ + (2, 2) + */ + rast2 = rt_raster_new(2, 2); + assert(rast2); + + band2 = addBand(rast2, PT_8BUI, 1, 0); + CHECK(band2); + rt_band_set_nodata(band2, 0); + rtn = rt_band_set_pixel(band2, 0, 0, 1); + rtn = rt_band_set_pixel(band2, 0, 1, 1); + rtn = rt_band_set_pixel(band2, 1, 0, 1); + rtn = rt_band_set_pixel(band2, 1, 1, 1); + + nodata = rt_band_get_nodata(band2); + CHECK_EQUALS(nodata, 0); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + rtn = rt_raster_coveredby( + rast2, -1, + rast1, -1, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + /* + rast2 + + (0, 0) + +-+-+ + |0|1| + +-+-+ + |1|1| + +-+-+ + (2, 2) + */ + rtn = rt_band_set_pixel(band2, 0, 0, 0); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + /* + rast2 + + (0, 0) + +-+-+ + |1|0| + +-+-+ + |1|1| + +-+-+ + (2, 2) + */ + rtn = rt_band_set_pixel(band2, 0, 0, 1); + rtn = rt_band_set_pixel(band2, 1, 0, 0); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + /* + rast2 + + (0, 0) + +-+-+ + |0|0| + +-+-+ + |0|1| + +-+-+ + (2, 2) + */ + rtn = rt_band_set_pixel(band2, 0, 0, 0); + rtn = rt_band_set_pixel(band2, 1, 0, 0); + rtn = rt_band_set_pixel(band2, 0, 1, 0); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + /* + rast2 + + (0, 0) + +-+-+ + |0|0| + +-+-+ + |0|0| + +-+-+ + (2, 2) + */ + rtn = rt_band_set_pixel(band2, 0, 0, 0); + rtn = rt_band_set_pixel(band2, 1, 0, 0); + rtn = rt_band_set_pixel(band2, 0, 1, 0); + rtn = rt_band_set_pixel(band2, 1, 1, 0); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + /* + rast2 + + (2, 0) + +-+-+ + |1|1| + +-+-+ + |1|1| + +-+-+ + (4, 2) + */ + rt_raster_set_offsets(rast2, 2, 0); + + rtn = rt_band_set_pixel(band2, 0, 0, 1); + rtn = rt_band_set_pixel(band2, 1, 0, 1); + rtn = rt_band_set_pixel(band2, 0, 1, 1); + rtn = rt_band_set_pixel(band2, 1, 1, 1); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + /* + rast2 + + (0, 1) + +-+-+ + |1|1| + +-+-+ + |1|1| + +-+-+ + (2, 3) + */ + rt_raster_set_offsets(rast2, 0, 1); + + rtn = rt_band_set_pixel(band2, 0, 0, 1); + rtn = rt_band_set_pixel(band2, 1, 0, 1); + rtn = rt_band_set_pixel(band2, 0, 1, 1); + rtn = rt_band_set_pixel(band2, 1, 1, 1); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + /* + rast2 + + (-1, 1) + +-+-+ + |1|1| + +-+-+ + |1|1| + +-+-+ + (1, 3) + */ + rt_raster_set_offsets(rast2, -1, 1); + + rtn = rt_band_set_pixel(band2, 0, 0, 1); + rtn = rt_band_set_pixel(band2, 1, 0, 1); + rtn = rt_band_set_pixel(band2, 0, 1, 1); + rtn = rt_band_set_pixel(band2, 1, 1, 1); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + /* + rast2 + + (0.1, 0.1) + +-+-+ + |1|1| + +-+-+ + |1|1| + +-+-+ + (0.9, 0.9) + */ + rt_raster_set_offsets(rast2, 0.1, 0.1); + rt_raster_set_scale(rast2, 0.4, 0.4); + + rtn = rt_band_set_pixel(band2, 0, 0, 1); + rtn = rt_band_set_pixel(band2, 1, 0, 1); + rtn = rt_band_set_pixel(band2, 0, 1, 1); + rtn = rt_band_set_pixel(band2, 1, 1, 1); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result == 1)); + + /* + rast2 + + (-0.1, 0.1) + +-+-+ + |1|1| + +-+-+ + |1|1| + +-+-+ + (0.9, 0.9) + */ + rt_raster_set_offsets(rast2, -0.1, 0.1); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result == 1)); + + deepRelease(rast2); + + /* + rast2 + + (0, 0) + +-+-+-+ + |1|1|1| + +-+-+-+ + |1|1|1| + +-+-+-+ + |1|1|1| + +-+-+-+ + (3, 3) + */ + rast2 = rt_raster_new(3, 3); + assert(rast2); + + band2 = addBand(rast2, PT_8BUI, 1, 0); + CHECK(band2); + rt_band_set_nodata(band2, 0); + rtn = rt_band_set_pixel(band2, 0, 0, 1); + rtn = rt_band_set_pixel(band2, 0, 1, 1); + rtn = rt_band_set_pixel(band2, 0, 2, 1); + rtn = rt_band_set_pixel(band2, 1, 0, 1); + rtn = rt_band_set_pixel(band2, 1, 1, 1); + rtn = rt_band_set_pixel(band2, 1, 2, 1); + rtn = rt_band_set_pixel(band2, 2, 0, 1); + rtn = rt_band_set_pixel(band2, 2, 1, 1); + rtn = rt_band_set_pixel(band2, 2, 2, 1); + + nodata = rt_band_get_nodata(band2); + CHECK_EQUALS(nodata, 0); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + /* + rast2 + + (-2, -2) + +-+-+-+ + |1|1|1| + +-+-+-+ + |1|1|1| + +-+-+-+ + |1|1|1| + +-+-+-+ + (1, 1) + */ + rt_raster_set_offsets(rast2, -2, -2); + + rtn = rt_band_set_pixel(band2, 0, 0, 1); + rtn = rt_band_set_pixel(band2, 0, 1, 1); + rtn = rt_band_set_pixel(band2, 0, 2, 1); + rtn = rt_band_set_pixel(band2, 1, 0, 1); + rtn = rt_band_set_pixel(band2, 1, 1, 1); + rtn = rt_band_set_pixel(band2, 1, 2, 1); + rtn = rt_band_set_pixel(band2, 2, 0, 1); + rtn = rt_band_set_pixel(band2, 2, 1, 1); + rtn = rt_band_set_pixel(band2, 2, 2, 1); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + /* + rast2 + + (-2, -2) + +-+-+-+ + |0|1|1| + +-+-+-+ + |1|0|1| + +-+-+-+ + |1|1|0| + +-+-+-+ + (1, 1) + */ + rtn = rt_band_set_pixel(band2, 0, 0, 0); + rtn = rt_band_set_pixel(band2, 0, 1, 1); + rtn = rt_band_set_pixel(band2, 0, 2, 1); + rtn = rt_band_set_pixel(band2, 1, 0, 1); + rtn = rt_band_set_pixel(band2, 1, 1, 0); + rtn = rt_band_set_pixel(band2, 1, 2, 1); + rtn = rt_band_set_pixel(band2, 2, 0, 1); + rtn = rt_band_set_pixel(band2, 2, 1, 1); + rtn = rt_band_set_pixel(band2, 2, 2, 0); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + /* + rast2 + + (-2, -2) + +-+-+-+ + |0|1|1| + +-+-+-+ + |1|0|0| + +-+-+-+ + |1|0|0| + +-+-+-+ + (1, 1) + */ + rtn = rt_band_set_pixel(band2, 0, 0, 0); + rtn = rt_band_set_pixel(band2, 0, 1, 1); + rtn = rt_band_set_pixel(band2, 0, 2, 1); + rtn = rt_band_set_pixel(band2, 1, 0, 1); + rtn = rt_band_set_pixel(band2, 1, 1, 0); + rtn = rt_band_set_pixel(band2, 1, 2, 0); + rtn = rt_band_set_pixel(band2, 2, 0, 1); + rtn = rt_band_set_pixel(band2, 2, 1, 0); + rtn = rt_band_set_pixel(band2, 2, 2, 0); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + /* + rast2 + + (-2, -2) + +-+-+-+ + |0|1|0| + +-+-+-+ + |1|0|0| + +-+-+-+ + |0|0|0| + +-+-+-+ + (1, 1) + */ + rtn = rt_band_set_pixel(band2, 0, 0, 0); + rtn = rt_band_set_pixel(band2, 0, 1, 1); + rtn = rt_band_set_pixel(band2, 0, 2, 0); + rtn = rt_band_set_pixel(band2, 1, 0, 1); + rtn = rt_band_set_pixel(band2, 1, 1, 0); + rtn = rt_band_set_pixel(band2, 1, 2, 0); + rtn = rt_band_set_pixel(band2, 2, 0, 0); + rtn = rt_band_set_pixel(band2, 2, 1, 0); + rtn = rt_band_set_pixel(band2, 2, 2, 0); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + deepRelease(rast2); + + /* skew tests */ + /* rast2 (skewed by -0.5, 0.5) */ + rast2 = rt_raster_new(3, 3); + assert(rast2); + rt_raster_set_skews(rast2, -0.5, 0.5); + + band2 = addBand(rast2, PT_8BUI, 1, 0); + CHECK(band2); + rt_band_set_nodata(band2, 0); + rtn = rt_band_set_pixel(band2, 0, 0, 1); + rtn = rt_band_set_pixel(band2, 0, 1, 2); + rtn = rt_band_set_pixel(band2, 0, 2, 3); + rtn = rt_band_set_pixel(band2, 1, 0, 1); + rtn = rt_band_set_pixel(band2, 1, 1, 2); + rtn = rt_band_set_pixel(band2, 1, 2, 3); + rtn = rt_band_set_pixel(band2, 2, 0, 1); + rtn = rt_band_set_pixel(band2, 2, 1, 2); + rtn = rt_band_set_pixel(band2, 2, 2, 3); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + /* rast2 (skewed by -1, 1) */ + rt_raster_set_skews(rast2, -1, 1); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + /* rast2 (skewed by 1, -1) */ + rt_raster_set_skews(rast2, 1, -1); + + rtn = rt_raster_coveredby( + rast2, 0, + rast1, 0, + &result + ); + CHECK((rtn != 0)); + CHECK((result != 1)); + + deepRelease(rast2); + deepRelease(rast1); +} + static void testAlignment() { rt_raster rast1; rt_raster rast2; @@ -5898,6 +6421,10 @@ main() testCovers(); printf("OK\n"); + printf("Testing rt_raster_covered_by... "); + testCoveredBy(); + printf("OK\n"); + printf("Testing rt_raster_same_alignment... "); testAlignment(); printf("OK\n");