PostGIS  3.4.0dev-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 932 of file mvt.c.

934 {
935  AFFINE affine = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
936  gridspec grid = {0, 0, 0, 0, 1, 1, 0, 0};
937  double width = gbox->xmax - gbox->xmin;
938  double height = gbox->ymax - gbox->ymin;
939  double fx, fy;
940  const uint8_t basic_type = lwgeom_get_basic_type(lwgeom);
941  int preserve_collapsed = LW_FALSE;
942  POSTGIS_DEBUG(2, "mvt_geom called");
943 
944  /* Simplify it as soon as possible */
945  lwgeom = lwgeom_to_basic_type(lwgeom, basic_type);
946 
947  /* Short circuit out on EMPTY */
948  if (lwgeom_is_empty(lwgeom))
949  return NULL;
950 
951  fx = extent / width;
952  fy = -(extent / height);
953 
954  /* If geometry has disappeared, you're done */
955  if (lwgeom_is_empty(lwgeom))
956  return NULL;
957 
958  /* transform to tile coordinate space */
959  affine.afac = fx;
960  affine.efac = fy;
961  affine.ifac = 1;
962  affine.xoff = -gbox->xmin * fx;
963  affine.yoff = -gbox->ymax * fy;
964  lwgeom_affine(lwgeom, &affine);
965 
966  /* Snap to integer precision, removing duplicate points */
967  lwgeom_grid_in_place(lwgeom, &grid);
968 
969  /* Remove points on straight lines */
970  lwgeom_simplify_in_place(lwgeom, 0, preserve_collapsed);
971 
972  /* Remove duplicates in multipoints */
973  if (lwgeom->type == MULTIPOINTTYPE)
975 
976  if (!lwgeom || lwgeom_is_empty(lwgeom))
977  return NULL;
978 
979  lwgeom = mvt_clip_and_validate(lwgeom, basic_type, extent, buffer, clip_geom);
980  if (!lwgeom || lwgeom_is_empty(lwgeom))
981  return NULL;
982 
983  return lwgeom;
984 }
#define LW_FALSE
Definition: liblwgeom.h:94
int lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1737
#define MULTIPOINTTYPE
Definition: liblwgeom.h:105
int lwgeom_remove_repeated_points_in_place(LWGEOM *in, double tolerance)
Definition: lwgeom.c:1594
void lwgeom_affine(LWGEOM *geom, const AFFINE *affine)
Definition: lwgeom.c:1997
void lwgeom_grid_in_place(LWGEOM *lwgeom, const gridspec *grid)
Definition: lwgeom.c:2166
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:815
static uint8_t lwgeom_get_basic_type(LWGEOM *geom)
Definition: mvt.c:775
static LWGEOM * mvt_clip_and_validate(LWGEOM *lwgeom, uint8_t basic_type, uint32_t extent, uint32_t buffer, bool clip_geom)
Definition: mvt.c:896
Datum buffer(PG_FUNCTION_ARGS)
double ifac
Definition: liblwgeom.h:332
double xoff
Definition: liblwgeom.h:332
double afac
Definition: liblwgeom.h:332
double efac
Definition: liblwgeom.h:332
double yoff
Definition: liblwgeom.h:332
double ymax
Definition: liblwgeom.h:357
double xmax
Definition: liblwgeom.h:355
double ymin
Definition: liblwgeom.h:356
double xmin
Definition: liblwgeom.h:354
uint8_t type
Definition: liblwgeom.h:462
Snap-to-grid.
Definition: liblwgeom.h:1375

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: