2102 uint32_t worldTileSize;
2103 double tileGeoSizeX, tileGeoSizeY;
2104 double boundsWidth, boundsHeight;
2105 double x1, y1, x2, y2;
2116 POSTGIS_DEBUG(2,
"ST_TileEnvelope called");
2118 zoom = PG_GETARG_INT32(0);
2119 x = PG_GETARG_INT32(1);
2120 y = PG_GETARG_INT32(2);
2122 bounds = PG_GETARG_GSERIALIZED_P(3);
2131 elog(ERROR,
"%s: Unable to compute bbox", __func__);
2136 margin = PG_NARGS() < 4 ? 0 : PG_GETARG_FLOAT8(4);
2139 elog(ERROR,
"%s: Margin must not be less than -50%%, margin=%f", __func__, margin);
2141 boundsWidth = bbox.
xmax - bbox.
xmin;
2142 boundsHeight = bbox.
ymax - bbox.
ymin;
2143 if (boundsWidth <= 0 || boundsHeight <= 0)
2144 elog(ERROR,
"%s: Geometric bounds are too small", __func__);
2146 if (zoom < 0 || zoom >= 32)
2147 elog(ERROR,
"%s: Invalid tile zoom value, %d", __func__, zoom);
2149 zoomu = (uint32_t)zoom;
2150 worldTileSize = 0x01u << (zoomu > 31 ? 31 : zoomu);
2152 if (
x < 0 || (uint32_t)
x >= worldTileSize)
2153 elog(ERROR,
"%s: Invalid tile x value, %d", __func__,
x);
2154 if (
y < 0 || (uint32_t)
y >= worldTileSize)
2155 elog(ERROR,
"%s: Invalid tile y value, %d", __func__,
y);
2157 tileGeoSizeX = boundsWidth / worldTileSize;
2158 tileGeoSizeY = boundsHeight / worldTileSize;
2165 if ((1 + margin * 2) > worldTileSize)
2172 x1 = bbox.
xmin + tileGeoSizeX * (
x - margin);
2173 x2 = bbox.
xmin + tileGeoSizeX * (
x + 1 + margin);
2176 y1 = bbox.
ymax - tileGeoSizeY * (
y + 1 + margin);
2177 y2 = bbox.
ymax - tileGeoSizeY * (
y - margin);
2180 if (y1 < bbox.
ymin) y1 = bbox.
ymin;
2181 if (y2 > bbox.
ymax) y2 = bbox.
ymax;
2182 if (x1 < bbox.
xmin) x1 = bbox.
xmin;
2183 if (x2 > bbox.
xmax) x2 = bbox.
xmax;
2189 srid, x1, y1, x2, y2))));
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
LWPOLY * lwpoly_construct_envelope(int32_t srid, double x1, double y1, double x2, double y2)
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...