PostGIS  2.5.7dev-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 910 of file mvt.c.

911 {
912  if (basic_type != POLYGONTYPE)
913  {
914  return mvt_unsafe_clip_by_box(lwgeom, clip_gbox);
915  }
916 
917  if (lwgeom->type != MULTIPOLYGONTYPE || ((LWMPOLY *)lwgeom)->ngeoms == 1)
918  {
919  return mvt_safe_clip_polygon_by_box(lwgeom, clip_gbox);
920  }
921  else
922  {
923  GBOX geom_box;
924  uint32_t i;
925  LWCOLLECTION *lwmg;
926  LWCOLLECTION *res;
927 
928  gbox_init(&geom_box);
929  FLAGS_SET_GEODETIC(geom_box.flags, 0);
930  lwgeom_calculate_gbox(lwgeom, &geom_box);
931 
932  lwmg = ((LWCOLLECTION *)lwgeom);
934  MULTIPOLYGONTYPE, lwgeom->srid, FLAGS_GET_Z(lwgeom->flags), FLAGS_GET_M(lwgeom->flags));
935  for (i = 0; i < lwmg->ngeoms; i++)
936  {
937  LWGEOM *clipped = mvt_safe_clip_polygon_by_box(lwcollection_getsubgeom(lwmg, i), clip_gbox);
938  if (clipped)
939  {
940  clipped = lwgeom_to_basic_type(clipped, POLYGONTYPE);
941  if (!lwgeom_is_empty(clipped) &&
942  (clipped->type == POLYGONTYPE || clipped->type == MULTIPOLYGONTYPE))
943  {
944  if (!lwgeom_is_collection(clipped))
945  {
946  lwcollection_add_lwgeom(res, clipped);
947  }
948  else
949  {
950  uint32_t j;
951  for (j = 0; j < ((LWCOLLECTION *)clipped)->ngeoms; j++)
953  res, lwcollection_getsubgeom((LWCOLLECTION *)clipped, j));
954  }
955  }
956  }
957  }
958  return lwcollection_as_lwgeom(res);
959  }
960 }
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
Definition: g_box.c:47
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:300
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
LWGEOM * lwcollection_getsubgeom(LWCOLLECTION *col, int gnum)
Definition: lwcollection.c:113
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
int lwgeom_is_collection(const LWGEOM *lwgeom)
Determine whether a LWGEOM can contain sub-geometries or not.
Definition: lwgeom.c:1085
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition: lwgeom.c:1393
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:746
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:187
#define FLAGS_SET_GEODETIC(flags, value)
Definition: liblwgeom.h:149
static LWGEOM * mvt_unsafe_clip_by_box(LWGEOM *lwg_in, GBOX *clip_box)
Definition: mvt.c:796
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:831
static LWGEOM * lwgeom_to_basic_type(LWGEOM *geom, uint8 original_type)
In place process a collection to find a concrete geometry object and expose that as the actual object...
Definition: mvt.c:771
tuple res
Definition: window.py:78
uint8_t flags
Definition: liblwgeom.h:294
uint32_t ngeoms
Definition: liblwgeom.h:510
uint8_t type
Definition: liblwgeom.h:399
uint8_t flags
Definition: liblwgeom.h:494
int32_t srid
Definition: liblwgeom.h:496
unsigned int uint32_t
Definition: uthash.h:78

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: