PostGIS  3.3.9dev-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 933 of file mvt.c.

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

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: