PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ lwgeom_clip_by_rect()

LWGEOM* lwgeom_clip_by_rect ( const LWGEOM geom1,
double  x0,
double  y0,
double  x1,
double  y1 

Definition at line 883 of file liblwgeom/lwgeom_geos.c.

References COLLECTIONTYPE, LWGEOM::flags, FLAGS_GET_Z, dumpnode::geom, geos_clean(), geos_clean_and_fail(), get_result_srid(), input_lwgeom_to_geos(), LW_TRUE, lwcollection_as_lwgeom(), lwcollection_extract(), lwfree(), lwgeom_as_lwcollection(), lwgeom_clone_deep(), lwgeom_dimension(), lwgeom_free(), lwgeom_geos_error(), lwgeom_intersection(), lwgeom_is_empty(), lwgeom_simplify_in_place(), lwnotice(), lwpoly_construct_envelope(), output_geos_as_lwgeom(), LWGEOM::srid, SRID_INVALID, and LWGEOM::type.

Referenced by lwgeom_subdivide_recursive(), mvt_geom(), ST_ClipByBox2d(), and test_lwgeom_clip_by_rect().

884 {
885  LWGEOM *result;
886  LWGEOM *tmp;
887  LWGEOM *envelope = (LWGEOM*)lwpoly_construct_envelope(geom1->srid, x1, y1, x2, y2);
889  result = lwgeom_intersection(geom1, envelope);
890  lwgeom_free(envelope);
892  if (!result) return NULL;
894  /* clipping should not produce lower dimension objects */
895  if (
896  /* input has exact dimensionality, isn't a generic collection */
897  geom1->type != COLLECTIONTYPE &&
898  /* output may have different things inside */
899  result->type == COLLECTIONTYPE)
900  {
902  lwfree(result);
903  result = tmp;
904  if (!result) return NULL;
905  }
907  /* clean up stray points on geometry boundary */
908  lwgeom_simplify_in_place(result, 0.0, LW_TRUE);
910  return result;
912 #if 0 /* POSTGIS_GEOS_VERSION >= 35, enable only after bugs in geos are fixed */
913  int32_t srid = get_result_srid(geom, NULL, __func__);
914  uint8_t is3d = FLAGS_GET_Z(geom->flags);
915  GEOSGeometry *g1, *g3;
917  if (srid == SRID_INVALID) return NULL;
919  /* A.Intersection(Empty) == Empty */
920  if (lwgeom_is_empty(geom)) return lwgeom_clone_deep(geom);
922  initGEOS(lwnotice, lwgeom_geos_error);
924  if (!input_lwgeom_to_geos(&g1, geom, __func__)) return NULL;
926  g3 = GEOSClipByRect(g1, x1, y1, x2, y2);
928  if (!g3) return geos_clean_and_fail(g1, NULL, NULL, __func__);
930  if (!output_geos_as_lwgeom(&g3, &result, srid, is3d, __func__))
931  return geos_clean_and_fail(g1, NULL, g3, __func__);
933  geos_clean(g1, NULL, g3);
935  return result;
936 #endif /* POSTGIS_GEOS_VERSION >= 35 */
937 }
LWCOLLECTION * lwcollection_extract(LWCOLLECTION *col, int type)
Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of ...
Definition: lwcollection.c:386
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
void lwfree(void *mem)
Definition: lwutil.c:244
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
static LWGEOM * geos_clean_and_fail(GEOSGeometry *g1, GEOSGeometry *g2, GEOSGeometry *g3, const char *funcname)
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:520
int32_t srid
Definition: liblwgeom.h:401
LWGEOM * lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2)
static uint8_t output_geos_as_lwgeom(GEOSGeometry **g, LWGEOM **geom, const int32_t srid, const uint8_t is3d, const char *funcname)
void lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1748
LWPOLY * lwpoly_construct_envelope(int srid, double x1, double y1, double x2, double y2)
Definition: lwpoly.c:98
void lwgeom_geos_error(const char *fmt,...)
static void geos_clean(GEOSGeometry *g1, GEOSGeometry *g2, GEOSGeometry *g3)
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
Definition: liblwgeom.h:191
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
static uint8_t input_lwgeom_to_geos(GEOSGeometry **g, const LWGEOM *geom, const char *funcname)
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:224
int lwgeom_dimension(const LWGEOM *geom)
For an LWGEOM, returns 0 for points, 1 for lines, 2 for polygons, 3 for volume, and the max dimension...
Definition: lwgeom.c:1287
uint8_t type
Definition: liblwgeom.h:398
static int32_t get_result_srid(const LWGEOM *geom1, const LWGEOM *geom2, const char *funcname)
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
unsigned char uint8_t
Definition: uthash.h:79
Definition: liblwgeom.h:90
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:300
Here is the call graph for this function:
Here is the caller graph for this function: