PostGIS  2.2.8dev-r@@SVN_REVISION@@
lwmpoint.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * Copyright (C) 2001-2006 Refractions Research Inc.
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU General Public Licence. See the COPYING file.
10  *
11  **********************************************************************/
12 
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include "liblwgeom_internal.h"
17 #include "lwgeom_log.h"
18 
19 void
21 {
23 }
24 
25 LWMPOINT *
26 lwmpoint_construct_empty(int srid, char hasz, char hasm)
27 {
29  return ret;
30 }
31 
33 {
34  LWDEBUG(4, "Called");
35  return (LWMPOINT*)lwcollection_add_lwgeom((LWCOLLECTION*)mobj, (LWGEOM*)obj);
36 }
37 
38 LWMPOINT *
39 lwmpoint_construct(int srid, const POINTARRAY *pa)
40 {
41  int i;
42  int hasz = ptarray_has_z(pa);
43  int hasm = ptarray_has_m(pa);
45 
46  for ( i = 0; i < pa->npoints; i++ )
47  {
48  LWPOINT *lwp;
49  POINT4D p;
50  getPoint4d_p(pa, i, &p);
51  lwp = lwpoint_make(srid, hasz, hasm, &p);
52  lwmpoint_add_lwpoint(ret, lwp);
53  }
54 
55  return ret;
56 }
57 
58 
60 {
61  int i;
62 
63  if ( ! mpt ) return;
64 
65  if ( mpt->bbox )
66  lwfree(mpt->bbox);
67 
68  for ( i = 0; i < mpt->ngeoms; i++ )
69  if ( mpt->geoms && mpt->geoms[i] )
70  lwpoint_free(mpt->geoms[i]);
71 
72  if ( mpt->geoms )
73  lwfree(mpt->geoms);
74 
75  lwfree(mpt);
76 }
77 
78 LWGEOM*
79 lwmpoint_remove_repeated_points(LWMPOINT *mpoint, double tolerance)
80 {
81  uint32_t nnewgeoms;
82  uint32_t i, j;
83  LWGEOM **newgeoms;
84 
85  newgeoms = lwalloc(sizeof(LWGEOM *)*mpoint->ngeoms);
86  nnewgeoms = 0;
87  for (i=0; i<mpoint->ngeoms; ++i)
88  {
89  /* Brute force, may be optimized by building an index */
90  int seen=0;
91  for (j=0; j<nnewgeoms; ++j)
92  {
93  if ( lwpoint_same((LWPOINT*)newgeoms[j],
94  (LWPOINT*)mpoint->geoms[i]) )
95  {
96  seen=1;
97  break;
98  }
99  }
100  if ( seen ) continue;
101  newgeoms[nnewgeoms++] = (LWGEOM*)lwpoint_clone(mpoint->geoms[i]);
102  }
103 
104  return (LWGEOM*)lwcollection_construct(mpoint->type,
105  mpoint->srid, mpoint->bbox ? gbox_copy(mpoint->bbox) : NULL,
106  nnewgeoms, newgeoms);
107 
108 }
109 
GBOX * gbox_copy(const GBOX *box)
Return a copy of the GBOX, based on dimensionality of flags.
Definition: g_box.c:403
void lwmpoint_free(LWMPOINT *mpt)
Definition: lwmpoint.c:59
char lwpoint_same(const LWPOINT *p1, const LWPOINT *p2)
Definition: lwpoint.c:233
GBOX * bbox
Definition: liblwgeom.h:450
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:30
void lwfree(void *mem)
Definition: lwutil.c:214
int npoints
Definition: liblwgeom.h:355
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:182
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
LWMPOINT * lwmpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwmpoint.c:26
uint8_t type
Definition: liblwgeom.h:448
LWPOINT * lwpoint_clone(const LWPOINT *lwgeom)
Definition: lwpoint.c:208
LWPOINT * lwpoint_make(int srid, int hasz, int hasm, const POINT4D *p)
Definition: lwpoint.c:175
LWPOINT ** geoms
Definition: liblwgeom.h:454
LWMPOINT * lwmpoint_construct(int srid, const POINTARRAY *pa)
Definition: lwmpoint.c:39
int ptarray_has_m(const POINTARRAY *pa)
Definition: ptarray.c:43
void lwmpoint_release(LWMPOINT *lwmpoint)
Definition: lwmpoint.c:20
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
Definition: lwmpoint.c:32
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:372
LWGEOM * lwmpoint_remove_repeated_points(LWMPOINT *mpoint, double tolerance)
Definition: lwmpoint.c:79
int ptarray_has_z(const POINTARRAY *pa)
Definition: ptarray.c:36
void * lwalloc(size_t size)
Definition: lwutil.c:199
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:81
int ngeoms
Definition: liblwgeom.h:452
int32_t srid
Definition: liblwgeom.h:451
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:174
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:231
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition: lwgeom.c:214