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

◆ ptarray_filterm()

static POINTARRAY * ptarray_filterm ( POINTARRAY pa,
double  min,
double  max,
int  returnm 
)
static

Definition at line 31 of file lwmval.c.

32{
33 LWDEBUGF(2, "Entered %s", __func__);
34
35 /*Check if M exists
36 * This should already be tested earlier so we don't handle it properly.
37 * If this happens it is because the function is used in another context than filterM
38 and we throw an error*/
39 if(!FLAGS_GET_M(pa->flags))
40 lwerror("missing m-value in function %s\n",__func__);
41
42 /*Dimensions in input geometry*/
43 int ndims = FLAGS_NDIMS(pa->flags);
44
45 /*Dimensions in result*/
46 int res_ndims;
47 if(returnm)
48 res_ndims = ndims;
49 else
50 res_ndims = ndims-1;
51
52 int pointsize = res_ndims * sizeof(double);
53
54 double m_val;
55
56 //M-value will always be the last dimension
57 int m_pos = ndims-1;
58
59 uint32_t i, counter=0;
60 for(i=0;i<pa->npoints;i++)
61 {
62 m_val = *((double*)pa->serialized_pointlist + i*ndims + m_pos);
63 if(m_val >= min && m_val <= max)
64 counter++;
65 }
66
67 POINTARRAY *pa_res = ptarray_construct(FLAGS_GET_Z(pa->flags),returnm * FLAGS_GET_M(pa->flags), counter);
68
69 double *res_cursor = (double*) pa_res->serialized_pointlist;
70 for(i=0;i<pa->npoints;i++)
71 {
72 m_val = *((double*)pa->serialized_pointlist + i*ndims + m_pos);
73 if(m_val >= min && m_val <= max)
74 {
75 memcpy(res_cursor, (double*) pa->serialized_pointlist + i*ndims, pointsize);
76 res_cursor+=res_ndims;
77 }
78 }
79
80 return pa_res;
81
82}
#define FLAGS_GET_Z(flags)
Definition liblwgeom.h:165
#define FLAGS_NDIMS(flags)
Definition liblwgeom.h:179
#define FLAGS_GET_M(flags)
Definition liblwgeom.h:166
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
#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.
lwflags_t flags
Definition liblwgeom.h:431
uint32_t npoints
Definition liblwgeom.h:427
uint8_t * serialized_pointlist
Definition liblwgeom.h:434

References POINTARRAY::flags, FLAGS_GET_M, FLAGS_GET_Z, FLAGS_NDIMS, LWDEBUGF, lwerror(), POINTARRAY::npoints, ptarray_construct(), and POINTARRAY::serialized_pointlist.

Referenced by lwline_filterm(), lwpoint_filterm(), and lwpoly_filterm().

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