PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

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

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

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: