PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_raster_geos_contains()

static void test_raster_geos_contains ( )
static

Definition at line 1029 of file cu_spatial_relationship.c.

References cu_add_band(), cu_free_raster(), ES_NONE, PT_8BUI, rt_band_get_nodata(), rt_band_set_nodata(), rt_band_set_pixel(), rt_raster_contains(), rt_raster_new(), rt_raster_set_offsets(), rt_raster_set_scale(), and rt_raster_set_skews().

Referenced by spatial_relationship_suite_setup().

1029  {
1030  rt_raster rast1;
1031  rt_raster rast2;
1032  rt_band band1;
1033  rt_band band2;
1034  double nodata;
1035  int rtn;
1036  int result;
1037 
1038  /*
1039  rast1
1040 
1041  (-1, -1)
1042  +-+-+
1043  |1|1|
1044  +-+-+
1045  |1|1|
1046  +-+-+
1047  (1, 1)
1048  */
1049  rast1 = rt_raster_new(2, 2);
1050  CU_ASSERT(rast1 != NULL);
1051  rt_raster_set_scale(rast1, 1, 1);
1052  rt_raster_set_offsets(rast1, -1, -1);
1053 
1054  band1 = cu_add_band(rast1, PT_8BUI, 1, 0);
1055  CU_ASSERT(band1 != NULL);
1056  rt_band_set_nodata(band1, 0, NULL);
1057  rtn = rt_band_set_pixel(band1, 0, 0, 1, NULL);
1058  rtn = rt_band_set_pixel(band1, 0, 1, 1, NULL);
1059  rtn = rt_band_set_pixel(band1, 1, 0, 1, NULL);
1060  rtn = rt_band_set_pixel(band1, 1, 1, 1, NULL);
1061 
1062  rt_band_get_nodata(band1, &nodata);
1063  CU_ASSERT_EQUAL(nodata, 0);
1064 
1065  rtn = rt_raster_contains(
1066  rast1, 0,
1067  rast1, 0,
1068  &result
1069  );
1070  CU_ASSERT_EQUAL(rtn, ES_NONE);
1071  CU_ASSERT_EQUAL(result, 1);
1072 
1073  /*
1074  rast2
1075 
1076  (0, 0)
1077  +-+-+
1078  |1|1|
1079  +-+-+
1080  |1|1|
1081  +-+-+
1082  (2, 2)
1083  */
1084  rast2 = rt_raster_new(2, 2);
1085  CU_ASSERT(rast2 != NULL);
1086  rt_raster_set_scale(rast2, 1, 1);
1087 
1088  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
1089  CU_ASSERT(band2 != NULL);
1090  rt_band_set_nodata(band2, 0, NULL);
1091  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1092  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1093  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1094  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1095 
1096  rt_band_get_nodata(band2, &nodata);
1097  CU_ASSERT_EQUAL(nodata, 0);
1098 
1099  rtn = rt_raster_contains(
1100  rast1, 0,
1101  rast2, 0,
1102  &result
1103  );
1104  CU_ASSERT_EQUAL(rtn, ES_NONE);
1105  CU_ASSERT_NOT_EQUAL(result, 1);
1106 
1107  rtn = rt_raster_contains(
1108  rast1, -1,
1109  rast2, -1,
1110  &result
1111  );
1112  CU_ASSERT_EQUAL(rtn, ES_NONE);
1113  CU_ASSERT_NOT_EQUAL(result, 1);
1114 
1115  /*
1116  rast2
1117 
1118  (0, 0)
1119  +-+-+
1120  |0|1|
1121  +-+-+
1122  |1|1|
1123  +-+-+
1124  (2, 2)
1125  */
1126  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1127 
1128  rtn = rt_raster_contains(
1129  rast1, 0,
1130  rast2, 0,
1131  &result
1132  );
1133  CU_ASSERT_EQUAL(rtn, ES_NONE);
1134  CU_ASSERT_NOT_EQUAL(result, 1);
1135 
1136  /*
1137  rast2
1138 
1139  (0, 0)
1140  +-+-+
1141  |1|0|
1142  +-+-+
1143  |1|1|
1144  +-+-+
1145  (2, 2)
1146  */
1147  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1148  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
1149 
1150  rtn = rt_raster_contains(
1151  rast1, 0,
1152  rast2, 0,
1153  &result
1154  );
1155  CU_ASSERT_EQUAL(rtn, ES_NONE);
1156  CU_ASSERT_NOT_EQUAL(result, 1);
1157 
1158  /*
1159  rast2
1160 
1161  (0, 0)
1162  +-+-+
1163  |0|0|
1164  +-+-+
1165  |0|1|
1166  +-+-+
1167  (2, 2)
1168  */
1169  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1170  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
1171  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
1172 
1173  rtn = rt_raster_contains(
1174  rast1, 0,
1175  rast2, 0,
1176  &result
1177  );
1178  CU_ASSERT_EQUAL(rtn, ES_NONE);
1179  CU_ASSERT_NOT_EQUAL(result, 1);
1180 
1181  /*
1182  rast2
1183 
1184  (0, 0)
1185  +-+-+
1186  |0|0|
1187  +-+-+
1188  |0|0|
1189  +-+-+
1190  (2, 2)
1191  */
1192  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1193  rtn = rt_band_set_pixel(band2, 1, 0, 0, NULL);
1194  rtn = rt_band_set_pixel(band2, 0, 1, 0, NULL);
1195  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
1196 
1197  rtn = rt_raster_contains(
1198  rast1, 0,
1199  rast2, 0,
1200  &result
1201  );
1202  CU_ASSERT_EQUAL(rtn, ES_NONE);
1203  CU_ASSERT_NOT_EQUAL(result, 1);
1204 
1205  /*
1206  rast2
1207 
1208  (2, 0)
1209  +-+-+
1210  |1|1|
1211  +-+-+
1212  |1|1|
1213  +-+-+
1214  (4, 2)
1215  */
1216  rt_raster_set_offsets(rast2, 2, 0);
1217 
1218  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1219  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1220  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1221  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1222 
1223  rtn = rt_raster_contains(
1224  rast1, 0,
1225  rast2, 0,
1226  &result
1227  );
1228  CU_ASSERT_EQUAL(rtn, ES_NONE);
1229  CU_ASSERT_NOT_EQUAL(result, 1);
1230 
1231  /*
1232  rast2
1233 
1234  (0, 1)
1235  +-+-+
1236  |1|1|
1237  +-+-+
1238  |1|1|
1239  +-+-+
1240  (2, 3)
1241  */
1242  rt_raster_set_offsets(rast2, 0, 1);
1243 
1244  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1245  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1246  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1247  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1248 
1249  rtn = rt_raster_contains(
1250  rast1, 0,
1251  rast2, 0,
1252  &result
1253  );
1254  CU_ASSERT_EQUAL(rtn, ES_NONE);
1255  CU_ASSERT_NOT_EQUAL(result, 1);
1256 
1257  /*
1258  rast2
1259 
1260  (-1, 1)
1261  +-+-+
1262  |1|1|
1263  +-+-+
1264  |1|1|
1265  +-+-+
1266  (1, 3)
1267  */
1268  rt_raster_set_offsets(rast2, -1, 1);
1269 
1270  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1271  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1272  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1273  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1274 
1275  rtn = rt_raster_contains(
1276  rast1, 0,
1277  rast2, 0,
1278  &result
1279  );
1280  CU_ASSERT_EQUAL(rtn, ES_NONE);
1281  CU_ASSERT_NOT_EQUAL(result, 1);
1282 
1283  /*
1284  rast2
1285 
1286  (0.1, 0.1)
1287  +-+-+
1288  |1|1|
1289  +-+-+
1290  |1|1|
1291  +-+-+
1292  (0.9, 0.9)
1293  */
1294  rt_raster_set_offsets(rast2, 0.1, 0.1);
1295  rt_raster_set_scale(rast2, 0.4, 0.4);
1296 
1297  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1298  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1299  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1300  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1301 
1302  rtn = rt_raster_contains(
1303  rast1, 0,
1304  rast2, 0,
1305  &result
1306  );
1307  CU_ASSERT_EQUAL(rtn, ES_NONE);
1308  CU_ASSERT_EQUAL(result, 1);
1309 
1310  /*
1311  rast2
1312 
1313  (-0.1, 0.1)
1314  +-+-+
1315  |1|1|
1316  +-+-+
1317  |1|1|
1318  +-+-+
1319  (0.9, 0.9)
1320  */
1321  rt_raster_set_offsets(rast2, -0.1, 0.1);
1322 
1323  rtn = rt_raster_contains(
1324  rast1, 0,
1325  rast2, 0,
1326  &result
1327  );
1328  CU_ASSERT_EQUAL(rtn, ES_NONE);
1329  CU_ASSERT_EQUAL(result, 1);
1330 
1331  cu_free_raster(rast2);
1332 
1333  /*
1334  rast2
1335 
1336  (0, 0)
1337  +-+-+-+
1338  |1|1|1|
1339  +-+-+-+
1340  |1|1|1|
1341  +-+-+-+
1342  |1|1|1|
1343  +-+-+-+
1344  (3, 3)
1345  */
1346  rast2 = rt_raster_new(3, 3);
1347  CU_ASSERT(rast2 != NULL);
1348  rt_raster_set_scale(rast2, 1, 1);
1349 
1350  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
1351  CU_ASSERT(band2 != NULL);
1352  rt_band_set_nodata(band2, 0, NULL);
1353  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1354  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1355  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
1356  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1357  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1358  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
1359  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
1360  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
1361  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
1362 
1363  rt_band_get_nodata(band2, &nodata);
1364  CU_ASSERT_EQUAL(nodata, 0);
1365 
1366  rtn = rt_raster_contains(
1367  rast1, 0,
1368  rast2, 0,
1369  &result
1370  );
1371  CU_ASSERT_EQUAL(rtn, ES_NONE);
1372  CU_ASSERT_NOT_EQUAL(result, 1);
1373 
1374  /*
1375  rast2
1376 
1377  (-2, -2)
1378  +-+-+-+
1379  |1|1|1|
1380  +-+-+-+
1381  |1|1|1|
1382  +-+-+-+
1383  |1|1|1|
1384  +-+-+-+
1385  (1, 1)
1386  */
1387  rt_raster_set_offsets(rast2, -2, -2);
1388 
1389  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1390  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1391  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
1392  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1393  rtn = rt_band_set_pixel(band2, 1, 1, 1, NULL);
1394  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
1395  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
1396  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
1397  rtn = rt_band_set_pixel(band2, 2, 2, 1, NULL);
1398 
1399  rtn = rt_raster_contains(
1400  rast1, 0,
1401  rast2, 0,
1402  &result
1403  );
1404  CU_ASSERT_EQUAL(rtn, ES_NONE);
1405  CU_ASSERT_NOT_EQUAL(result, 1);
1406 
1407  /*
1408  rast2
1409 
1410  (-2, -2)
1411  +-+-+-+
1412  |0|1|1|
1413  +-+-+-+
1414  |1|0|1|
1415  +-+-+-+
1416  |1|1|0|
1417  +-+-+-+
1418  (1, 1)
1419  */
1420  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1421  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1422  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
1423  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1424  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
1425  rtn = rt_band_set_pixel(band2, 1, 2, 1, NULL);
1426  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
1427  rtn = rt_band_set_pixel(band2, 2, 1, 1, NULL);
1428  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
1429 
1430  rtn = rt_raster_contains(
1431  rast1, 0,
1432  rast2, 0,
1433  &result
1434  );
1435  CU_ASSERT_EQUAL(rtn, ES_NONE);
1436  CU_ASSERT_NOT_EQUAL(result, 1);
1437 
1438  /*
1439  rast2
1440 
1441  (-2, -2)
1442  +-+-+-+
1443  |0|1|1|
1444  +-+-+-+
1445  |1|0|0|
1446  +-+-+-+
1447  |1|0|0|
1448  +-+-+-+
1449  (1, 1)
1450  */
1451  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1452  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1453  rtn = rt_band_set_pixel(band2, 0, 2, 1, NULL);
1454  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1455  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
1456  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
1457  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
1458  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
1459  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
1460 
1461  rtn = rt_raster_contains(
1462  rast1, 0,
1463  rast2, 0,
1464  &result
1465  );
1466  CU_ASSERT_EQUAL(rtn, ES_NONE);
1467  CU_ASSERT_NOT_EQUAL(result, 1);
1468 
1469  /*
1470  rast2
1471 
1472  (-2, -2)
1473  +-+-+-+
1474  |0|1|0|
1475  +-+-+-+
1476  |1|0|0|
1477  +-+-+-+
1478  |0|0|0|
1479  +-+-+-+
1480  (1, 1)
1481  */
1482  rtn = rt_band_set_pixel(band2, 0, 0, 0, NULL);
1483  rtn = rt_band_set_pixel(band2, 0, 1, 1, NULL);
1484  rtn = rt_band_set_pixel(band2, 0, 2, 0, NULL);
1485  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1486  rtn = rt_band_set_pixel(band2, 1, 1, 0, NULL);
1487  rtn = rt_band_set_pixel(band2, 1, 2, 0, NULL);
1488  rtn = rt_band_set_pixel(band2, 2, 0, 0, NULL);
1489  rtn = rt_band_set_pixel(band2, 2, 1, 0, NULL);
1490  rtn = rt_band_set_pixel(band2, 2, 2, 0, NULL);
1491 
1492  rtn = rt_raster_contains(
1493  rast1, 0,
1494  rast2, 0,
1495  &result
1496  );
1497  CU_ASSERT_EQUAL(rtn, ES_NONE);
1498  CU_ASSERT_NOT_EQUAL(result, 1);
1499 
1500  cu_free_raster(rast2);
1501 
1502  /* skew tests */
1503  /* rast2 (skewed by -0.5, 0.5) */
1504  rast2 = rt_raster_new(3, 3);
1505  CU_ASSERT(rast2 != NULL);
1506  rt_raster_set_scale(rast2, 1, 1);
1507  rt_raster_set_skews(rast2, -0.5, 0.5);
1508 
1509  band2 = cu_add_band(rast2, PT_8BUI, 1, 0);
1510  CU_ASSERT(band2 != NULL);
1511  rt_band_set_nodata(band2, 0, NULL);
1512  rtn = rt_band_set_pixel(band2, 0, 0, 1, NULL);
1513  rtn = rt_band_set_pixel(band2, 0, 1, 2, NULL);
1514  rtn = rt_band_set_pixel(band2, 0, 2, 3, NULL);
1515  rtn = rt_band_set_pixel(band2, 1, 0, 1, NULL);
1516  rtn = rt_band_set_pixel(band2, 1, 1, 2, NULL);
1517  rtn = rt_band_set_pixel(band2, 1, 2, 3, NULL);
1518  rtn = rt_band_set_pixel(band2, 2, 0, 1, NULL);
1519  rtn = rt_band_set_pixel(band2, 2, 1, 2, NULL);
1520  rtn = rt_band_set_pixel(band2, 2, 2, 3, NULL);
1521 
1522  rtn = rt_raster_contains(
1523  rast1, 0,
1524  rast2, 0,
1525  &result
1526  );
1527  CU_ASSERT_EQUAL(rtn, ES_NONE);
1528  CU_ASSERT_NOT_EQUAL(result, 1);
1529 
1530  /* rast2 (skewed by -1, 1) */
1531  rt_raster_set_skews(rast2, -1, 1);
1532 
1533  rtn = rt_raster_contains(
1534  rast1, 0,
1535  rast2, 0,
1536  &result
1537  );
1538  CU_ASSERT_EQUAL(rtn, ES_NONE);
1539  CU_ASSERT_NOT_EQUAL(result, 1);
1540 
1541  /* rast2 (skewed by 1, -1) */
1542  rt_raster_set_skews(rast2, 1, -1);
1543 
1544  rtn = rt_raster_contains(
1545  rast1, 0,
1546  rast2, 0,
1547  &result
1548  );
1549  CU_ASSERT_EQUAL(rtn, ES_NONE);
1550  CU_ASSERT_NOT_EQUAL(result, 1);
1551 
1552  cu_free_raster(rast2);
1553  cu_free_raster(rast1);
1554 }
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
Definition: rt_raster.c:168
rt_errorstate rt_raster_contains(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *contains)
Return ES_ERROR if error occurred in function.
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_band.c:600
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1597
void cu_free_raster(rt_raster raster)
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition: rt_band.c:841
Here is the call graph for this function:
Here is the caller graph for this function: