PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ 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 1140 of file mvt.c.

1142 {
1143  AFFINE affine = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1144  gridspec grid = {0, 0, 0, 0, 1, 1, 0, 0};
1145  double width = gbox->xmax - gbox->xmin;
1146  double height = gbox->ymax - gbox->ymin;
1147  double resx, resy, res, fx, fy;
1148  const uint8_t basic_type = lwgeom_get_basic_type(lwgeom);
1149  int preserve_collapsed = LW_FALSE;
1150  POSTGIS_DEBUG(2, "mvt_geom called");
1151 
1152  /* Simplify it as soon as possible */
1153  lwgeom = lwgeom_to_basic_type(lwgeom, basic_type);
1154 
1155  /* Short circuit out on EMPTY */
1156  if (lwgeom_is_empty(lwgeom))
1157  return NULL;
1158 
1159  resx = width / extent;
1160  resy = height / extent;
1161  res = (resx < resy ? resx : resy)/2;
1162  fx = extent / width;
1163  fy = -(extent / height);
1164 
1165  /* Remove all non-essential points (under the output resolution) */
1167  lwgeom_simplify_in_place(lwgeom, res, preserve_collapsed);
1168 
1169  /* If geometry has disappeared, you're done */
1170  if (lwgeom_is_empty(lwgeom))
1171  return NULL;
1172 
1173  /* transform to tile coordinate space */
1174  affine.afac = fx;
1175  affine.efac = fy;
1176  affine.ifac = 1;
1177  affine.xoff = -gbox->xmin * fx;
1178  affine.yoff = -gbox->ymax * fy;
1179  lwgeom_affine(lwgeom, &affine);
1180 
1181  /* Snap to integer precision, removing duplicate points */
1182  lwgeom_grid_in_place(lwgeom, &grid);
1183 
1184  if (!lwgeom || lwgeom_is_empty(lwgeom))
1185  return NULL;
1186 
1187  lwgeom = mvt_clip_and_validate(lwgeom, basic_type, extent, buffer, clip_geom);
1188  if (!lwgeom || lwgeom_is_empty(lwgeom))
1189  return NULL;
1190 
1191  return lwgeom;
1192 }
#define LW_FALSE
Definition: liblwgeom.h:108
int lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1714
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:1974
void lwgeom_grid_in_place(LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:2143
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:203
static LWGEOM * lwgeom_to_basic_type(LWGEOM *geom, uint8_t original_type)
In place process a collection to find a concrete geometry object and expose that as the actual object...
Definition: mvt.c:787
static uint8_t lwgeom_get_basic_type(LWGEOM *geom)
Definition: mvt.c:747
static LWGEOM * mvt_clip_and_validate(LWGEOM *lwgeom, uint8_t basic_type, uint32_t extent, uint32_t buffer, bool clip_geom)
Definition: mvt.c:1095
tuple res
Definition: window.py:79
Datum buffer(PG_FUNCTION_ARGS)
double ifac
Definition: liblwgeom.h:346
double xoff
Definition: liblwgeom.h:346
double afac
Definition: liblwgeom.h:346
double efac
Definition: liblwgeom.h:346
double yoff
Definition: liblwgeom.h:346
double ymax
Definition: liblwgeom.h:371
double xmax
Definition: liblwgeom.h:369
double ymin
Definition: liblwgeom.h:370
double xmin
Definition: liblwgeom.h:368
Snap-to-grid.
Definition: liblwgeom.h:1366

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(), window::res, 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: