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

◆ LWGEOM_FilterByM()

Datum LWGEOM_FilterByM ( PG_FUNCTION_ARGS  )

Definition at line 3350 of file lwgeom_functions_basic.c.

3351{
3352 GSERIALIZED *geom_in;
3353 GSERIALIZED *geom_out;
3354 LWGEOM *lwgeom_in;
3355 LWGEOM *lwgeom_out;
3356 double min, max;
3357 int returnm;
3358 int hasm;
3359
3360 if (PG_NARGS() > 0 && !PG_ARGISNULL(0))
3361 {
3362 geom_in = PG_GETARG_GSERIALIZED_P(0);
3363 }
3364 else
3365 {
3366 PG_RETURN_NULL();
3367 }
3368
3369 if (PG_NARGS() > 1 && !PG_ARGISNULL(1))
3370 min = PG_GETARG_FLOAT8(1);
3371 else
3372 {
3373 min = DBL_MIN;
3374 }
3375 if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
3376 max = PG_GETARG_FLOAT8(2);
3377 else
3378 {
3379 max = DBL_MAX;
3380 }
3381 if (PG_NARGS() > 3 && !PG_ARGISNULL(3) && PG_GETARG_BOOL(3))
3382 returnm = 1;
3383 else
3384 {
3385 returnm = 0;
3386 }
3387
3388 if (min > max)
3389 {
3390 elog(ERROR, "Min-value cannot be larger than Max value\n");
3391 PG_RETURN_NULL();
3392 }
3393
3394 lwgeom_in = lwgeom_from_gserialized(geom_in);
3395
3396 hasm = lwgeom_has_m(lwgeom_in);
3397
3398 if (!hasm)
3399 {
3400 elog(NOTICE, "No M-value, No vertex removed\n");
3401 PG_RETURN_POINTER(geom_in);
3402 }
3403
3404 lwgeom_out = lwgeom_filter_m(lwgeom_in, min, max, returnm);
3405
3406 geom_out = geometry_serialize(lwgeom_out);
3407 lwgeom_free(lwgeom_out);
3408 PG_RETURN_POINTER(geom_out);
3409}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition lwgeom.c:969
LWGEOM * lwgeom_filter_m(LWGEOM *geom, double min, double max, int returnm)
Definition lwmval.c:221

References lwgeom_filter_m(), lwgeom_free(), lwgeom_from_gserialized(), and lwgeom_has_m().

Here is the call graph for this function: