3452 double _offset[2][4] = {{0.}};
3453 uint16_t _dim[2][2] = {{0}};
3458 double gt[6] = {0.};
3460 assert(NULL != rast1);
3461 assert(NULL != rast2);
3462 assert(NULL != rtnraster);
3469 rterror(
"rt_raster_from_two_rasters: Could not test for alignment on the two rasters");
3473 rterror(
"rt_raster_from_two_rasters: The two rasters provided do not have the same alignment");
3478 _dim[0][0] = rast1->
width;
3479 _dim[0][1] = rast1->
height;
3480 _dim[1][0] = rast2->width;
3481 _dim[1][1] = rast2->height;
3486 _rast[0]->
ipX, _rast[0]->
ipY,
3487 &(_offset[1][0]), &(_offset[1][1]),
3490 rterror(
"rt_raster_from_two_rasters: Could not compute offsets of the second raster relative to the first raster");
3493 _offset[1][0] = -1 * _offset[1][0];
3494 _offset[1][1] = -1 * _offset[1][1];
3495 _offset[1][2] = _offset[1][0] + _dim[1][0] - 1;
3496 _offset[1][3] = _offset[1][1] + _dim[1][1] - 1;
3499 switch (extenttype) {
3508 _offset[0][0] = -1 * _offset[1][0];
3509 _offset[0][1] = -1 * _offset[1][1];
3514 dim[0] = _dim[i][0];
3515 dim[1] = _dim[i][1];
3520 if (raster == NULL) {
3521 rterror(
"rt_raster_from_two_rasters: Could not create output raster");
3529 double off[4] = {0};
3543 if (_offset[1][0] < 0)
3544 off[0] = _offset[1][0];
3546 if (_offset[1][1] < 0)
3547 off[1] = _offset[1][1];
3550 off[2] = _dim[0][0] - 1;
3551 if ((
int) _offset[1][2] >= _dim[0][0])
3552 off[2] = _offset[1][2];
3553 off[3] = _dim[0][1] - 1;
3554 if ((
int) _offset[1][3] >= _dim[0][1])
3555 off[3] = _offset[1][3];
3564 rterror(
"rt_raster_from_two_rasters: Could not get spatial coordinates of upper-left pixel of output raster");
3568 dim[0] = off[2] - off[0] + 1;
3569 dim[1] = off[3] - off[1] + 1;
3582 if (raster == NULL) {
3583 rterror(
"rt_raster_from_two_rasters: Could not create output raster");
3601 &(_offset[0][0]), &(_offset[0][1]),
3604 rterror(
"rt_raster_from_two_rasters: Could not get offsets of the FIRST raster relative to the output raster");
3608 _offset[0][0] *= -1;
3609 _offset[0][1] *= -1;
3614 &(_offset[1][0]), &(_offset[1][1]),
3617 rterror(
"rt_raster_from_two_rasters: Could not get offsets of the SECOND raster relative to the output raster");
3621 _offset[1][0] *= -1;
3622 _offset[1][1] *= -1;
3626 double off[4] = {0};
3630 (_offset[1][2] < 0 || _offset[1][0] > (_dim[0][0] - 1)) ||
3631 (_offset[1][3] < 0 || _offset[1][1] > (_dim[0][1] - 1))
3633 RASTER_DEBUG(3,
"The two rasters provided have no intersection. Returning no band raster");
3636 if (raster == NULL) {
3637 rterror(
"rt_raster_from_two_rasters: Could not create output raster");
3644 if (NULL != offset) {
3645 for (i = 0; i < 4; i++)
3646 offset[i] = _offset[i / 2][i % 2];
3653 if (_offset[1][0] > 0)
3654 off[0] = _offset[1][0];
3655 if (_offset[1][1] > 0)
3656 off[1] = _offset[1][1];
3658 off[2] = _dim[0][0] - 1;
3659 if (_offset[1][2] < _dim[0][0])
3660 off[2] = _offset[1][2];
3661 off[3] = _dim[0][1] - 1;
3662 if (_offset[1][3] < _dim[0][1])
3663 off[3] = _offset[1][3];
3665 dim[0] = off[2] - off[0] + 1;
3666 dim[1] = off[3] - off[1] + 1;
3671 if (raster == NULL) {
3672 rterror(
"rt_raster_from_two_rasters: Could not create output raster");
3685 rterror(
"rt_raster_from_two_rasters: Could not get spatial coordinates of upper-left pixel of output raster");
3696 &(_offset[0][0]), &(_offset[0][1]),
3699 rterror(
"rt_raster_from_two_rasters: Could not get pixel coordinates to compute the offsets of the FIRST raster relative to the output raster");
3703 _offset[0][0] *= -1;
3704 _offset[0][1] *= -1;
3709 &(_offset[1][0]), &(_offset[1][1]),
3712 rterror(
"rt_raster_from_two_rasters: Could not get pixel coordinates to compute the offsets of the SECOND raster relative to the output raster");
3716 _offset[1][0] *= -1;
3717 _offset[1][1] *= -1;
3721 rterror(
"rt_raster_from_two_rasters: Extent type ET_CUSTOM is not supported by this function");
3726 if (NULL != offset) {
3727 for (i = 0; i < 4; i++)
3728 offset[i] = _offset[i / 2][i % 2];
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): ...
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
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 rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
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_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster's geotransform using 6-element array.
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
#define RASTER_DEBUGF(level, msg,...)
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
#define RASTER_DEBUG(level, msg)
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.