]> granicus.if.org Git - postgis/commitdiff
Added rt_raster_covered_by() and related tests
authorBborie Park <bkpark at ucdavis.edu>
Mon, 23 Jul 2012 22:57:05 +0000 (22:57 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Mon, 23 Jul 2012 22:57:05 +0000 (22:57 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10106 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/rt_core/rt_api.h
raster/test/core/testapi.c

index fdc03ef2708f757aec2684f419f4db92a3f84478..ce5b22cc26a42d6b99fd22bffdae3fcd5e4a3779 100644 (file)
@@ -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
index e84c40913c310297b7987bf8f285e4766eef0bc9..7ac3f76fe1ae4ba3b825c9e6a71784603b9bd79a 100644 (file)
@@ -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
index 6b3eb6a6fd81050acab514ea9abc72e709f209a4..56f85e667842f0a977c87809e1c7f5aef4a09d4a 100644 (file)
@@ -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");