/src/postgis/liblwgeom/lwmpoint.c
Line | Count | Source |
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 |
33 | | lwmpoint_release(LWMPOINT *lwmpoint) |
34 | 0 | { |
35 | 0 | lwgeom_release(lwmpoint_as_lwgeom(lwmpoint)); |
36 | 0 | } |
37 | | |
38 | | LWMPOINT * |
39 | | lwmpoint_construct_empty(int32_t srid, char hasz, char hasm) |
40 | 0 | { |
41 | 0 | LWMPOINT *ret = (LWMPOINT*)lwcollection_construct_empty(MULTIPOINTTYPE, srid, hasz, hasm); |
42 | 0 | return ret; |
43 | 0 | } |
44 | | |
45 | | LWMPOINT* lwmpoint_add_lwpoint(LWMPOINT *mobj, const LWPOINT *obj) |
46 | 0 | { |
47 | 0 | LWDEBUG(4, "Called"); |
48 | 0 | return (LWMPOINT*)lwcollection_add_lwgeom((LWCOLLECTION*)mobj, (LWGEOM*)obj); |
49 | 0 | } |
50 | | |
51 | | LWMPOINT * |
52 | | lwmpoint_construct(int32_t srid, const POINTARRAY *pa) |
53 | 0 | { |
54 | 0 | uint32_t i; |
55 | 0 | int hasz = ptarray_has_z(pa); |
56 | 0 | int hasm = ptarray_has_m(pa); |
57 | 0 | LWMPOINT *ret = (LWMPOINT*)lwcollection_construct_empty(MULTIPOINTTYPE, srid, hasz, hasm); |
58 | |
|
59 | 0 | for ( i = 0; i < pa->npoints; i++ ) |
60 | 0 | { |
61 | 0 | LWPOINT *lwp; |
62 | 0 | POINT4D p; |
63 | 0 | getPoint4d_p(pa, i, &p); |
64 | 0 | lwp = lwpoint_make(srid, hasz, hasm, &p); |
65 | 0 | lwmpoint_add_lwpoint(ret, lwp); |
66 | 0 | } |
67 | |
|
68 | 0 | return ret; |
69 | 0 | } |
70 | | |
71 | | |
72 | | void lwmpoint_free(LWMPOINT *mpt) |
73 | 0 | { |
74 | 0 | uint32_t i; |
75 | |
|
76 | 0 | if ( ! mpt ) return; |
77 | | |
78 | 0 | if ( mpt->bbox ) |
79 | 0 | lwfree(mpt->bbox); |
80 | |
|
81 | 0 | for ( i = 0; i < mpt->ngeoms; i++ ) |
82 | 0 | if ( mpt->geoms && mpt->geoms[i] ) |
83 | 0 | lwpoint_free(mpt->geoms[i]); |
84 | |
|
85 | 0 | if ( mpt->geoms ) |
86 | 0 | lwfree(mpt->geoms); |
87 | |
|
88 | 0 | lwfree(mpt); |
89 | 0 | } |
90 | | |
91 | | |
92 | | LWMPOINT* |
93 | | lwmpoint_from_lwgeom(const LWGEOM *g) |
94 | 0 | { |
95 | 0 | LWPOINTITERATOR* it = lwpointiterator_create(g); |
96 | 0 | int has_z = lwgeom_has_z(g); |
97 | 0 | int has_m = lwgeom_has_m(g); |
98 | 0 | LWMPOINT* result = lwmpoint_construct_empty(g->srid, has_z, has_m); |
99 | 0 | POINT4D p; |
100 | |
|
101 | 0 | while(lwpointiterator_next(it, &p)) { |
102 | 0 | LWPOINT* lwp = lwpoint_make(g->srid, has_z, has_m, &p); |
103 | 0 | lwmpoint_add_lwpoint(result, lwp); |
104 | 0 | } |
105 | |
|
106 | 0 | lwpointiterator_destroy(it); |
107 | 0 | return result; |
108 | 0 | } |