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++) {
71 sscanf(pos,
"%2x", &b);
72 wkb[i] = (
unsigned char)b;
113 CU_ASSERT(
band != NULL);
159 LWGEOM *gexpected, *gobserved;
160 gexpected =
lwgeom_from_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))",
169 CU_ASSERT_DOUBLE_EQUAL(gv[0].val, 1.8, FLT_EPSILON);
171 gobserved = (
LWGEOM *)gv[0].geom;
175 CU_ASSERT_DOUBLE_EQUAL(gv[1].val, 0.0, FLT_EPSILON);
176 gobserved = (
LWGEOM *)gv[1].geom;
180 CU_ASSERT_DOUBLE_EQUAL(gv[2].val, 2.8, FLT_EPSILON);
181 gobserved = (
LWGEOM *)gv[2].geom;
182 gexpected =
lwgeom_from_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))",
186 gobserved = (
LWGEOM *)gv[3].geom;
188 "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))",
190 CU_ASSERT_DOUBLE_EQUAL(gv[3].val, 0.0, FLT_EPSILON);
214 CU_ASSERT_DOUBLE_EQUAL(gv[1].val, 0.0, FLT_EPSILON);
215 gobserved = (
LWGEOM *)gv[1].geom;
222 CU_ASSERT_DOUBLE_EQUAL(gv[2].val, 2.8, FLT_EPSILON);
223 gobserved = (
LWGEOM *)gv[2].geom;
224 gexpected =
lwgeom_from_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))",
231 CU_ASSERT_DOUBLE_EQUAL(gv[3].val, 0.0, FLT_EPSILON);
232 gobserved = (
LWGEOM *)gv[3].geom;
234 "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))",
259 CU_ASSERT_DOUBLE_EQUAL(gv[3].val, 0.0, FLT_EPSILON);
260 gobserved = (
LWGEOM *)gv[3].geom;
262 "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))",
266 gobserved = (
LWGEOM *)gv[0].geom;
268 "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))",
LW_PARSER_CHECK_NONE);
271 CU_ASSERT_DOUBLE_EQUAL(gv[1].val, 0.0, FLT_EPSILON);
272 gobserved = (
LWGEOM *)gv[1].geom;
296 CU_ASSERT_DOUBLE_EQUAL(gv[0].val, 1.8, FLT_EPSILON);
297 gobserved = (
LWGEOM *)gv[0].geom;
298 gexpected =
lwgeom_from_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))",
LW_PARSER_CHECK_NONE);
301 CU_ASSERT_DOUBLE_EQUAL(gv[1].val, 2.8, FLT_EPSILON);
302 gobserved = (
LWGEOM *)gv[1].geom;
303 gexpected =
lwgeom_from_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))",
327 CU_ASSERT_DOUBLE_EQUAL(gv[0].val, 1.8, FLT_EPSILON);
328 gobserved = (
LWGEOM *)gv[0].geom;
330 "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))",
LW_PARSER_CHECK_NONE);
333 CU_ASSERT_DOUBLE_EQUAL(gv[1].val, 0.0, FLT_EPSILON);
334 gobserved = (
LWGEOM *)gv[1].geom;
338 CU_ASSERT_DOUBLE_EQUAL(gv[2].val, 2.8, FLT_EPSILON);
339 gobserved = (
LWGEOM *)gv[2].geom;
340 gexpected =
lwgeom_from_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))",
344 CU_ASSERT_DOUBLE_EQUAL(gv[3].val, 0.0, FLT_EPSILON);
345 gobserved = (
LWGEOM *)gv[3].geom;
347 "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))",
364 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\"]]";
370 CU_ASSERT(
raster != NULL);
373 CU_ASSERT(
band != NULL);
378 for (
x = 0;
x < width;
x++) {
379 for (
y = 0;
y < height;
y++) {
395 if (gdal) CPLFree(gdal);
400 CU_ASSERT(
raster != NULL);
403 CU_ASSERT(
band != NULL);
408 for (
x = 0;
x < width;
x++) {
409 for (
y = 0;
y < height;
y++) {
421 if (gdal) CPLFree(gdal);
424 CU_ASSERT(gdal == NULL);
440 double values[width][height];
444 GDALDriverH gddrv = NULL;
446 GDALDatasetH gdds = NULL;
449 CU_ASSERT(
raster != NULL);
452 CU_ASSERT(
band != NULL);
454 for (
x = 0;
x < width;
x++) {
455 for (
y = 0;
y < height;
y++) {
456 values[
x][
y] = (((double)
x *
y) + (
x +
y) + (
x +
y *
x)) / (
x +
y + 1);
462 CU_ASSERT(gddrv != NULL);
463 CU_ASSERT_EQUAL(destroy, 0);
464 CU_ASSERT(gdds != NULL);
465 CU_ASSERT_EQUAL((
uint32_t)GDALGetRasterXSize(gdds), width);
466 CU_ASSERT_EQUAL((
uint32_t)GDALGetRasterYSize(gdds), height);
469 CU_ASSERT(
rast != NULL);
473 CU_ASSERT(
band != NULL);
475 for (
x = 0;
x < width;
x++) {
476 for (
y = 0;
y < height;
y++) {
479 CU_ASSERT_DOUBLE_EQUAL(
value, values[
x][
y], DBL_EPSILON);
491 CU_ASSERT(
raster != NULL);
495 CU_ASSERT(
band != NULL);
498 for (
x = 0;
x < width;
x++) {
499 for (
y = 0;
y < height;
y++) {
508 CU_ASSERT(gddrv != NULL);
509 CU_ASSERT_EQUAL(destroy, 0);
510 CU_ASSERT(gdds != NULL);
511 CU_ASSERT_EQUAL((
uint32_t)GDALGetRasterXSize(gdds), width);
512 CU_ASSERT_EQUAL((
uint32_t)GDALGetRasterYSize(gdds), height);
515 CU_ASSERT(
rast != NULL);
519 CU_ASSERT(
band != NULL);
522 for (
x = 0;
x < width;
x++) {
523 for (
y = 0;
y < height;
y++) {
526 CU_ASSERT_DOUBLE_EQUAL(
value, values[
x][
y], 1.);
550 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\"]]";
552 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]]";
555 CU_ASSERT(
raster != NULL);
558 CU_ASSERT(
band != NULL);
563 for (
x = 0;
x < width;
x++) {
564 for (
y = 0;
y < height;
y++) {
577 GRA_NearestNeighbour, -1
579 CU_ASSERT(
rast != NULL);
585 CU_ASSERT(
band != NULL);
589 CU_ASSERT_DOUBLE_EQUAL(
value, 0., DBL_EPSILON);
592 CU_ASSERT_DOUBLE_EQUAL(
value, 0., DBL_EPSILON);
602 CU_pSuite suite = CU_add_suite(
"gdal", NULL, NULL);
static rt_raster fillRasterToPolygonize(int hasnodata, double nodataval)
static void test_gdal_warp()
static void test_gdal_rasterize()
static void test_gdal_to_raster()
static void test_raster_to_gdal()
void gdal_suite_setup(void)
static void test_gdal_drivers()
static void test_gdal_configured()
static void test_gdal_polygonize()
#define PG_ADD_TEST(suite, testfunc)
void lwgeom_free(LWGEOM *geom)
#define LW_PARSER_CHECK_NONE
double lwgeom_area(const LWGEOM *geom)
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
void * rtalloc(size_t size)
Wrappers used for managing memory.
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
int rt_util_gdal_configured(void)
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
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.
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.
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...
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
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.
uint16_t rt_raster_get_num_bands(rt_raster raster)
struct rt_gdaldriver_t * rt_gdaldriver
uint16_t rt_raster_get_height(rt_raster raster)
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
uint16_t rt_raster_get_width(rt_raster raster)
void rtdealloc(void *mem)
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.
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.
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
void cu_free_raster(rt_raster raster)