24 #include "CUnit/Basic.h" 37 CU_ASSERT(drv != NULL);
39 for (i = 0; i < size; i++) {
40 CU_ASSERT(strlen(drv[i].short_name));
51 char srs[] =
"PROJCS[\"unnamed\",GEOGCS[\"unnamed ellipse\",DATUM[\"unknown\",SPHEROID[\"unnamed\",6370997,0]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Lambert_Azimuthal_Equal_Area\"],PARAMETER[\"latitude_of_center\",45],PARAMETER[\"longitude_of_center\",-100],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"2163\"]]";
52 const char wkb_hex[] =
"010300000001000000050000000000000080841ec100000000600122410000000080841ec100000000804f22410000000040e81dc100000000804f22410000000040e81dc100000000600122410000000080841ec10000000060012241";
53 const char *pos = wkb_hex;
54 unsigned char *wkb = NULL;
58 double scale_y = -100;
63 double nodata[] = {0};
67 wkb_len = (int) ceil(((
double) strlen(wkb_hex)) / 2);
68 wkb = (
unsigned char *)
rtalloc(
sizeof(
unsigned char) * wkb_len);
69 for (i = 0; i < wkb_len; i++) {
70 sscanf(pos,
"%2hhx", &wkb[i]);
88 CU_ASSERT(raster != NULL);
120 band =
cu_add_band(raster, pixtype, hasnodata, nodataval);
121 CU_ASSERT(band != NULL);
175 CU_ASSERT_DOUBLE_EQUAL(gv[0].val, 1.8, FLT_EPSILON);
178 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((3 1,3 2,2 2,2 3,1 3,1 6,2 6,2 7,3 7,3 8,5 8,5 6,3 6,3 3,4 3,5 3,5 1,3 1))");
181 CU_ASSERT_DOUBLE_EQUAL(gv[1].val, 0.0, FLT_EPSILON);
183 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((3 3,3 6,6 6,6 3,3 3))");
186 CU_ASSERT_DOUBLE_EQUAL(gv[2].val, 2.8, FLT_EPSILON);
189 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))");
192 CU_ASSERT_DOUBLE_EQUAL(gv[3].val, 0.0, FLT_EPSILON);
194 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))");
218 CU_ASSERT_DOUBLE_EQUAL(gv[1].val, 0.0, FLT_EPSILON);
220 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((3 3,3 6,6 6,6 3,3 3))");
223 CU_ASSERT_DOUBLE_EQUAL(gv[2].val, 2.8, FLT_EPSILON);
225 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))");
228 CU_ASSERT_DOUBLE_EQUAL(gv[3].val, 0.0, FLT_EPSILON);
230 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))");
254 CU_ASSERT_DOUBLE_EQUAL(gv[0].val, 1.8, FLT_EPSILON);
256 CU_ASSERT_DOUBLE_EQUAL(gv[3].val, 0.0, FLT_EPSILON);
258 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))");
262 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((3 1,3 2,2 2,2 3,1 3,1 6,2 6,2 7,3 7,3 8,5 8,5 6,3 6,3 3,4 3,5 3,5 1,3 1))");
265 CU_ASSERT_DOUBLE_EQUAL(gv[1].val, 0.0, FLT_EPSILON);
267 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((3 3,3 6,6 6,6 3,3 3))");
290 CU_ASSERT_DOUBLE_EQUAL(gv[0].val, 1.8, FLT_EPSILON);
293 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((3 1,3 2,2 2,2 3,1 3,1 6,2 6,2 7,3 7,3 8,5 8,5 6,3 6,3 3,4 3,5 3,5 1,3 1))");
296 CU_ASSERT_DOUBLE_EQUAL(gv[1].val, 2.8, FLT_EPSILON);
299 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))");
322 CU_ASSERT_DOUBLE_EQUAL(gv[0].val, 1.8, FLT_EPSILON);
325 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((3 1,3 2,2 2,2 3,1 3,1 6,2 6,2 7,3 7,3 8,5 8,5 6,3 6,3 3,4 3,5 3,5 1,3 1))");
328 CU_ASSERT_DOUBLE_EQUAL(gv[1].val, 0.0, FLT_EPSILON);
330 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((3 3,3 6,6 6,6 3,3 3))");
333 CU_ASSERT_DOUBLE_EQUAL(gv[2].val, 2.8, FLT_EPSILON);
336 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))");
339 CU_ASSERT_DOUBLE_EQUAL(gv[3].val, 0.0, FLT_EPSILON);
341 CU_ASSERT_STRING_EQUAL(wkt,
"POLYGON((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))");
357 char srs[] =
"PROJCS[\"unnamed\",GEOGCS[\"unnamed ellipse\",DATUM[\"unknown\",SPHEROID[\"unnamed\",6370997,0]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Lambert_Azimuthal_Equal_Area\"],PARAMETER[\"latitude_of_center\",45],PARAMETER[\"longitude_of_center\",-100],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"2163\"]]";
363 CU_ASSERT(raster != NULL);
366 CU_ASSERT(band != NULL);
371 for (x = 0; x < width; x++) {
372 for (y = 0; y < height; y++) {
373 rt_band_set_pixel(band, x, y, (((
double) x * y) + (x + y) + (x + y * x)) / (x + y + 1), NULL);
388 if (gdal) CPLFree(gdal);
393 CU_ASSERT(raster != NULL);
396 CU_ASSERT(band != NULL);
401 for (x = 0; x < width; x++) {
402 for (y = 0; y < height; y++) {
414 if (gdal) CPLFree(gdal);
430 double values[width][height];
434 GDALDriverH gddrv = NULL;
436 GDALDatasetH gdds = NULL;
439 CU_ASSERT(raster != NULL);
442 CU_ASSERT(band != NULL);
444 for (x = 0; x < width; x++) {
445 for (y = 0; y < height; y++) {
446 values[
x][
y] = (((double) x * y) + (x +
y) + (x + y * x)) / (x + y + 1);
452 CU_ASSERT(gddrv != NULL);
453 CU_ASSERT_EQUAL(destroy, 0);
454 CU_ASSERT(gdds != NULL);
455 CU_ASSERT_EQUAL(GDALGetRasterXSize(gdds), width);
456 CU_ASSERT_EQUAL(GDALGetRasterYSize(gdds), height);
459 CU_ASSERT(rast != NULL);
463 CU_ASSERT(band != NULL);
465 for (x = 0; x < width; x++) {
466 for (y = 0; y < height; y++) {
469 CU_ASSERT_DOUBLE_EQUAL(value, values[x][y], DBL_EPSILON);
481 CU_ASSERT(raster != NULL);
485 CU_ASSERT(band != NULL);
488 for (x = 0; x < width; x++) {
489 for (y = 0; y < height; y++) {
498 CU_ASSERT(gddrv != NULL);
499 CU_ASSERT_EQUAL(destroy, 0);
500 CU_ASSERT(gdds != NULL);
501 CU_ASSERT_EQUAL(GDALGetRasterXSize(gdds), width);
502 CU_ASSERT_EQUAL(GDALGetRasterYSize(gdds), height);
505 CU_ASSERT(rast != NULL);
509 CU_ASSERT(band != NULL);
512 for (x = 0; x < width; x++) {
513 for (y = 0; y < height; y++) {
516 CU_ASSERT_DOUBLE_EQUAL(value, values[x][y], 1.);
540 char src_srs[] =
"PROJCS[\"unnamed\",GEOGCS[\"unnamed ellipse\",DATUM[\"unknown\",SPHEROID[\"unnamed\",6370997,0]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Lambert_Azimuthal_Equal_Area\"],PARAMETER[\"latitude_of_center\",45],PARAMETER[\"longitude_of_center\",-100],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"2163\"]]";
542 char dst_srs[] =
"PROJCS[\"NAD83 / California Albers\",GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6269\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4269\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],PROJECTION[\"Albers_Conic_Equal_Area\"],PARAMETER[\"standard_parallel_1\",34],PARAMETER[\"standard_parallel_2\",40.5],PARAMETER[\"latitude_of_center\",0],PARAMETER[\"longitude_of_center\",-120],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",-4000000],AUTHORITY[\"EPSG\",\"3310\"],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]";
545 CU_ASSERT(raster != NULL);
548 CU_ASSERT(band != NULL);
553 for (x = 0; x < width; x++) {
554 for (y = 0; y < height; y++) {
555 rt_band_set_pixel(band, x, y, (((
double) x * y) + (x + y) + (x + y * x)) / (x + y + 1), NULL);
567 GRA_NearestNeighbour, -1
569 CU_ASSERT(rast != NULL);
575 CU_ASSERT(band != NULL);
579 CU_ASSERT_DOUBLE_EQUAL(value, 0., DBL_EPSILON);
582 CU_ASSERT_DOUBLE_EQUAL(value, 0., DBL_EPSILON);
592 CU_pSuite suite = CU_add_suite(
"gdal", NULL, NULL);
static void test_gdal_to_raster()
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
int rt_raster_get_num_bands(rt_raster raster)
static void test_gdal_drivers()
char * lwgeom_to_wkt(const LWGEOM *geom, uint8_t variant, int precision, size_t *size_out)
WKT emitter function.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
static void test_gdal_polygonize()
rt_geomval rt_raster_gdal_polygonize(rt_raster raster, int nband, int exclude_nodata_value, int *pnElements)
Returns a set of "geomval" value, one for each group of pixel sharing the same value for the provided...
void lwgeom_free(LWGEOM *geom)
struct rt_gdaldriver_t * rt_gdaldriver
GDALDatasetH rt_raster_to_gdal_mem(rt_raster raster, const char *srs, uint32_t *bandNums, int *excludeNodataValues, int count, GDALDriverH *rtn_drv, int *destroy_rtn_drv)
Return GDAL dataset using GDAL MEM driver from raster.
rt_raster rt_raster_gdal_rasterize(const unsigned char *wkb, uint32_t wkb_len, const char *srs, uint32_t num_bands, rt_pixtype *pixtype, double *init, double *value, double *nodata, uint8_t *hasnodata, int *width, int *height, double *scale_x, double *scale_y, double *ul_xw, double *ul_yw, double *grid_xw, double *grid_yw, double *skew_x, double *skew_y, char **options)
Return a raster of the provided geometry.
void * rtalloc(size_t size)
Wrappers used for managing memory.
rt_raster rt_raster_gdal_warp(rt_raster raster, const char *src_srs, const char *dst_srs, double *scale_x, double *scale_y, int *width, int *height, double *ul_xw, double *ul_yw, double *grid_xw, double *grid_yw, double *skew_x, double *skew_y, GDALResampleAlg resample_alg, double max_err)
Return a warped raster using GDAL Warp API.
static void test_raster_to_gdal()
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
void cu_free_raster(rt_raster raster)
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
static char * lwgeom_to_text(const LWGEOM *lwgeom)
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
#define PG_ADD_TEST(suite, testfunc)
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
static rt_raster fillRasterToPolygonize(int hasnodata, double nodataval)
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
static void test_gdal_warp()
uint16_t rt_raster_get_width(rt_raster raster)
void rtdealloc(void *mem)
void gdal_suite_setup(void)
uint8_t * rt_raster_to_gdal(rt_raster raster, const char *srs, char *format, char **options, uint64_t *gdalsize)
Return formatted GDAL raster from raster.
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
int rt_util_gdal_configured(void)
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.
uint16_t rt_raster_get_height(rt_raster raster)
static void test_gdal_rasterize()
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
static void test_gdal_configured()