PostGIS  2.5.0dev-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  * PostGIS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * PostGIS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  **********************************************************************
20  *
21  * Copyright (C) 2001-2006 Refractions Research Inc.
22  *
23  **********************************************************************/
24 
25 
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include "liblwgeom_internal.h"
30 #include "lwgeom_log.h"
31 
32 void
34 {
36 }
37 
38 LWMPOINT *
39 lwmpoint_construct_empty(int srid, char hasz, char hasm)
40 {
42  return ret;
43 }
44 
46 {
47  LWDEBUG(4, "Called");
48  return (LWMPOINT*)lwcollection_add_lwgeom((LWCOLLECTION*)mobj, (LWGEOM*)obj);
49 }
50 
51 LWMPOINT *
52 lwmpoint_construct(int srid, const POINTARRAY *pa)
53 {
54  uint32_t i;
55  int hasz = ptarray_has_z(pa);
56  int hasm = ptarray_has_m(pa);
58 
59  for ( i = 0; i < pa->npoints; i++ )
60  {
61  LWPOINT *lwp;
62  POINT4D p;
63  getPoint4d_p(pa, i, &p);
64  lwp = lwpoint_make(srid, hasz, hasm, &p);
65  lwmpoint_add_lwpoint(ret, lwp);
66  }
67 
68  return ret;
69 }
70 
71 
73 {
74  uint32_t i;
75 
76  if ( ! mpt ) return;
77 
78  if ( mpt->bbox )
79  lwfree(mpt->bbox);
80 
81  for ( i = 0; i < mpt->ngeoms; i++ )
82  if ( mpt->geoms && mpt->geoms[i] )
83  lwpoint_free(mpt->geoms[i]);
84 
85  if ( mpt->geoms )
86  lwfree(mpt->geoms);
87 
88  lwfree(mpt);
89 }
90 
91 
92 LWMPOINT*
94 {
96  int has_z = lwgeom_has_z(g);
97  int has_m = lwgeom_has_m(g);
98  LWMPOINT* result = lwmpoint_construct_empty(g->srid, has_z, has_m);
99  POINT4D p;
100 
101  while(lwpointiterator_next(it, &p)) {
102  LWPOINT* lwp = lwpoint_make(g->srid, has_z, has_m, &p);
103  lwmpoint_add_lwpoint(result, lwp);
104  }
105 
107  return result;
108 }
void lwmpoint_free(LWMPOINT *mpt)
Definition: lwmpoint.c:72
GBOX * bbox
Definition: liblwgeom.h:468
uint32_t ngeoms
Definition: liblwgeom.h:470
int lwpointiterator_next(LWPOINTITERATOR *s, POINT4D *p)
Attempts to assign the next point in the iterator to p, and advances the iterator to the next point...
Definition: lwiterator.c:212
void lwfree(void *mem)
Definition: lwutil.c:244
void lwpoint_free(LWPOINT *pt)
Definition: lwpoint.c:213
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:930
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
Definition: lwiterator.c:244
int32_t srid
Definition: liblwgeom.h:401
LWMPOINT * lwmpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwmpoint.c:39
unsigned int uint32_t
Definition: uthash.h:78
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
Definition: lwiterator.c:269
LWPOINT * lwpoint_make(int srid, int hasz, int hasm, const POINT4D *p)
Definition: lwpoint.c:206
LWPOINT ** geoms
Definition: liblwgeom.h:472
LWMPOINT * lwmpoint_construct(int srid, const POINTARRAY *pa)
Definition: lwmpoint.c:52
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
Definition: lwgeom_api.c:113
int ptarray_has_m(const POINTARRAY *pa)
Definition: ptarray.c:43
void lwmpoint_release(LWMPOINT *lwmpoint)
Definition: lwmpoint.c:33
LWMPOINT * lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj)
Definition: lwmpoint.c:45
void lwgeom_release(LWGEOM *lwgeom)
Free the containing LWGEOM and the associated BOX.
Definition: lwgeom.c:459
int ptarray_has_z(const POINTARRAY *pa)
Definition: ptarray.c:36
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:937
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:187
LWGEOM * lwmpoint_as_lwgeom(const LWMPOINT *obj)
Definition: lwgeom.c:295
uint32_t npoints
Definition: liblwgeom.h:373
LWMPOINT * lwmpoint_from_lwgeom(const LWGEOM *g)
Definition: lwmpoint.c:93