PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ mvt_geom()

LWGEOM * mvt_geom ( LWGEOM lwgeom,
const GBOX gbox,
uint32_t  extent,
uint32_t  buffer,
bool  clip_geom 
)

Transform a geometry into vector tile coordinate space.

Makes best effort to keep validity. Might collapse geometry into lower dimension.

NOTE: modifies in place if possible (not currently possible for polygons)

Definition at line 1176 of file mvt.c.

1178{
1179 AFFINE affine = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1180 gridspec grid = {0, 0, 0, 0, 1, 1, 0, 0};
1181 double width = gbox->xmax - gbox->xmin;
1182 double height = gbox->ymax - gbox->ymin;
1183 double resx, resy, res, fx, fy;
1184 const uint8_t basic_type = lwgeom_get_basic_type(lwgeom);
1185 int preserve_collapsed = LW_FALSE;
1186 POSTGIS_DEBUG(2, "mvt_geom called");
1187
1188 /* Simplify it as soon as possible */
1189 lwgeom = lwgeom_to_basic_type(lwgeom, basic_type);
1190
1191 /* Short circuit out on EMPTY */
1192 if (lwgeom_is_empty(lwgeom))
1193 return NULL;
1194
1195 resx = width / extent;
1196 resy = height / extent;
1197 res = (resx < resy ? resx : resy)/2;
1198 fx = extent / width;
1199 fy = -(extent / height);
1200
1201 /* Remove all non-essential points (under the output resolution) */
1203 lwgeom_simplify_in_place(lwgeom, res, preserve_collapsed);
1204
1205 /* If geometry has disappeared, you're done */
1206 if (lwgeom_is_empty(lwgeom))
1207 return NULL;
1208
1209 /* transform to tile coordinate space */
1210 affine.afac = fx;
1211 affine.efac = fy;
1212 affine.ifac = 1;
1213 affine.xoff = -gbox->xmin * fx;
1214 affine.yoff = -gbox->ymax * fy;
1215 lwgeom_affine(lwgeom, &affine);
1216
1217 /* Snap to integer precision, removing duplicate points */
1218 lwgeom_grid_in_place(lwgeom, &grid);
1219
1220 if (!lwgeom || lwgeom_is_empty(lwgeom))
1221 return NULL;
1222
1223 lwgeom = mvt_clip_and_validate(lwgeom, basic_type, extent, buffer, clip_geom);
1224 if (!lwgeom || lwgeom_is_empty(lwgeom))
1225 return NULL;
1226
1227 return lwgeom;
1228}
#define LW_FALSE
Definition liblwgeom.h:108
int lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed)
Definition lwgeom.c:1715
int lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance)
Definition lwgeom.c:1554
void lwgeom_affine(LWGEOM *geom, const AFFINE *affine)
Definition lwgeom.c:1975
void lwgeom_grid_in_place(LWGEOM *lwgeom, const gridspec *grid)
Definition lwgeom.c:2144
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:193
static LWGEOM * mvt_clip_and_validate(LWGEOM *lwgeom, uint8_t basic_type, uint32_t extent, uint32_t buffer, bool clip_geom)
Definition mvt.c:1131
static uint8 lwgeom_get_basic_type(LWGEOM *geom)
Definition mvt.c:783
static LWGEOM * lwgeom_to_basic_type(LWGEOM *geom, uint8 original_type)
In place process a collection to find a concrete geometry object and expose that as the actual object...
Definition mvt.c:823
tuple res
Definition window.py:79
Datum buffer(PG_FUNCTION_ARGS)
double ifac
Definition liblwgeom.h:318
double xoff
Definition liblwgeom.h:318
double afac
Definition liblwgeom.h:318
double efac
Definition liblwgeom.h:318
double yoff
Definition liblwgeom.h:318
double ymax
Definition liblwgeom.h:343
double xmax
Definition liblwgeom.h:341
double ymin
Definition liblwgeom.h:342
double xmin
Definition liblwgeom.h:340
Snap-to-grid.
Definition liblwgeom.h:1341

References AFFINE::afac, buffer(), AFFINE::efac, AFFINE::ifac, LW_FALSE, lwgeom_affine(), lwgeom_get_basic_type(), lwgeom_grid_in_place(), lwgeom_is_empty(), lwgeom_remove_repeated_points_in_place(), lwgeom_simplify_in_place(), lwgeom_to_basic_type(), mvt_clip_and_validate(), GBOX::xmax, GBOX::xmin, AFFINE::xoff, GBOX::ymax, GBOX::ymin, and AFFINE::yoff.

Referenced by ST_AsMVTGeom().

Here is the call graph for this function:
Here is the caller graph for this function: