PostGIS  3.1.6dev-r@@SVN_REVISION@@

◆ mvt_iterate_clip_by_box_geos()

static LWGEOM* mvt_iterate_clip_by_box_geos ( LWGEOM lwgeom,
GBOX clip_gbox,
uint8_t  basic_type 
)
static

Clips the geometry using GEOSIntersection in a "safe way", cleaning the input if necessary and clipping MULTIPOLYGONs separately to reduce the impact of using invalid input in GEOS Might return NULL.

Definition at line 926 of file mvt.c.

927 {
928  if (basic_type != POLYGONTYPE)
929  {
930  return mvt_unsafe_clip_by_box(lwgeom, clip_gbox);
931  }
932 
933  if (lwgeom->type != MULTIPOLYGONTYPE || ((LWMPOLY *)lwgeom)->ngeoms == 1)
934  {
935  return mvt_safe_clip_polygon_by_box(lwgeom, clip_gbox);
936  }
937  else
938  {
939  GBOX geom_box;
940  uint32_t i;
941  LWCOLLECTION *lwmg;
942  LWCOLLECTION *res;
943 
944  gbox_init(&geom_box);
945  FLAGS_SET_GEODETIC(geom_box.flags, 0);
946  lwgeom_calculate_gbox(lwgeom, &geom_box);
947 
948  lwmg = ((LWCOLLECTION *)lwgeom);
950  MULTIPOLYGONTYPE, lwgeom->srid, FLAGS_GET_Z(lwgeom->flags), FLAGS_GET_M(lwgeom->flags));
951  for (i = 0; i < lwmg->ngeoms; i++)
952  {
953  LWGEOM *clipped = mvt_safe_clip_polygon_by_box(lwcollection_getsubgeom(lwmg, i), clip_gbox);
954  if (clipped)
955  {
956  clipped = lwgeom_to_basic_type(clipped, POLYGONTYPE);
957  if (!lwgeom_is_empty(clipped) &&
958  (clipped->type == POLYGONTYPE || clipped->type == MULTIPOLYGONTYPE))
959  {
960  if (!lwgeom_is_collection(clipped))
961  {
962  lwcollection_add_lwgeom(res, clipped);
963  }
964  else
965  {
966  uint32_t j;
967  for (j = 0; j < ((LWCOLLECTION *)clipped)->ngeoms; j++)
969  res, lwcollection_getsubgeom((LWCOLLECTION *)clipped, j));
970  }
971  }
972  }
973  }
974  return lwcollection_as_lwgeom(res);
975  }
976 }
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: gbox.c:40
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:292
LWGEOM * lwcollection_getsubgeom(LWCOLLECTION *col, int gnum)
Definition: lwcollection.c:114
#define FLAGS_GET_Z(flags)
Definition: liblwgeom.h:179
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:121
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1080
#define POLYGONTYPE
Definition: liblwgeom.h:118
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
Definition: lwcollection.c:92
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:180
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
Definition: lwgeom.c:738
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:188
#define FLAGS_SET_GEODETIC(flags, value)
Definition: liblwgeom.h:189
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 * mvt_unsafe_clip_by_box(LWGEOM *lwg_in, GBOX *clip_box)
Definition: mvt.c:812
static LWGEOM * mvt_safe_clip_polygon_by_box(LWGEOM *lwg_in, GBOX *clip_box)
Clips an input geometry using GEOSIntersection It used to try to use GEOSClipByRect (as mvt_unsafe_cl...
Definition: mvt.c:847
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:787
tuple res
Definition: window.py:79
lwflags_t flags
Definition: liblwgeom.h:367
uint32_t ngeoms
Definition: liblwgeom.h:594
uint8_t type
Definition: liblwgeom.h:476
lwflags_t flags
Definition: liblwgeom.h:577
int32_t srid
Definition: liblwgeom.h:576

References GBOX::flags, LWGEOM::flags, FLAGS_GET_M, FLAGS_GET_Z, FLAGS_SET_GEODETIC, gbox_init(), lwcollection_add_lwgeom(), lwcollection_as_lwgeom(), lwcollection_construct_empty(), lwcollection_getsubgeom(), lwgeom_calculate_gbox(), lwgeom_is_collection(), lwgeom_is_empty(), lwgeom_to_basic_type(), MULTIPOLYGONTYPE, mvt_safe_clip_polygon_by_box(), mvt_unsafe_clip_by_box(), LWCOLLECTION::ngeoms, POLYGONTYPE, window::res, LWGEOM::srid, and LWGEOM::type.

Referenced by mvt_clip_and_validate_geos().

Here is the call graph for this function:
Here is the caller graph for this function: