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

◆ lwgeom_split_wrapx()

static LWGEOM * lwgeom_split_wrapx ( const LWGEOM geom_in,
double  cutx,
double  amount 
)
static

Definition at line 37 of file lwgeom_wrapx.c.

38{
39 LWGEOM *blade, *split;
40 POINTARRAY *bladepa;
41 POINT4D pt;
42 const GBOX *box_in;
43 AFFINE affine = {
44 1, 0, 0,
45 0, 1, 0,
46 0, 0, 1,
47 amount, 0, 0,
48 };
49
50 /* Extract box */
51 /* TODO: check if the bbox should be force-recomputed */
52 box_in = lwgeom_get_bbox(geom_in);
53 if ( ! box_in ) {
54 /* must be empty */
55 return lwgeom_clone_deep(geom_in);
56 }
57
58 LWDEBUGF(2, "BOX X range is %g..%g, cutx:%g, amount:%g", box_in->xmin, box_in->xmax, cutx, amount);
59
60 /* Check if geometry is fully on the side needing shift */
61 if ( ( amount < 0 && box_in->xmin >= cutx ) || ( amount > 0 && box_in->xmax <= cutx ) )
62 {
63 split = lwgeom_clone_deep(geom_in);
64 lwgeom_affine(split, &affine);
65 LWDEBUGG(2, split, "returning the translated geometry");
66 return split;
67 }
68
69 /* Check if geometry is fully on the side needing no shift */
70 if ( ( amount < 0 && box_in->xmax <= cutx ) || ( amount > 0 && box_in->xmin >= cutx ) )
71 {
72 split = lwgeom_clone_deep(geom_in);
73 LWDEBUGG(2, split, "returning the cloned geometry");
74 return split;
75 }
76
77 /* We need splitting here */
78
79 /* construct blade */
80 bladepa = ptarray_construct(0, 0, 2);
81 pt.x = cutx;
82 pt.y = box_in->ymin - 1;
83 ptarray_set_point4d(bladepa, 0, &pt);
84 pt.y = box_in->ymax + 1;
85 ptarray_set_point4d(bladepa, 1, &pt);
86 blade = lwline_as_lwgeom(lwline_construct(geom_in->srid, NULL, bladepa));
87
88 LWDEBUG(2, "splitting the geometry");
89
90 /* split by blade */
91 split = lwgeom_split(geom_in, blade);
92 lwgeom_free(blade);
93 if ( ! split ) {
94 lwerror("%s:%d - lwgeom_split_wrapx: %s", __FILE__, __LINE__, lwgeom_geos_errmsg);
95 return NULL;
96 }
97 LWDEBUGG(2, split, "split geometry");
98
99
100 /* iterate over components, translate if needed */
101 const LWCOLLECTION *col = lwgeom_as_lwcollection(split);
102 if ( ! col ) {
103 /* not split, this is unexpected */
104 lwnotice("WARNING: unexpected lack of split in lwgeom_split_wrapx");
105 return lwgeom_clone_deep(geom_in);
106 }
107 LWCOLLECTION *col_out = lwcollection_wrapx(col, cutx, amount);
108 lwgeom_free(split);
109
110 /* unary-union the result (homogenize too ?) */
112 LWDEBUGF(2, "col_out:%p, unaryunion_out:%p", col_out, out);
113 LWDEBUGG(2, out, "unary-unioned");
114
115 lwcollection_free(col_out);
116
117 return out;
118}
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
LWGEOM * lwgeom_unaryunion(const LWGEOM *geom1)
LWGEOM * lwgeom_split(const LWGEOM *lwgeom_in, const LWGEOM *blade_in)
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition lwgeom.c:261
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition lwline.c:42
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition lwgeom.c:367
void lwgeom_affine(LWGEOM *geom, const AFFINE *affine)
Definition lwgeom.c:2111
void lwcollection_free(LWCOLLECTION *col)
const GBOX * lwgeom_get_bbox(const LWGEOM *lwgeom)
Get a non-empty geometry bounding box, computing and caching it if not already there.
Definition lwgeom.c:771
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
Definition lwgeom_api.c:369
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition lwgeom.c:337
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition ptarray.c:51
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition lwgeom.c:557
#define LWDEBUG(level, msg)
Definition lwgeom_log.h:101
#define LWDEBUGF(level, msg,...)
Definition lwgeom_log.h:106
void lwnotice(const char *fmt,...) __attribute__((format(printf
Write a notice out to the notice handler.
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
#define LWDEBUGG(level, geom, msg)
Definition lwgeom_log.h:111
static LWCOLLECTION * lwcollection_wrapx(const LWCOLLECTION *lwcoll_in, double cutx, double amount)
double ymax
Definition liblwgeom.h:357
double xmax
Definition liblwgeom.h:355
double ymin
Definition liblwgeom.h:356
double xmin
Definition liblwgeom.h:354
int32_t srid
Definition liblwgeom.h:460
double x
Definition liblwgeom.h:414
double y
Definition liblwgeom.h:414

References lwcollection_as_lwgeom(), lwcollection_free(), lwcollection_wrapx(), LWDEBUG, LWDEBUGF, LWDEBUGG, lwerror(), lwgeom_affine(), lwgeom_as_lwcollection(), lwgeom_clone_deep(), lwgeom_free(), lwgeom_geos_errmsg, lwgeom_get_bbox(), lwgeom_split(), lwgeom_unaryunion(), lwline_as_lwgeom(), lwline_construct(), lwnotice(), ptarray_construct(), ptarray_set_point4d(), LWGEOM::srid, POINT4D::x, GBOX::xmax, GBOX::xmin, POINT4D::y, GBOX::ymax, and GBOX::ymin.

Referenced by lwgeom_wrapx().

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