458 text *algtext = NULL;
459 char *algchar = NULL;
460 GDALResampleAlg alg = GRA_NearestNeighbour;
461 double max_err = 0.125;
464 char *src_srs = NULL;
466 char *dst_srs = NULL;
469 double scale[2] = {0};
470 double *scale_x = NULL;
471 double *scale_y = NULL;
473 double gridw[2] = {0};
474 double *grid_xw = NULL;
475 double *grid_yw = NULL;
477 double skew[2] = {0};
478 double *skew_x = NULL;
479 double *skew_y = NULL;
490 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
495 PG_FREE_IF_COPY(pgraster, 0);
496 elog(ERROR,
"RASTER_GDALWarp: Could not deserialize raster");
501 if (!PG_ARGISNULL(1)) {
502 algtext = PG_GETARG_TEXT_P(1);
509 if (!PG_ARGISNULL(2)) {
510 max_err = PG_GETARG_FLOAT8(2);
511 if (max_err < 0.) max_err = 0.;
520 if (!PG_ARGISNULL(3)) {
524 PG_FREE_IF_COPY(pgraster, 0);
525 elog(ERROR,
"RASTER_GDALWarp: %d is an invalid target SRID", dst_srid);
536 PG_FREE_IF_COPY(pgraster, 0);
537 elog(ERROR,
"RASTER_GDALWarp: Input raster has unknown (%d) SRID", src_srid);
541 else if (dst_srid == src_srid) {
546 if (!PG_ARGISNULL(4)) {
547 scale[0] = PG_GETARG_FLOAT8(4);
548 if (
FLT_NEQ(scale[0], 0)) scale_x = &scale[0];
552 if (!PG_ARGISNULL(5)) {
553 scale[1] = PG_GETARG_FLOAT8(5);
554 if (
FLT_NEQ(scale[1], 0)) scale_y = &scale[1];
558 if (!PG_ARGISNULL(6)) {
559 gridw[0] = PG_GETARG_FLOAT8(6);
564 if (!PG_ARGISNULL(7)) {
565 gridw[1] = PG_GETARG_FLOAT8(7);
570 if (!PG_ARGISNULL(8)) {
571 skew[0] = PG_GETARG_FLOAT8(8);
572 if (
FLT_NEQ(skew[0], 0)) skew_x = &skew[0];
576 if (!PG_ARGISNULL(9)) {
577 skew[1] = PG_GETARG_FLOAT8(9);
578 if (
FLT_NEQ(skew[1], 0)) skew_y = &skew[1];
582 if (!PG_ARGISNULL(10)) {
583 dim[0] = PG_GETARG_INT32(10);
584 if (dim[0] < 0) dim[0] = 0;
585 if (dim[0] > 0) dim_x = &dim[0];
589 if (!PG_ARGISNULL(11)) {
590 dim[1] = PG_GETARG_INT32(11);
591 if (dim[1] < 0) dim[1] = 0;
592 if (dim[1] > 0) dim_y = &dim[1];
598 (scale_x == NULL) && (scale_y == NULL) &&
599 (grid_xw == NULL) && (grid_yw == NULL) &&
600 (skew_x == NULL) && (skew_y == NULL) &&
601 (dim_x == NULL) && (dim_y == NULL)
603 elog(NOTICE,
"No resampling parameters provided. Returning original raster");
605 PG_RETURN_POINTER(pgraster);
609 (grid_xw != NULL && grid_yw == NULL) ||
610 (grid_xw == NULL && grid_yw != NULL)
612 elog(NOTICE,
"Values must be provided for both X and Y when specifying the alignment. Returning original raster");
614 PG_RETURN_POINTER(pgraster);
618 (scale_x != NULL && scale_y == NULL) ||
619 (scale_x == NULL && scale_y != NULL)
621 elog(NOTICE,
"Values must be provided for both X and Y when specifying the scale. Returning original raster");
623 PG_RETURN_POINTER(pgraster);
627 (scale_x != NULL || scale_y != NULL) &&
628 (dim_x != NULL || dim_y != NULL)
630 elog(NOTICE,
"Scale X/Y and width/height are mutually exclusive. Only provide one. Returning original raster");
632 PG_RETURN_POINTER(pgraster);
639 if (NULL == src_srs) {
641 PG_FREE_IF_COPY(pgraster, 0);
642 elog(ERROR,
"RASTER_GDALWarp: Input raster has unknown SRID (%d)", src_srid);
648 if (NULL == dst_srs) {
649 if (!no_srid) pfree(src_srs);
651 PG_FREE_IF_COPY(pgraster, 0);
652 elog(ERROR,
"RASTER_GDALWarp: Target SRID (%d) is unknown", dst_srid);
668 PG_FREE_IF_COPY(pgraster, 0);
674 elog(ERROR,
"RASTER_band: Could not create transformed raster");
684 if (NULL == pgrast) PG_RETURN_NULL();
688 SET_VARSIZE(pgrast, pgrast->
size);
689 PG_RETURN_POINTER(pgrast);
int clamp_srid(int srid)
Return a valid SRID from an arbitrary integer Raises a notice if what comes out is different from wha...
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
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.
#define POSTGIS_RT_DEBUGF(level, msg,...)
#define SRID_UNKNOWN
Unknown SRID value.
char * rtpg_trim(const char *input)
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
char * rtpg_getSR(int srid)
#define POSTGIS_RT_DEBUG(level, msg)
GDALResampleAlg rt_util_gdal_resample_alg(const char *algname)
Convert cstring name to GDAL Resample Algorithm.
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
char * rtpg_strtoupper(char *str)