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

◆ lwgeom_wrapx()

LWGEOM * lwgeom_wrapx ( const LWGEOM lwgeom_in,
double  cutx,
double  amount 
)

wrap geometry on given cut x value

For a positive amount, shifts anything that is on the left of "cutx" to the right by the given amount.

For a negative amount, shifts anything that is on the right of "cutx" to the left by the given absolute amount.

Parameters
cutxthe X value to perform wrapping on
amountshift amount and wrapping direction

Definition at line 169 of file lwgeom_wrapx.c.

170{
171 /* Nothing to wrap in an empty geom */
172 if ( lwgeom_is_empty(lwgeom_in) )
173 {
174 LWDEBUG(2, "geom is empty, cloning");
175 return lwgeom_clone_deep(lwgeom_in);
176 }
177
178 /* Nothing to wrap if shift amount is zero */
179 if ( amount == 0 )
180 {
181 LWDEBUG(2, "amount is zero, cloning");
182 return lwgeom_clone_deep(lwgeom_in);
183 }
184
185 switch (lwgeom_in->type)
186 {
187 case LINETYPE:
188 case POLYGONTYPE:
189 LWDEBUG(2, "split-wrapping line or polygon");
190 return lwgeom_split_wrapx(lwgeom_in, cutx, amount);
191
192 case POINTTYPE:
193 {
194 const LWPOINT *pt = lwgeom_as_lwpoint(lwgeom_clone_deep(lwgeom_in));
195 POINT4D pt4d;
196 getPoint4d_p(pt->point, 0, &pt4d);
197
198 LWDEBUGF(2, "POINT X is %g, cutx:%g, amount:%g", pt4d.x, cutx, amount);
199
200 if ( ( amount < 0 && pt4d.x > cutx ) || ( amount > 0 && pt4d.x < cutx ) )
201 {
202 pt4d.x += amount;
203 ptarray_set_point4d(pt->point, 0, &pt4d);
204 }
205 return lwpoint_as_lwgeom(pt);
206 }
207
208 case MULTIPOINTTYPE:
209 case MULTIPOLYGONTYPE:
210 case MULTILINETYPE:
211 case COLLECTIONTYPE:
212 LWDEBUG(2, "collection-wrapping multi");
214 lwcollection_wrapx((const LWCOLLECTION*)lwgeom_in, cutx, amount)
215 );
216
217 default:
218 lwerror("Wrapping of %s geometries is unsupported",
219 lwtype_name(lwgeom_in->type));
220 return NULL;
221 }
222
223}
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition lwutil.c:216
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition lwgeom.c:372
#define COLLECTIONTYPE
Definition liblwgeom.h:108
#define MULTILINETYPE
Definition liblwgeom.h:106
#define LINETYPE
Definition liblwgeom.h:103
#define MULTIPOINTTYPE
Definition liblwgeom.h:105
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition liblwgeom.h:102
#define MULTIPOLYGONTYPE
Definition liblwgeom.h:107
#define POLYGONTYPE
Definition liblwgeom.h:104
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition lwgeom_api.c:125
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
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 void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
static LWGEOM * lwgeom_split_wrapx(const LWGEOM *geom_in, double cutx, double amount)
static LWCOLLECTION * lwcollection_wrapx(const LWCOLLECTION *lwcoll_in, double cutx, double amount)
static LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition lwinline.h:127
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
uint8_t type
Definition liblwgeom.h:462
POINTARRAY * point
Definition liblwgeom.h:471
double x
Definition liblwgeom.h:414

References COLLECTIONTYPE, getPoint4d_p(), LINETYPE, lwcollection_as_lwgeom(), lwcollection_wrapx(), LWDEBUG, LWDEBUGF, lwerror(), lwgeom_as_lwpoint(), lwgeom_clone_deep(), lwgeom_is_empty(), lwgeom_split_wrapx(), lwpoint_as_lwgeom(), lwtype_name(), MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, LWPOINT::point, POINTTYPE, POLYGONTYPE, ptarray_set_point4d(), LWGEOM::type, LWCOLLECTION::type, and POINT4D::x.

Referenced by lwcollection_wrapx(), ST_WrapX(), and test_lwgeom_wrapx().

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