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

◆ LWGEOM_FilterByM()

Datum LWGEOM_FilterByM ( PG_FUNCTION_ARGS  )

Definition at line 3323 of file lwgeom_functions_basic.c.

3324{
3325 GSERIALIZED *geom_in;
3326 GSERIALIZED *geom_out;
3327 LWGEOM *lwgeom_in;
3328 LWGEOM *lwgeom_out;
3329 double min, max;
3330 int returnm;
3331 int hasm;
3332
3333 if (PG_NARGS() > 0 && !PG_ARGISNULL(0))
3334 {
3335 geom_in = PG_GETARG_GSERIALIZED_P(0);
3336 }
3337 else
3338 {
3339 PG_RETURN_NULL();
3340 }
3341
3342 if (PG_NARGS() > 1 && !PG_ARGISNULL(1))
3343 min = PG_GETARG_FLOAT8(1);
3344 else
3345 {
3346 min = DBL_MIN;
3347 }
3348 if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
3349 max = PG_GETARG_FLOAT8(2);
3350 else
3351 {
3352 max = DBL_MAX;
3353 }
3354 if (PG_NARGS() > 3 && !PG_ARGISNULL(3) && PG_GETARG_BOOL(3))
3355 returnm = 1;
3356 else
3357 {
3358 returnm = 0;
3359 }
3360
3361 if (min > max)
3362 {
3363 elog(ERROR, "Min-value cannot be larger than Max value\n");
3364 PG_RETURN_NULL();
3365 }
3366
3367 lwgeom_in = lwgeom_from_gserialized(geom_in);
3368
3369 hasm = lwgeom_has_m(lwgeom_in);
3370
3371 if (!hasm)
3372 {
3373 elog(NOTICE, "No M-value, No vertex removed\n");
3374 PG_RETURN_POINTER(geom_in);
3375 }
3376
3377 lwgeom_out = lwgeom_filter_m(lwgeom_in, min, max, returnm);
3378
3379 geom_out = geometry_serialize(lwgeom_out);
3380 lwgeom_free(lwgeom_out);
3381 PG_RETURN_POINTER(geom_out);
3382}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1218
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition lwgeom.c:941
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: