3472 double _offset[2][4] = {{0.}};
3473 uint16_t _dim[2][2] = {{0}};
3478 double gt[6] = {0.};
3480 assert(NULL != rast1);
3481 assert(NULL != rast2);
3482 assert(NULL != rtnraster);
3489 rterror(
"rt_raster_from_two_rasters: Could not test for alignment on the two rasters");
3493 rterror(
"rt_raster_from_two_rasters: The two rasters provided do not have the same alignment");
3498 _dim[0][0] = rast1->
width;
3499 _dim[0][1] = rast1->
height;
3500 _dim[1][0] = rast2->
width;
3501 _dim[1][1] = rast2->
height;
3506 _rast[0]->ipX, _rast[0]->ipY,
3507 &(_offset[1][0]), &(_offset[1][1]),
3510 rterror(
"rt_raster_from_two_rasters: Could not compute offsets of the second raster relative to the first raster");
3513 _offset[1][0] = -1 * _offset[1][0];
3514 _offset[1][1] = -1 * _offset[1][1];
3515 _offset[1][2] = _offset[1][0] + _dim[1][0] - 1;
3516 _offset[1][3] = _offset[1][1] + _dim[1][1] - 1;
3519 switch (extenttype) {
3529 _offset[0][0] = -1 * _offset[1][0];
3530 _offset[0][1] = -1 * _offset[1][1];
3535 dim[0] = _dim[i][0];
3536 dim[1] = _dim[i][1];
3542 rterror(
"rt_raster_from_two_rasters: Could not create output raster");
3550 double off[4] = {0};
3564 if (_offset[1][0] < 0)
3565 off[0] = _offset[1][0];
3567 if (_offset[1][1] < 0)
3568 off[1] = _offset[1][1];
3571 off[2] = _dim[0][0] - 1;
3572 if ((
int) _offset[1][2] >= _dim[0][0])
3573 off[2] = _offset[1][2];
3574 off[3] = _dim[0][1] - 1;
3575 if ((
int) _offset[1][3] >= _dim[0][1])
3576 off[3] = _offset[1][3];
3585 rterror(
"rt_raster_from_two_rasters: Could not get spatial coordinates of upper-left pixel of output raster");
3589 dim[0] = off[2] - off[0] + 1;
3590 dim[1] = off[3] - off[1] + 1;
3604 rterror(
"rt_raster_from_two_rasters: Could not create output raster");
3622 &(_offset[0][0]), &(_offset[0][1]),
3625 rterror(
"rt_raster_from_two_rasters: Could not get offsets of the FIRST raster relative to the output raster");
3629 _offset[0][0] *= -1;
3630 _offset[0][1] *= -1;
3635 &(_offset[1][0]), &(_offset[1][1]),
3638 rterror(
"rt_raster_from_two_rasters: Could not get offsets of the SECOND raster relative to the output raster");
3642 _offset[1][0] *= -1;
3643 _offset[1][1] *= -1;
3647 double off[4] = {0};
3651 (_offset[1][2] < 0 || _offset[1][0] > (_dim[0][0] - 1)) ||
3652 (_offset[1][3] < 0 || _offset[1][1] > (_dim[0][1] - 1))
3654 RASTER_DEBUG(3,
"The two rasters provided have no intersection. Returning no band raster");
3658 rterror(
"rt_raster_from_two_rasters: Could not create output raster");
3665 if (NULL != offset) {
3666 for (i = 0; i < 4; i++)
3667 offset[i] = _offset[i / 2][i % 2];
3674 if (_offset[1][0] > 0)
3675 off[0] = _offset[1][0];
3676 if (_offset[1][1] > 0)
3677 off[1] = _offset[1][1];
3679 off[2] = _dim[0][0] - 1;
3680 if (_offset[1][2] < _dim[0][0])
3681 off[2] = _offset[1][2];
3682 off[3] = _dim[0][1] - 1;
3683 if (_offset[1][3] < _dim[0][1])
3684 off[3] = _offset[1][3];
3686 dim[0] = off[2] - off[0] + 1;
3687 dim[1] = off[3] - off[1] + 1;
3693 rterror(
"rt_raster_from_two_rasters: Could not create output raster");
3706 rterror(
"rt_raster_from_two_rasters: Could not get spatial coordinates of upper-left pixel of output raster");
3717 &(_offset[0][0]), &(_offset[0][1]),
3720 rterror(
"rt_raster_from_two_rasters: Could not get pixel coordinates to compute the offsets of the FIRST raster relative to the output raster");
3724 _offset[0][0] *= -1;
3725 _offset[0][1] *= -1;
3730 &(_offset[1][0]), &(_offset[1][1]),
3733 rterror(
"rt_raster_from_two_rasters: Could not get pixel coordinates to compute the offsets of the SECOND raster relative to the output raster");
3737 _offset[1][0] *= -1;
3738 _offset[1][1] *= -1;
3742 rterror(
"rt_raster_from_two_rasters: Extent type ET_CUSTOM is not supported by this function");
3747 if (NULL != offset) {
3748 for (i = 0; i < 4; i++)
3749 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 cell coordinate.
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.