2096 uint32_t worldTileSize;
2097 double tileGeoSizeX, tileGeoSizeY;
2098 double boundsWidth, boundsHeight;
2099 double x1, y1, x2, y2;
2110 POSTGIS_DEBUG(2,
"ST_TileEnvelope called");
2112 zoom = PG_GETARG_INT32(0);
2113 x = PG_GETARG_INT32(1);
2114 y = PG_GETARG_INT32(2);
2116 bounds = PG_GETARG_GSERIALIZED_P(3);
2125 elog(ERROR,
"%s: Unable to compute bbox", __func__);
2130 margin = PG_NARGS() < 4 ? 0 : PG_GETARG_FLOAT8(4);
2133 elog(ERROR,
"%s: Margin must not be less than -50%%, margin=%f", __func__, margin);
2135 boundsWidth = bbox.
xmax - bbox.
xmin;
2136 boundsHeight = bbox.
ymax - bbox.
ymin;
2137 if (boundsWidth <= 0 || boundsHeight <= 0)
2138 elog(ERROR,
"%s: Geometric bounds are too small", __func__);
2140 if (zoom < 0 || zoom >= 32)
2141 elog(ERROR,
"%s: Invalid tile zoom value, %d", __func__, zoom);
2143 zoomu = (uint32_t)zoom;
2144 worldTileSize = 0x01u << (zoomu > 31 ? 31 : zoomu);
2146 if (
x < 0 || (uint32_t)
x >= worldTileSize)
2147 elog(ERROR,
"%s: Invalid tile x value, %d", __func__,
x);
2148 if (
y < 0 || (uint32_t)
y >= worldTileSize)
2149 elog(ERROR,
"%s: Invalid tile y value, %d", __func__,
y);
2151 tileGeoSizeX = boundsWidth / worldTileSize;
2152 tileGeoSizeY = boundsHeight / worldTileSize;
2159 if ((1 + margin * 2) > worldTileSize)
2166 x1 = bbox.
xmin + tileGeoSizeX * (
x - margin);
2167 x2 = bbox.
xmin + tileGeoSizeX * (
x + 1 + margin);
2170 y1 = bbox.
ymax - tileGeoSizeY * (
y + 1 + margin);
2171 y2 = bbox.
ymax - tileGeoSizeY * (
y - margin);
2174 if (y1 < bbox.
ymin) y1 = bbox.
ymin;
2175 if (y2 > bbox.
ymax) y2 = bbox.
ymax;
2176 if (x1 < bbox.
xmin) x1 = bbox.
xmin;
2177 if (x2 > bbox.
xmax) x2 = bbox.
xmax;
2183 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...