PostGIS  3.2.2dev-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 906 of file mvt.c.

908 {
909  AFFINE affine = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
910  gridspec grid = {0, 0, 0, 0, 1, 1, 0, 0};
911  double width = gbox->xmax - gbox->xmin;
912  double height = gbox->ymax - gbox->ymin;
913  double fx, fy;
914  const uint8_t basic_type = lwgeom_get_basic_type(lwgeom);
915  int preserve_collapsed = LW_FALSE;
916  POSTGIS_DEBUG(2, "mvt_geom called");
917 
918  /* Simplify it as soon as possible */
919  lwgeom = lwgeom_to_basic_type(lwgeom, basic_type);
920 
921  /* Short circuit out on EMPTY */
922  if (lwgeom_is_empty(lwgeom))
923  return NULL;
924 
925  fx = extent / width;
926  fy = -(extent / height);
927 
928  /* If geometry has disappeared, you're done */
929  if (lwgeom_is_empty(lwgeom))
930  return NULL;
931 
932  /* transform to tile coordinate space */
933  affine.afac = fx;
934  affine.efac = fy;
935  affine.ifac = 1;
936  affine.xoff = -gbox->xmin * fx;
937  affine.yoff = -gbox->ymax * fy;
938  lwgeom_affine(lwgeom, &affine);
939 
940  /* Snap to integer precision, removing duplicate points */
941  lwgeom_grid_in_place(lwgeom, &grid);
942 
943  /* Remove points on straight lines */
944  lwgeom_simplify_in_place(lwgeom, 0, preserve_collapsed);
945 
946  /* Remove duplicates in multipoints */
947  if (lwgeom->type == MULTIPOINTTYPE)
949 
950  if (!lwgeom || lwgeom_is_empty(lwgeom))
951  return NULL;
952 
953  lwgeom = mvt_clip_and_validate(lwgeom, basic_type, extent, buffer, clip_geom);
954  if (!lwgeom || lwgeom_is_empty(lwgeom))
955  return NULL;
956 
957  return lwgeom;
958 }
#define LW_FALSE
Definition: liblwgeom.h:108
int lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1743
#define MULTIPOINTTYPE
Definition: liblwgeom.h:119
int lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance)
Definition: lwgeom.c:1587
void lwgeom_affine(LWGEOM *geom, const AFFINE *affine)
Definition: lwgeom.c:2003
void lwgeom_grid_in_place(LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:2172
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:789
static uint8_t lwgeom_get_basic_type(LWGEOM *geom)
Definition: mvt.c:749
static LWGEOM * mvt_clip_and_validate(LWGEOM *lwgeom, uint8_t basic_type, uint32_t extent, uint32_t buffer, bool clip_geom)
Definition: mvt.c:870
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
uint8_t type
Definition: liblwgeom.h:476
Snap-to-grid.
Definition: liblwgeom.h:1382

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(), MULTIPOINTTYPE, mvt_clip_and_validate(), LWGEOM::type, 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: