[postgis-commits] svn - r3861 - spike/mleslie/parser/liblwgeom
postgis-commits at postgis.refractions.net
postgis-commits at postgis.refractions.net
Thu Mar 12 20:52:44 PDT 2009
Author: mleslie
Date: 2009-03-12 20:52:43 -0700 (Thu, 12 Mar 2009)
New Revision: 3861
Modified:
spike/mleslie/parser/liblwgeom/liblwgeom.h
spike/mleslie/parser/liblwgeom/lwgparse.c
Log:
Adding knowledge of the SQL-MM WKB definitions for curved and 3-4d geometries.
Modified: spike/mleslie/parser/liblwgeom/liblwgeom.h
===================================================================
--- spike/mleslie/parser/liblwgeom/liblwgeom.h 2009-03-12 23:20:26 UTC (rev 3860)
+++ spike/mleslie/parser/liblwgeom/liblwgeom.h 2009-03-13 03:52:43 UTC (rev 3861)
@@ -597,6 +597,48 @@
#define MULTICURVETYPE 14
#define MULTISURFACETYPE 15
+#define WKBCIRCULARSTRING 1000001
+#define WKBCOMPOUNDCURVE 1000002
+#define WKBCURVEPOLYGON 1000003
+#define WKBMULTICURVE 1000004
+#define WKBMULTISURFACE 1000005
+#define WKBPOINTZM 2000001
+#define WKBLINESTRINGZM 2000002
+#define WKBCIRCULARSTRINGZM 2000003
+#define WKBCOMPOUNDCURVEZM 2000004
+#define WKBPOLYGONZM 2000005
+#define WKBCURVEPOLYGONZM 2000006
+#define WKBMULTIPOINTZM 2000007
+#define WKBMULTICURVEZM 200008
+#define WKBMULTILINESTRINGZM 2000009
+#define WKBMULTISURFACEZM 2000010
+#define WKBMULTIPOLYGONZM 2000011
+#define WKBGEOMETRYCOLLECTIONZM 2000012
+#define WKBPOINTZ 3000001
+#define WKBLINESTRINGZ 3000002
+#define WKBCIRCULARSTRINGZ 3000003
+#define WKBCOMPOUNDCURVEZ 3000004
+#define WKBPOLYGONZ 3000005
+#define WKBCURVEPOLYGONZ 3000006
+#define WKBMULTIPOINTZ 3000007
+#define WKBMULTICURVEZ 300008
+#define WKBMULTILINESTRINGZ 3000009
+#define WKBMULTISURFACEZ 3000010
+#define WKBMULTIPOLYGONZ 3000011
+#define WKBGEOMETRYCOLLECTIONZ 3000012
+#define WKBPOINTM 4000001
+#define WKBLINESTRINGM 4000002
+#define WKBCIRCULARSTRINGM 4000003
+#define WKBCOMPOUNDCURVEM 4000004
+#define WKBPOLYGONM 4000005
+#define WKBCURVEPOLYGONM 4000006
+#define WKBMULTIPOINTM 4000007
+#define WKBMULTICURVEM 400008
+#define WKBMULTILINESTRINGM 4000009
+#define WKBMULTISURFACEM 4000010
+#define WKBMULTIPOLYGONM 4000011
+#define WKBGEOMETRYCOLLECTIONM 4000012
+
#define WKBZOFFSET 0x80000000
#define WKBMOFFSET 0x40000000
#define WKBSRIDFLAG 0x20000000
Modified: spike/mleslie/parser/liblwgeom/lwgparse.c
===================================================================
--- spike/mleslie/parser/liblwgeom/lwgparse.c 2009-03-12 23:20:26 UTC (rev 3860)
+++ spike/mleslie/parser/liblwgeom/lwgparse.c 2009-03-13 03:52:43 UTC (rev 3861)
@@ -28,6 +28,8 @@
typedef uint32_t int4;
+int4 clean_type(int4);
+
typedef struct tag_tuple tuple;
struct tag_outputstate{
@@ -1427,6 +1429,7 @@
{
/* Read through a WKB ordinate array */
int4 cnt=read_wkb_int(b);
+ LWDEBUGF(5, "read_wkb_ordinate_array: count %d", cnt);
alloc_counter();
while(cnt--){
@@ -1470,7 +1473,10 @@
}
type = read_wkb_int(b);
+ type = clean_type(type);
+ LWDEBUGF(5, "parse_wkb: type=%d", type);
+
/* quick exit on error */
if ( parser_ferror_occured ) return;
@@ -1517,14 +1523,18 @@
alloc_stack_tuple(towrite,write_type,1);
}
- switch(type ){
+ LWDEBUGF(5, "Entering Massive Type Switch (MTS) with type %d", type);
+ switch(type){
case POINTTYPE:
+ LWDEBUG(5, "parse_wkb: Found point");
read_wkb_point(b);
break;
+
case LINETYPE:
read_wkb_linestring(b);
break;
case CIRCSTRINGTYPE:
+ LWDEBUG(5, "parse_wkb: Found circularstring");
read_wkb_circstring(b);
break;
case POLYGONTYPE:
@@ -1561,7 +1571,7 @@
the_geom.from_lwgi=1;
read_wkb_polygon(b);
break;
-
+ /* Start handling the SQL-MM binary types */
default:
LWGEOM_WKB_PARSER_ERROR(PARSER_ERROR_INVALIDWKBTYPE);
}
@@ -1571,7 +1581,167 @@
pop();
}
+/*
+ * int4 clean_type(int4)
+ *
+ * Mark Leslie
+ * This method was added to convert SQL-MM style type descriptors into those
+ * currently used by PostGIS. The goal is to make the common case where the
+ * type values are internal PostGIS types as fast as possible, at the expense
+ * of the currently rare SQL-MM WKB versions.
+ * Internal types are defined be the macros <type>TYPE.
+ * SQL-MM types are defined by the macros WKB<type>[Z][M]
+ */
+int4
+clean_type(int4 type_in)
+{
+ int4 type_out = 0;
+ LWDEBUGF(3, "clean_type %d", type_in);
+ /*
+ * Determine if there is content outside of what PostGIS uses internally.
+ * If not, return the input
+ */
+ if((0xF000000F & type_in) == type_in)
+ {
+ LWDEBUG(5, "clean_type: unchanged");
+ return type_in;
+ }
+ type_in = 0x00FFFFFF & type_in;
+ /* Prepare the massive switch :( */
+ switch(type_in)
+ {
+ case WKBCIRCULARSTRING:
+ type_out = CIRCSTRINGTYPE;
+ break;
+ case WKBCOMPOUNDCURVE:
+ type_out = COMPOUNDTYPE;
+ break;
+ case WKBCURVEPOLYGON:
+ type_out = CURVEPOLYTYPE;
+ break;
+ case WKBMULTICURVE:
+ type_out = MULTICURVETYPE;
+ break;
+ case WKBMULTISURFACE:
+ type_out = MULTISURFACETYPE;
+ break;
+ case WKBPOINTZM:
+ type_out = POINTTYPE & (WKBZOFFSET | WKBMOFFSET);
+ break;
+ case WKBLINESTRINGZM:
+ type_out = LINETYPE & (WKBZOFFSET | WKBMOFFSET);
+ break;
+ case WKBCIRCULARSTRINGZM:
+ type_out = CIRCSTRINGTYPE & (WKBZOFFSET | WKBMOFFSET);
+ break;
+ case WKBCOMPOUNDCURVEZM:
+ type_out = COMPOUNDTYPE & (WKBZOFFSET | WKBMOFFSET);
+ break;
+ case WKBPOLYGONZM:
+ type_out = POLYGONTYPE & (WKBZOFFSET | WKBMOFFSET);
+ break;
+ case WKBCURVEPOLYGONZM:
+ type_out = CURVEPOLYTYPE & (WKBZOFFSET | WKBMOFFSET);
+ break;
+ case WKBMULTIPOINTZM:
+ type_out = MULTIPOINTTYPE & (WKBZOFFSET | WKBMOFFSET);
+ break;
+ case WKBMULTICURVEZM:
+ type_out = MULTICURVETYPE & (WKBZOFFSET | WKBMOFFSET);
+ break;
+ case WKBMULTILINESTRINGZM:
+ type_out = MULTILINETYPE & (WKBZOFFSET | WKBMOFFSET);
+ break;
+ case WKBMULTISURFACEZM:
+ type_out = MULTISURFACETYPE & (WKBZOFFSET | WKBMOFFSET);
+ break;
+ case WKBMULTIPOLYGONZM:
+ type_out = MULTIPOLYGON & (WKBZOFFSET | WKBMOFFSET);
+ break;
+ case WKBGEOMETRYCOLLECTIONZM:
+ type_out = COLLECTIONTYPE & (WKBZOFFSET | WKBMOFFSET);
+ break;
+ case WKBPOINTZ:
+ type_out = POINTTYPE & WKBZOFFSET;
+ break;
+ case WKBLINESTRINGZ:
+ type_out = LINETYPE & WKBZOFFSET;
+ break;
+ case WKBCIRCULARSTRINGZ:
+ type_out = CIRCSTRINGTYPE & WKBZOFFSET;
+ break;
+ case WKBCOMPOUNDCURVEZ:
+ type_out = COMPOUNDTYPE & WKBZOFFSET;
+ break;
+ case WKBPOLYGONZ:
+ type_out = POLYGONTYPE & WKBZOFFSET;
+ break;
+ case WKBCURVEPOLYGONZ:
+ type_out = CURVEPOLYTYPE & WKBZOFFSET;
+ break;
+ case WKBMULTIPOINTZ:
+ type_out = MULTIPOINTTYPE & WKBZOFFSET;
+ break;
+ case WKBMULTICURVEZ:
+ type_out = MULTICURVE & WKBZOFFSET;
+ break;
+ case WKBMULTILINESTRINGZ:
+ type_out = MULTILINETYPE & WKBZOFFSET;
+ break;
+ case WKBMULTISURFACEZ:
+ type_out = MULTISURFACETYPE & WKBZOFFSET;
+ break;
+ case WKBMULTIPOLYGONZ:
+ type_out = MULTIPOLYGONTYPE & WKBZOFFSET;
+ break;
+ case WKBGEOMETRYCOLLECTIONZ:
+ type_out = COLLECTIONTYPE & WKBZOFFSET;
+ break;
+ case WKBPOINTM:
+ type_out = POINTTYPE & WKBMOFFSET;
+ break;
+ case WKBLINESTRINGM:
+ type_out = LINETYPE & WKBMOFFSET;
+ break;
+ case WKBCIRCULARSTRINGM:
+ type_out = CIRCSTRINGTYPE & WKBMOFFSET;
+ break;
+ case WKBCOMPOUNDCURVEM:
+ type_out = COMPOUNDTYPE & WKBMOFFSET;
+ break;
+ case WKBPOLYGONM:
+ type_out = POLYGONTYPE & WKBMOFFSET;
+ break;
+ case WKBCURVEPOLYGONM:
+ type_out = CURVEPOLYTYPE & WKBMOFFSET;
+ break;
+ case WKBMULTIPOINTM:
+ type_out = MULTIPOINTTYPE & WKBMOFFSET;
+ break;
+ case WKBMULTICURVEM:
+ type_out = MULTICURVETYPE & WKBMOFFSET;
+ break;
+ case WKBMULTILINESTRINGM:
+ type_out = MULTILINETYPE & WKBMOFFSET;
+ break;
+ case WKBMULTISURFACEM:
+ type_out = MULTISURFACETYPE & WKBMOFFSET;
+ break;
+ case WKBMULTIPOLYGONM:
+ type_out = MULTIPOLYGONTYPE & WKBMOFFSET;
+ break;
+ case WKBGEOMETRYCOLLECTIONM:
+ type_out = COLLECTIONTYPE & WKBMOFFSET;
+ break;
+ default:
+ type_out = type_in;
+ break;
+ }
+ LWDEBUGF(5, "clean_type: returning %d", type_out);
+ return type_out;
+}
+
void
alloc_wkb(const char *parser)
{
More information about the postgis-commits
mailing list