PostGIS  2.5.7dev-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 1081 of file mvt.c.

1083 {
1084  AFFINE affine = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1085  gridspec grid = {0, 0, 0, 0, 1, 1, 0, 0};
1086  double width = gbox->xmax - gbox->xmin;
1087  double height = gbox->ymax - gbox->ymin;
1088  double resx, resy, res, fx, fy;
1089  const uint8_t basic_type = lwgeom_get_basic_type(lwgeom);
1090  int preserve_collapsed = LW_FALSE;
1091  POSTGIS_DEBUG(2, "mvt_geom called");
1092 
1093  /* Simplify it as soon as possible */
1094  lwgeom = lwgeom_to_basic_type(lwgeom, basic_type);
1095 
1096  /* Short circuit out on EMPTY */
1097  if (lwgeom_is_empty(lwgeom))
1098  return NULL;
1099 
1100  if (width == 0 || height == 0)
1101  elog(ERROR, "mvt_geom: bounds width or height cannot be 0");
1102 
1103  if (extent == 0)
1104  elog(ERROR, "mvt_geom: extent cannot be 0");
1105 
1106  resx = width / extent;
1107  resy = height / extent;
1108  res = (resx < resy ? resx : resy)/2;
1109  fx = extent / width;
1110  fy = -(extent / height);
1111 
1112  /* Remove all non-essential points (under the output resolution) */
1114  lwgeom_simplify_in_place(lwgeom, res, preserve_collapsed);
1115 
1116  /* If geometry has disappeared, you're done */
1117  if (lwgeom_is_empty(lwgeom))
1118  return NULL;
1119 
1120  /* transform to tile coordinate space */
1121  affine.afac = fx;
1122  affine.efac = fy;
1123  affine.ifac = 1;
1124  affine.xoff = -gbox->xmin * fx;
1125  affine.yoff = -gbox->ymax * fy;
1126  lwgeom_affine(lwgeom, &affine);
1127 
1128  /* snap to integer precision, removing duplicate points */
1129  lwgeom_grid_in_place(lwgeom, &grid);
1130 
1131  if (lwgeom == NULL || lwgeom_is_empty(lwgeom))
1132  return NULL;
1133 
1134  lwgeom = mvt_clip_and_validate_geos(lwgeom, basic_type, extent, buffer, clip_geom);
1135  if (lwgeom == NULL || lwgeom_is_empty(lwgeom))
1136  return NULL;
1137 
1138  return lwgeom;
1139 }
#define LW_FALSE
Definition: liblwgeom.h:77
void lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance)
Definition: lwgeom.c:1603
void lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1750
void lwgeom_affine(LWGEOM *geom, const AFFINE *affine)
Definition: lwgeom.c:1984
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwgeom.c:1393
void lwgeom_grid_in_place(LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:2152
static uint8 lwgeom_get_basic_type(LWGEOM *geom)
Definition: mvt.c:734
static LWGEOM * mvt_clip_and_validate_geos(LWGEOM *lwgeom, uint8_t basic_type, uint32_t extent, uint32_t buffer, bool clip_geom)
Definition: mvt.c:1040
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:771
tuple res
Definition: window.py:78
Datum buffer(PG_FUNCTION_ARGS)
double ifac
Definition: liblwgeom.h:273
double xoff
Definition: liblwgeom.h:273
double afac
Definition: liblwgeom.h:273
double efac
Definition: liblwgeom.h:273
double yoff
Definition: liblwgeom.h:273
double ymax
Definition: liblwgeom.h:298
double xmax
Definition: liblwgeom.h:296
double ymin
Definition: liblwgeom.h:297
double xmin
Definition: liblwgeom.h:295
Snap to grid.
unsigned char uint8_t
Definition: uthash.h:79

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