3345 double _offset[2][4] = {{0.}};
3346 uint16_t _dim[2][2] = {{0}};
3351 double gt[6] = {0.};
3353 assert(NULL != rast1);
3354 assert(NULL != rast2);
3355 assert(NULL != rtnraster);
3362 rterror(
"rt_raster_from_two_rasters: Could not test for alignment on the two rasters");
3366 rterror(
"rt_raster_from_two_rasters: The two rasters provided do not have the same alignment");
3371 _dim[0][0] = rast1->
width;
3372 _dim[0][1] = rast1->
height;
3373 _dim[1][0] = rast2->
width;
3374 _dim[1][1] = rast2->
height;
3379 _rast[0]->ipX, _rast[0]->ipY,
3380 &(_offset[1][0]), &(_offset[1][1]),
3383 rterror(
"rt_raster_from_two_rasters: Could not compute offsets of the second raster relative to the first raster");
3386 _offset[1][0] = -1 * _offset[1][0];
3387 _offset[1][1] = -1 * _offset[1][1];
3388 _offset[1][2] = _offset[1][0] + _dim[1][0] - 1;
3389 _offset[1][3] = _offset[1][1] + _dim[1][1] - 1;
3392 switch (extenttype) {
3402 _offset[0][0] = -1 * _offset[1][0];
3403 _offset[0][1] = -1 * _offset[1][1];
3408 dim[0] = _dim[i][0];
3409 dim[1] = _dim[i][1];
3415 rterror(
"rt_raster_from_two_rasters: Could not create output raster");
3423 double off[4] = {0};
3437 if (_offset[1][0] < 0)
3438 off[0] = _offset[1][0];
3440 if (_offset[1][1] < 0)
3441 off[1] = _offset[1][1];
3444 off[2] = _dim[0][0] - 1;
3445 if ((
int) _offset[1][2] >= _dim[0][0])
3446 off[2] = _offset[1][2];
3447 off[3] = _dim[0][1] - 1;
3448 if ((
int) _offset[1][3] >= _dim[0][1])
3449 off[3] = _offset[1][3];
3458 rterror(
"rt_raster_from_two_rasters: Could not get spatial coordinates of upper-left pixel of output raster");
3462 dim[0] = off[2] - off[0] + 1;
3463 dim[1] = off[3] - off[1] + 1;
3477 rterror(
"rt_raster_from_two_rasters: Could not create output raster");
3495 &(_offset[0][0]), &(_offset[0][1]),
3498 rterror(
"rt_raster_from_two_rasters: Could not get offsets of the FIRST raster relative to the output raster");
3502 _offset[0][0] *= -1;
3503 _offset[0][1] *= -1;
3508 &(_offset[1][0]), &(_offset[1][1]),
3511 rterror(
"rt_raster_from_two_rasters: Could not get offsets of the SECOND raster relative to the output raster");
3515 _offset[1][0] *= -1;
3516 _offset[1][1] *= -1;
3520 double off[4] = {0};
3524 (_offset[1][2] < 0 || _offset[1][0] > (_dim[0][0] - 1)) ||
3525 (_offset[1][3] < 0 || _offset[1][1] > (_dim[0][1] - 1))
3527 RASTER_DEBUG(3,
"The two rasters provided have no intersection. Returning no band raster");
3531 rterror(
"rt_raster_from_two_rasters: Could not create output raster");
3538 if (NULL != offset) {
3539 for (i = 0; i < 4; i++)
3540 offset[i] = _offset[i / 2][i % 2];
3547 if (_offset[1][0] > 0)
3548 off[0] = _offset[1][0];
3549 if (_offset[1][1] > 0)
3550 off[1] = _offset[1][1];
3552 off[2] = _dim[0][0] - 1;
3553 if (_offset[1][2] < _dim[0][0])
3554 off[2] = _offset[1][2];
3555 off[3] = _dim[0][1] - 1;
3556 if (_offset[1][3] < _dim[0][1])
3557 off[3] = _offset[1][3];
3559 dim[0] = off[2] - off[0] + 1;
3560 dim[1] = off[3] - off[1] + 1;
3566 rterror(
"rt_raster_from_two_rasters: Could not create output raster");
3579 rterror(
"rt_raster_from_two_rasters: Could not get spatial coordinates of upper-left pixel of output raster");
3590 &(_offset[0][0]), &(_offset[0][1]),
3593 rterror(
"rt_raster_from_two_rasters: Could not get pixel coordinates to compute the offsets of the FIRST raster relative to the output raster");
3597 _offset[0][0] *= -1;
3598 _offset[0][1] *= -1;
3603 &(_offset[1][0]), &(_offset[1][1]),
3606 rterror(
"rt_raster_from_two_rasters: Could not get pixel coordinates to compute the offsets of the SECOND raster relative to the output raster");
3610 _offset[1][0] *= -1;
3611 _offset[1][1] *= -1;
3615 rterror(
"rt_raster_from_two_rasters: Extent type ET_CUSTOM is not supported by this function");
3620 if (NULL != offset) {
3621 for (i = 0; i < 4; i++)
3622 offset[i] = _offset[i / 2][i % 2];
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
#define RASTER_DEBUG(level, msg)
#define RASTER_DEBUGF(level, msg,...)
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
rt_errorstate rt_raster_cell_to_geopoint(rt_raster raster, double xr, double yr, double *xw, double *yw, double *gt)
Convert an xr, yr raster point to an xw, yw point on map.
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster's geotransform using 6-element array.
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
rt_errorstate rt_raster_geopoint_to_cell(rt_raster raster, double xw, double yw, double *xr, double *yr, double *igt)
Convert an xw,yw map point to a xr,yr raster point.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.