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) 2010-2015 Paul Ramsey <pramsey@cleverelephant.ca>
22  * Copyright (C) 2011      Sandro Santilli <strk@kbt.io>
23  *
24  **********************************************************************/
25 
26 #include "liblwgeom_internal.h"
27 
28 /*
29 * Coordinate object to hold information about last coordinate temporarily.
30 * We need to know how many dimensions there are at any given time.
31 */
32 typedef struct
33 {
34 	lwflags_t flags;
35 	double x;
36 	double y;
37 	double z;
38 	double m;
39 }
40 POINT;
41 
42 /*
43 * Global that holds the final output geometry for the WKT parser.
44 */
45 extern LWGEOM_PARSER_RESULT global_parser_result;
46 extern const char *parser_error_messages[];
47 
48 /*
49 * Prototypes for the lexer
50 */
51 extern void wkt_lexer_init(char *str);
52 extern void wkt_lexer_close(void);
53 extern int wkt_yylex_destroy(void);
54 
55 
56 /*
57 * Functions called from within the bison parser to construct geometries.
58 */
59 int32_t wkt_lexer_read_srid(char *str);
60 POINT wkt_parser_coord_2(double c1, double c2);
61 POINT wkt_parser_coord_3(double c1, double c2, double c3);
62 POINT wkt_parser_coord_4(double c1, double c2, double c3, double c4);
63 POINTARRAY* wkt_parser_ptarray_add_coord(POINTARRAY *pa, POINT p);
64 POINTARRAY* wkt_parser_ptarray_new(POINT p);
65 LWGEOM* wkt_parser_point_new(POINTARRAY *pa, char *dimensionality);
66 LWGEOM* wkt_parser_linestring_new(POINTARRAY *pa, char *dimensionality);
67 LWGEOM* wkt_parser_circularstring_new(POINTARRAY *pa, char *dimensionality);
68 LWGEOM* wkt_parser_triangle_new(POINTARRAY *pa, char *dimensionality);
69 LWGEOM* wkt_parser_polygon_new(POINTARRAY *pa, char dimcheck);
70 LWGEOM* wkt_parser_polygon_add_ring(LWGEOM *poly, POINTARRAY *pa, char dimcheck);
71 LWGEOM* wkt_parser_polygon_finalize(LWGEOM *poly, char *dimensionality);
72 LWGEOM* wkt_parser_curvepolygon_new(LWGEOM *ring);
73 LWGEOM* wkt_parser_curvepolygon_add_ring(LWGEOM *poly, LWGEOM *ring);
74 LWGEOM* wkt_parser_curvepolygon_finalize(LWGEOM *poly, char *dimensionality);
75 LWGEOM* wkt_parser_compound_new(LWGEOM *element);
76 LWGEOM* wkt_parser_compound_add_geom(LWGEOM *col, LWGEOM *geom);
77 LWGEOM* wkt_parser_collection_new(LWGEOM *geom);
78 LWGEOM* wkt_parser_collection_add_geom(LWGEOM *col, LWGEOM *geom);
79 LWGEOM* wkt_parser_collection_finalize(int lwtype, LWGEOM *col, char *dimensionality);
80 void wkt_parser_geometry_new(LWGEOM *geom, int32_t srid);
81