PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwmpoint_remove_repeated_points()

LWGEOM* lwmpoint_remove_repeated_points ( const LWMPOINT mpoint,
double  tolerance 
)

Definition at line 92 of file lwmpoint.c.

References LWMPOINT::bbox, gbox_copy(), LWMPOINT::geoms, lwalloc(), lwcollection_construct(), lwgeom_clone_deep(), lwgeom_mindistance2d(), LWMPOINT::ngeoms, LWMPOINT::srid, and LWMPOINT::type.

Referenced by lwgeom_remove_repeated_points().

93 {
94  uint32_t nnewgeoms;
95  uint32_t i, j;
96  LWGEOM **newgeoms;
97  LWGEOM *lwpt1, *lwpt2;
98 
99  newgeoms = lwalloc(sizeof(LWGEOM *)*mpoint->ngeoms);
100  nnewgeoms = 0;
101  for (i=0; i<mpoint->ngeoms; ++i)
102  {
103  lwpt1 = (LWGEOM*)mpoint->geoms[i];
104  /* Brute force, may be optimized by building an index */
105  int seen=0;
106  for (j=0; j<nnewgeoms; ++j)
107  {
108  lwpt2 = (LWGEOM*)newgeoms[j];
109  if ( lwgeom_mindistance2d(lwpt1, lwpt2) <= tolerance )
110  {
111  seen=1;
112  break;
113  }
114  }
115  if ( seen ) continue;
116  newgeoms[nnewgeoms++] = lwgeom_clone_deep(lwpt1);
117  }
118 
119  return (LWGEOM*)lwcollection_construct(mpoint->type,
120  mpoint->srid,
121  mpoint->bbox ? gbox_copy(mpoint->bbox) : NULL,
122  nnewgeoms, newgeoms);
123 
124 }
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:438
GBOX * bbox
Definition: liblwgeom.h:466
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:43
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:482
unsigned int uint32_t
Definition: uthash.h:78
uint8_t type
Definition: liblwgeom.h:464
LWPOINT ** geoms
Definition: liblwgeom.h:470
double lwgeom_mindistance2d(const LWGEOM *lw1, const LWGEOM *lw2)
Function initialazing min distance calculation.
Definition: measures.c:202
void * lwalloc(size_t size)
Definition: lwutil.c:229
int ngeoms
Definition: liblwgeom.h:468
int32_t srid
Definition: liblwgeom.h:467
Here is the call graph for this function:
Here is the caller graph for this function: