2044 uint32_t worldTileSize;
2045 double tileGeoSizeX, tileGeoSizeY;
2046 double boundsWidth, boundsHeight;
2047 double x1, y1, x2, y2;
2057 POSTGIS_DEBUG(2,
"ST_TileEnvelope called");
2059 zoom = PG_GETARG_INT32(0);
2060 x = PG_GETARG_INT32(1);
2061 y = PG_GETARG_INT32(2);
2063 bounds = PG_GETARG_GSERIALIZED_P(3);
2072 elog(ERROR,
"%s: Unable to compute bbox", __func__);
2076 boundsWidth = bbox.
xmax - bbox.
xmin;
2077 boundsHeight = bbox.
ymax - bbox.
ymin;
2078 if (boundsWidth <= 0 || boundsHeight <= 0)
2079 elog(ERROR,
"%s: Geometric bounds are too small", __func__);
2081 if (zoom < 0 || zoom >= 32)
2082 elog(ERROR,
"%s: Invalid tile zoom value, %d", __func__, zoom);
2084 zoomu = (uint32_t)zoom;
2085 worldTileSize = 0x01u << (zoomu > 31 ? 31 : zoomu);
2087 if (
x < 0 || (uint32_t)
x >= worldTileSize)
2088 elog(ERROR,
"%s: Invalid tile x value, %d", __func__,
x);
2089 if (
y < 0 || (uint32_t)
y >= worldTileSize)
2090 elog(ERROR,
"%s: Invalid tile y value, %d", __func__,
y);
2092 tileGeoSizeX = boundsWidth / worldTileSize;
2093 tileGeoSizeY = boundsHeight / worldTileSize;
2094 x1 = bbox.
xmin + tileGeoSizeX * (
x);
2095 x2 = bbox.
xmin + tileGeoSizeX * (
x+1);
2096 y1 = bbox.
ymax - tileGeoSizeY * (
y+1);
2097 y2 = bbox.
ymax - tileGeoSizeY * (
y);
2103 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...
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)