PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ 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 }
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:62
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:140
#define FLAGS_NDIMS(flags)
Definition: liblwgeom.h:152
#define FLAGS_GET_M(flags)
Definition: liblwgeom.h:141
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
uint32_t npoints
Definition: liblwgeom.h:374
uint8_t * serialized_pointlist
Definition: liblwgeom.h:369
uint8_t flags
Definition: liblwgeom.h:372
unsigned int uint32_t
Definition: uthash.h:78

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: