PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ test_gdal_warp()

static void test_gdal_warp ( )
static

Definition at line 531 of file cu_gdal.c.

References ovdump::band, cu_add_band(), cu_free_raster(), ES_NONE, gdal_suite_setup(), PT_64BF, rtpixdump::rast, rtrowdump::raster, rt_band_get_hasnodata_flag(), rt_band_get_nodata(), rt_band_get_pixel(), rt_band_set_pixel(), rt_raster_gdal_warp(), rt_raster_get_band(), rt_raster_get_height(), rt_raster_get_num_bands(), rt_raster_get_width(), rt_raster_new(), rt_raster_set_offsets(), rt_raster_set_scale(), genraster::value, pixval::x, and pixval::y.

Referenced by gdal_suite_setup().

531  {
532  rt_pixtype pixtype = PT_64BF;
533  rt_band band = NULL;
534 
536  rt_raster rast;
537  uint32_t x;
538  uint32_t width = 100;
539  uint32_t y;
540  uint32_t height = 100;
541  double value = 0;
542 
543  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\"]]";
544 
545  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]]";
546 
547  raster = rt_raster_new(width, height);
548  CU_ASSERT(raster != NULL); /* or we're out of virtual memory */
549 
550  band = cu_add_band(raster, pixtype, 1, 0);
551  CU_ASSERT(band != NULL);
552 
553  rt_raster_set_offsets(raster, -500000, 600000);
554  rt_raster_set_scale(raster, 1000, -1000);
555 
556  for (x = 0; x < width; x++) {
557  for (y = 0; y < height; y++) {
558  rt_band_set_pixel(band, x, y, (((double) x * y) + (x + y) + (x + y * x)) / (x + y + 1), NULL);
559  }
560  }
561 
562  rast = rt_raster_gdal_warp(
563  raster,
564  src_srs, dst_srs,
565  NULL, NULL,
566  NULL, NULL,
567  NULL, NULL,
568  NULL, NULL,
569  NULL, NULL,
570  GRA_NearestNeighbour, -1
571  );
572  CU_ASSERT(rast != NULL);
573  CU_ASSERT_EQUAL(rt_raster_get_width(rast), 122);
574  CU_ASSERT_EQUAL(rt_raster_get_height(rast), 116);
575  CU_ASSERT_NOT_EQUAL(rt_raster_get_num_bands(rast), 0);
576 
577  band = rt_raster_get_band(rast, 0);
578  CU_ASSERT(band != NULL);
579 
580  CU_ASSERT(rt_band_get_hasnodata_flag(band));
581  rt_band_get_nodata(band, &value);
582  CU_ASSERT_DOUBLE_EQUAL(value, 0., DBL_EPSILON);
583 
584  CU_ASSERT_EQUAL(rt_band_get_pixel(band, 0, 0, &value, NULL), ES_NONE);
585  CU_ASSERT_DOUBLE_EQUAL(value, 0., DBL_EPSILON);
586 
587  cu_free_raster(rast);
588  cu_free_raster(raster);
589 }
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
raster
Be careful!! Zeros function&#39;s input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
band
Definition: ovdump.py:57
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.
Definition: rt_warp.c:178
rt_pixtype
Definition: librtcore.h:185
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1730
unsigned int uint32_t
Definition: uthash.h:78
void cu_free_raster(rt_raster raster)
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1221
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_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:381
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:674
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_raster.c:121
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel&#39;s value.
Definition: rt_band.c:974
int value
Definition: genraster.py:61
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_raster.c:129
Here is the call graph for this function:
Here is the caller graph for this function: