[postgis-commits] svn - r2949 - in trunk: liblwgeom lwgeom
postgis-commits at postgis.refractions.net
postgis-commits at postgis.refractions.net
Tue Sep 9 14:10:47 PDT 2008
Author: mcayland
Date: 2008-09-09 14:10:46 -0700 (Tue, 09 Sep 2008)
New Revision: 2949
Modified:
trunk/liblwgeom/liblwgeom.h
trunk/liblwgeom/lwgeom.c
trunk/liblwgeom/lwgparse.c
trunk/liblwgeom/wktparse.h
trunk/lwgeom/lwgeom_gist.c
trunk/lwgeom/lwgeom_inout.c
trunk/lwgeom/lwgeom_ogc.c
trunk/lwgeom/lwgeom_pg.c
Log:
Allow a flags parameter to be passed into the WKT parser to determine which consistency checks are performed out of polygon ring closure, minimum number of points and odd number of points.
Modified: trunk/liblwgeom/liblwgeom.h
===================================================================
--- trunk/liblwgeom/liblwgeom.h 2008-09-08 20:17:29 UTC (rev 2948)
+++ trunk/liblwgeom/liblwgeom.h 2008-09-09 21:10:46 UTC (rev 2949)
@@ -1114,14 +1114,22 @@
extern uchar parse_hex(char *str);
extern void deparse_hex(uchar str, char *result);
+/* Parser check flags */
+#define PARSER_CHECK_MINPOINTS 1
+#define PARSER_CHECK_ODD 2
+#define PARSER_CHECK_CLOSURE 4
+
+#define PARSER_CHECK_ALL (PARSER_CHECK_MINPOINTS | PARSER_CHECK_ODD | PARSER_CHECK_CLOSURE)
+
+
/* Parser access routines */
extern char *lwgeom_to_ewkt(LWGEOM *lwgeom);
extern char *lwgeom_to_hexwkb(LWGEOM *lwgeom, unsigned int byteorder);
-extern LWGEOM *lwgeom_from_ewkb(uchar *ewkb, size_t ewkblen);
+extern LWGEOM *lwgeom_from_ewkb(uchar *ewkb, size_t ewkblen, int flags);
extern uchar *lwgeom_to_ewkb(LWGEOM *lwgeom, char byteorder, size_t *ewkblen);
extern char *serialized_lwgeom_to_ewkt(uchar *serialized);
-extern SERIALIZED_LWGEOM *serialized_lwgeom_from_ewkt(char *wkt_input);
+extern SERIALIZED_LWGEOM *serialized_lwgeom_from_ewkt(char *wkt_input, int flags);
extern char *serialized_lwgeom_to_hexwkb(uchar *serialized, unsigned int byteorder, size_t *size);
extern char *serialized_lwgeom_to_ewkb(uchar *serialized, unsigned int byteorder, size_t *size);
Modified: trunk/liblwgeom/lwgeom.c
===================================================================
--- trunk/liblwgeom/lwgeom.c 2008-09-08 20:17:29 UTC (rev 2948)
+++ trunk/liblwgeom/lwgeom.c 2008-09-09 21:10:46 UTC (rev 2949)
@@ -508,7 +508,7 @@
* - deserialize it
*/
LWGEOM *
-lwgeom_from_ewkb(uchar *ewkb, size_t size)
+lwgeom_from_ewkb(uchar *ewkb, size_t size, int flags)
{
size_t hexewkblen = size*2;
char *hexewkb;
@@ -522,7 +522,7 @@
hexewkb[hexewkblen] = '\0';
/* Rely on grammar parser to construct a LWGEOM */
- serialized_lwgeom = serialized_lwgeom_from_ewkt(hexewkb);
+ serialized_lwgeom = serialized_lwgeom_from_ewkt(hexewkb, flags);
/* Free intermediate HEXified representation */
lwfree(hexewkb);
@@ -543,9 +543,9 @@
* Make a serialzed LWGEOM object from a WKT input string
*/
SERIALIZED_LWGEOM *
-serialized_lwgeom_from_ewkt(char *wkt_input)
+serialized_lwgeom_from_ewkt(char *wkt_input, int flags)
{
- SERIALIZED_LWGEOM *serialized_form = parse_lwg(wkt_input,
+ SERIALIZED_LWGEOM *serialized_form = parse_lwg(wkt_input, flags,
lwalloc, lwerror);
Modified: trunk/liblwgeom/lwgparse.c
===================================================================
--- trunk/liblwgeom/lwgparse.c 2008-09-08 20:17:29 UTC (rev 2948)
+++ trunk/liblwgeom/lwgparse.c 2008-09-09 21:10:46 UTC (rev 2949)
@@ -91,6 +91,16 @@
} the_geom;
tuple* free_list=0;
+
+
+/*
+ * Parser global check flags - a bitmap of flags that determine which checks the parser will perform
+ * (see liblwgeom.h for the related PARSER_CHECK constants)
+ */
+int parser_check_flags;
+
+
+/* Parser state flags - these are set automatically by the parser */
int minpoints;
int checkclosed;
@@ -102,6 +112,7 @@
double *first_point=NULL;
double *last_point=NULL;
+
/* External functions */
extern void init_parser(const char *);
@@ -158,9 +169,9 @@
void read_collection(const char **b, read_col_func f);
void parse_wkb(const char **b);
void alloc_wkb(const char *parser);
-SERIALIZED_LWGEOM* parse_it(const char* geometry, allocator allocfunc, report_error errfunc);
-SERIALIZED_LWGEOM* parse_lwg(const char* geometry, allocator allocfunc, report_error errfunc);
-SERIALIZED_LWGEOM* parse_lwgi(const char* geometry, allocator allocfunc, report_error errfunc);
+SERIALIZED_LWGEOM* parse_it(const char* geometry, int flags, allocator allocfunc, report_error errfunc);
+SERIALIZED_LWGEOM* parse_lwg(const char* geometry, int flags, allocator allocfunc, report_error errfunc);
+SERIALIZED_LWGEOM* parse_lwgi(const char* geometry, int flags, allocator allocfunc, report_error errfunc);
void
set_srid(double d_srid)
@@ -269,21 +280,31 @@
void
popc(void)
{
+ /* If the minimum point check has been enabled, perform it */
+ if (parser_check_flags & PARSER_CHECK_MINPOINTS) {
+ if ( the_geom.stack->uu.nn.num < minpoints){
+ error("geometry requires more points");
+ }
+ }
- if ( the_geom.stack->uu.nn.num < minpoints){
- error("geometry requires more points");
+ /* If the odd number point check has been enabled, perform it */
+ if (parser_check_flags & PARSER_CHECK_CLOSURE) {
+ if(isodd != -1 && the_geom.stack->uu.nn.num % 2 != isodd) {
+ error("geometry must have an odd number of points");
+ }
}
- if(isodd != -1 && the_geom.stack->uu.nn.num % 2 != isodd) {
- error("geometry must have an odd number of points");
- }
- if ( checkclosed && first_point && last_point) {
- if ( memcmp(first_point, last_point,
- sizeof(double)*the_geom.ndims) )
- {
- error("geometry contains non-closed rings");
- }
- }
+ /* If the polygon closure check has been enabled, perform it */
+ if (parser_check_flags & PARSER_CHECK_ODD) {
+ if ( checkclosed && first_point && last_point) {
+ if ( memcmp(first_point, last_point,
+ sizeof(double)*the_geom.ndims) )
+ {
+ error("geometry contains non-closed rings");
+ }
+ }
+ }
+
the_geom.stack = the_geom.stack->uu.nn.stack_next;
}
@@ -1106,7 +1127,7 @@
Parse a string and return a LW_GEOM
*/
SERIALIZED_LWGEOM *
-parse_it(const char *geometry, allocator allocfunc, report_error errfunc)
+parse_it(const char *geometry, int flags, allocator allocfunc, report_error errfunc)
{
LWDEBUGF(2, "parse_it: %s", geometry);
@@ -1115,6 +1136,9 @@
ferror_occured = 0;
+ /* Setup the inital parser flags */
+ parser_check_flags = flags;
+
init_parser(geometry);
lwg_parse_yyparse();
@@ -1128,17 +1152,17 @@
}
SERIALIZED_LWGEOM *
-parse_lwg(const char* geometry,allocator allocfunc,report_error errfunc)
+parse_lwg(const char* geometry, int flags, allocator allocfunc, report_error errfunc)
{
the_geom.lwgi=0;
- return parse_it(geometry,allocfunc,errfunc);
+ return parse_it(geometry, flags, allocfunc, errfunc);
}
SERIALIZED_LWGEOM *
-parse_lwgi(const char* geometry,allocator allocfunc,report_error errfunc)
+parse_lwgi(const char* geometry, int flags, allocator allocfunc, report_error errfunc)
{
the_geom.lwgi=1;
- return parse_it(geometry,allocfunc,errfunc);
+ return parse_it(geometry, flags, allocfunc, errfunc);
}
void
Modified: trunk/liblwgeom/wktparse.h
===================================================================
--- trunk/liblwgeom/wktparse.h 2008-09-08 20:17:29 UTC (rev 2948)
+++ trunk/liblwgeom/wktparse.h 2008-09-09 21:10:46 UTC (rev 2949)
@@ -96,8 +96,8 @@
You are responsible for freeing the returned memory.
*/
-SERIALIZED_LWGEOM* parse_lwg(const char* wkt,allocator allocfunc,report_error errfunc);
-SERIALIZED_LWGEOM* parse_lwgi(const char* wkt,allocator allocfunc,report_error errfunc);
+SERIALIZED_LWGEOM* parse_lwg(const char* wkt, int flags, allocator allocfunc,report_error errfunc);
+SERIALIZED_LWGEOM* parse_lwgi(const char* wkt, int flags, allocator allocfunc,report_error errfunc);
char* unparse_WKT(uchar* serialized, allocator alloc,freeor free);
char* unparse_WKB(uchar* serialized, allocator alloc,freeor free, char endian, size_t *outsize, uchar hexform);
int lwg_parse_yyparse(void);
Modified: trunk/lwgeom/lwgeom_gist.c
===================================================================
--- trunk/lwgeom/lwgeom_gist.c 2008-09-08 20:17:29 UTC (rev 2948)
+++ trunk/lwgeom/lwgeom_gist.c 2008-09-09 21:10:46 UTC (rev 2949)
@@ -746,8 +746,8 @@
PG_FUNCTION_INFO_V1(LWGEOM_gist_decompress);
Datum LWGEOM_gist_decompress(PG_FUNCTION_ARGS)
{
+ static unsigned int counter2 = 0;
#if POSTGIS_DEBUG_LEVEL >= 4
- static unsigned int counter2 = 0;
counter2++;
#endif
POSTGIS_DEBUGF(2, "GIST: LWGEOM_gist_decompress called %i",counter2);
Modified: trunk/lwgeom/lwgeom_inout.c
===================================================================
--- trunk/lwgeom/lwgeom_inout.c 2008-09-08 20:17:29 UTC (rev 2948)
+++ trunk/lwgeom/lwgeom_inout.c 2008-09-09 21:10:46 UTC (rev 2949)
@@ -68,7 +68,7 @@
PG_LWGEOM *ret;
/* will handle both HEXEWKB and EWKT */
- serialized_lwgeom = serialized_lwgeom_from_ewkt(str);
+ serialized_lwgeom = serialized_lwgeom_from_ewkt(str, PARSER_CHECK_ALL);
lwgeom = lwgeom_deserialize(serialized_lwgeom->lwgeom);
ret = pglwgeom_serialize(lwgeom);
@@ -476,7 +476,7 @@
POSTGIS_DEBUGF(3, "in parse_WKT_lwgeom with input: '%s'",wkt);
- serialized_lwgeom = serialized_lwgeom_from_ewkt(wkt);
+ serialized_lwgeom = serialized_lwgeom_from_ewkt(wkt, PARSER_CHECK_ALL);
lwgeom = lwgeom_deserialize(serialized_lwgeom->lwgeom);
ret = pglwgeom_serialize(lwgeom);
Modified: trunk/lwgeom/lwgeom_ogc.c
===================================================================
--- trunk/lwgeom/lwgeom_ogc.c 2008-09-08 20:17:29 UTC (rev 2948)
+++ trunk/lwgeom/lwgeom_ogc.c 2008-09-09 21:10:46 UTC (rev 2949)
@@ -1002,7 +1002,7 @@
POSTGIS_DEBUGF(3, "wkt: [%s]", wkt);
- serialized_lwgeom = serialized_lwgeom_from_ewkt(wkt);
+ serialized_lwgeom = serialized_lwgeom_from_ewkt(wkt, PARSER_CHECK_ALL);
lwgeom = lwgeom_deserialize(serialized_lwgeom->lwgeom);
if ( lwgeom->SRID != -1 || TYPE_GETZM(lwgeom->type) != 0 )
Modified: trunk/lwgeom/lwgeom_pg.c
===================================================================
--- trunk/lwgeom/lwgeom_pg.c 2008-09-08 20:17:29 UTC (rev 2948)
+++ trunk/lwgeom/lwgeom_pg.c 2008-09-09 21:10:46 UTC (rev 2949)
@@ -264,7 +264,7 @@
}
hexewkb[hexewkblen] = '\0';
- serialized_lwgeom = serialized_lwgeom_from_ewkt(hexewkb);
+ serialized_lwgeom = serialized_lwgeom_from_ewkt(hexewkb, PARSER_CHECK_ALL);
ret = (PG_LWGEOM *)palloc(serialized_lwgeom->size + VARHDRSZ);
SET_VARSIZE(ret, serialized_lwgeom->size + VARHDRSZ);
More information about the postgis-commits
mailing list