965 uint32_t max_run = 1;
972 double _igt[6] = {0};
985 GEOSGeometry *sgeom = NULL;
986 GEOSGeometry *ngeom = NULL;
994 else if (tolerance > 1.)
998 while (dbl_run < 10) {
1006 for (i = 0; i < 2; i++) {
1007 if (
FLT_EQ(scale[i], 0.0))
1009 rterror(
"rt_raster_compute_skewed_raster: Scale cannot be zero");
1014 _gt[1] = fabs(scale[i] * tolerance);
1016 _gt[5] = fabs(scale[i] * tolerance);
1022 if ((skew == NULL) || (
FLT_EQ(skew[0], 0.0) &&
FLT_EQ(skew[1], 0.0)))
1025 (int) fmax((fabs(extent.
MaxX - extent.
MinX) + (fabs(scale[0]) / 2.)) / fabs(scale[0]), 1),
1026 (
int) fmax((fabs(extent.
MaxY - extent.
MinY) + (fabs(scale[1]) / 2.)) / fabs(scale[1]), 1)
1031 rterror(
"rt_raster_compute_skewed_raster: Could not create output raster");
1050 _gt[2] = skew[0] * tolerance;
1052 _gt[4] = skew[1] * tolerance;
1054 RASTER_DEBUGF(4,
"Initial geotransform: %f, %f, %f, %f, %f, %f",
1055 _gt[0], _gt[1], _gt[2], _gt[3], _gt[4], _gt[5]
1061 rterror(
"rt_raster_compute_skewed_raster: Out of memory allocating extent raster");
1067 if (!GDALInvGeoTransform(_gt, _igt)) {
1068 rterror(
"rt_raster_compute_skewed_raster: Could not compute inverse geotransform matrix");
1072 RASTER_DEBUGF(4,
"Inverse geotransform: %f, %f, %f, %f, %f, %f",
1073 _igt[0], _igt[1], _igt[2], _igt[3], _igt[4], _igt[5]
1077 for (i = 0; i < 2; i++) {
1081 RASTER_DEBUGF(3,
"Shifting along %s axis", i < 1 ?
"X" :
"Y");
1086 if (run > max_run) {
1087 rterror(
"rt_raster_compute_skewed_raster: Could not compute skewed extent due to check preventing infinite loop");
1096 for (j = 0; j < 4; j++) {
1100 _xy[0] = extent.
MinX;
1101 _xy[1] = extent.
MaxY;
1105 _xy[0] = extent.
MinX;
1106 _xy[1] = extent.
MinY;
1110 _xy[0] = extent.
MaxX;
1111 _xy[1] = extent.
MinY;
1115 _xy[0] = extent.
MaxX;
1116 _xy[1] = extent.
MaxY;
1127 rterror(
"rt_raster_compute_skewed_raster: Could not compute raster pixel for spatial coordinates");
1132 RASTER_DEBUGF(4,
"Point %d at cell %d x %d", j, (
int) _r[0], (
int) _r[1]);
1135 if ((
int) _r[i] < 0) {
1139 if (_dlastpos != j) {
1140 _dlast = (int) _r[i];
1143 else if ((
int) _r[i] < _dlast) {
1144 RASTER_DEBUG(4,
"Point going in wrong direction. Reversing direction");
1160 x = _d[i] * fabs(_r[i]);
1162 y = _d[i] * fabs(_r[i]);
1171 rterror(
"rt_raster_compute_skewed_raster: Could not compute spatial coordinates for raster pixel");
1182 RASTER_DEBUGF(4,
"Shifted geotransform: %f, %f, %f, %f, %f, %f",
1183 _gt[0], _gt[1], _gt[2], _gt[3], _gt[4], _gt[5]
1187 if (!GDALInvGeoTransform(_gt, _igt)) {
1188 rterror(
"rt_raster_compute_skewed_raster: Could not compute inverse geotransform matrix");
1192 RASTER_DEBUGF(4,
"Inverse geotransform: %f, %f, %f, %f, %f, %f",
1193 _igt[0], _igt[1], _igt[2], _igt[3], _igt[4], _igt[5]
1210 rterror(
"rt_raster_compute_skewed_raster: Could not compute raster pixel for spatial coordinates");
1215 RASTER_DEBUGF(4,
"geopoint %f x %f at cell %d x %d", extent.
MaxX, extent.
MinY, (
int) _r[0], (
int) _r[1]);
1226 if (npoly == NULL) {
1227 rterror(
"rt_raster_compute_skewed_raster: Could not build extent's geometry for covers test");
1241 rterror(
"rt_raster_compute_skewed_raster: Could not build skewed extent's geometry for covers test");
1242 GEOSGeom_destroy(ngeom);
1250 covers = GEOSRelatePattern(sgeom, ngeom,
"******FF*");
1251 GEOSGeom_destroy(sgeom);
1254 rterror(
"rt_raster_compute_skewed_raster: Could not run covers test");
1255 GEOSGeom_destroy(ngeom);
1270 raster->width = (int) ((((
double)
raster->width) * fabs(_gt[1]) + fabs(scale[0] / 2.)) / fabs(scale[0]));
1271 raster->height = (int) ((((
double)
raster->height) * fabs(_gt[5]) + fabs(scale[1] / 2.)) / fabs(scale[1]));
1272 _gt[1] = fabs(scale[0]);
1273 _gt[5] = -1 * fabs(scale[1]);
1279 for (i = 0; i < 2; i++) {
1289 rterror(
"rt_raster_compute_skewed_raster: Could not build skewed extent's geometry for minimizing dimensions");
1290 GEOSGeom_destroy(ngeom);
1298 covers = GEOSRelatePattern(sgeom, ngeom,
"******FF*");
1299 GEOSGeom_destroy(sgeom);
1302 rterror(
"rt_raster_compute_skewed_raster: Could not run covers test for minimizing dimensions");
1303 GEOSGeom_destroy(ngeom);
1316 GEOSGeom_destroy(ngeom);
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
void lwgeom_geos_error(const char *fmt,...)
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
void lwpoly_free(LWPOLY *poly)
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
#define RASTER_DEBUG(level, msg)
#define RASTER_DEBUGF(level, msg,...)
void rtinfo(const char *fmt,...)
rt_errorstate rt_raster_get_convex_hull(rt_raster raster, LWGEOM **hull)
Get raster's convex hull.
LWPOLY * rt_util_envelope_to_lwpoly(rt_envelope ext)
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Datum covers(PG_FUNCTION_ARGS)
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.
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.