]> granicus.if.org Git - postgis/commitdiff
*** empty log message ***
authorMarkus Schaber <markus@schabi.de>
Mon, 21 Feb 2005 18:28:27 +0000 (18:28 +0000)
committerMarkus Schaber <markus@schabi.de>
Mon, 21 Feb 2005 18:28:27 +0000 (18:28 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@1417 b70326c6-7e19-0410-871a-916f4a2858ee

15 files changed:
CHANGES
jdbc2/src/examples/TestParser.java
jdbc2/src/org/postgis/ComposedGeom.java
jdbc2/src/org/postgis/Geometry.java
jdbc2/src/org/postgis/GeometryCollection.java
jdbc2/src/org/postgis/LineString.java
jdbc2/src/org/postgis/LinearRing.java
jdbc2/src/org/postgis/MultiLineString.java
jdbc2/src/org/postgis/MultiPoint.java
jdbc2/src/org/postgis/MultiPolygon.java
jdbc2/src/org/postgis/PGgeometry.java
jdbc2/src/org/postgis/Point.java
jdbc2/src/org/postgis/PointComposedGeom.java
jdbc2/src/org/postgis/Polygon.java
jdbc2/todo.txt

diff --git a/CHANGES b/CHANGES
index 77b4dfd1fafe35de69e7827a63764d0e89b7e9b0..14096d8132bb1a391343d2cf74605c1eac7b21bd 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -24,6 +24,7 @@ PostGIS 1.0.0?
        - plugged a leak in GEOS2POSTGIS converter
        - jdbc2: added BETA support for jts geometry classes
        - jdbc2: Skip known-to-fail tests against older PostGIS servers.
+       - jdbc2: Fixed handling of measured geometries in EWKT.
 
 PostGIS 1.0.0RC2
 2005/01/26
index 8acefbd68a971c42d78660020f9512c2994c6332..a616cdf9501c147c0442cfd6ae1cd4e492386479 100644 (file)
@@ -28,6 +28,7 @@ package examples;
 
 import org.postgis.Geometry;
 import org.postgis.PGgeometry;
+import org.postgresql.PGConnection;
 import org.postgresql.util.PGtokenizer;
 
 import java.sql.Connection;
@@ -45,26 +46,92 @@ public class TestParser {
      */
     public static final String[][] testset = new String[][]{
         {
-            ALL,
+            ALL, // 2D
+            "POINT(10 10)"},
+        {
+            ALL, // 3D with 3rd coordinate set to 0
+            "POINT(10 10 0)"},
+        {
+            ALL, // 3D
             "POINT(10 10 20)"},
+        {
+            ONLY10, // 2D + Measures
+            "POINTM(10 10 20)"},
+        {
+            ONLY10, // 3D + Measures
+            "POINT(10 10 20 30)"},
+        {
+            ALL,
+            "MULTIPOINT(11 12, 20 20)"},
         {
             ALL,
-            "MULTIPOINT(10 10 10, 20 20 20)"},
+            "MULTIPOINT(11 12 13, 20 20 20)"},
+        {
+            ONLY10,
+            "MULTIPOINTM(11 12 13, 20 20 20)"},
+        {
+            ONLY10,
+            "MULTIPOINT(11 12 13 14,20 20 20 20)"},
+        {
+            ALL,
+            "LINESTRING(10 10,20 20,50 50,34 34)"},
+        {
+            ALL,
+            "LINESTRING(10 10 20,20 20 20,50 50 50,34 34 34)"},
+        {
+            ONLY10,
+            "LINESTRINGM(10 10 20,20 20 20,50 50 50,34 34 34)"},
+        {
+            ONLY10,
+            "LINESTRING(10 10 20 20,20 20 20 20,50 50 50 50,34 34 34 50)"},
         {
             ALL,
-            "LINESTRING(10 10 20,20 20 20, 50 50 50, 34 34 34)"},
+            "POLYGON((10 10,20 10,20 20,20 10,10 10),(5 5,5 6,6 6,6 5,5 5))"},
         {
             ALL,
             "POLYGON((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0))"},
+        {
+            ONLY10,
+            "POLYGONM((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0))"},
+        {
+            ONLY10,
+            "POLYGON((10 10 0 7,20 10 0 7,20 20 0 7,20 10 0 7,10 10 0 7),(5 5 0 7,5 6 0 7,6 6 0 7,6 5 0 7,5 5 0 7))"},
+        {
+            ALL,
+            "MULTIPOLYGON(((10 10,20 10,20 20,20 10,10 10),(5 5,5 6,6 6,6 5,5 5)),((10 10,20 10,20 20,20 10,10 10),(5 5,5 6,6 6,6 5,5 5)))"},
         {
             ALL,
             "MULTIPOLYGON(((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0)),((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0)))"},
+        {
+            ONLY10,
+            "MULTIPOLYGONM(((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0)),((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0)))"},
+        {
+            ONLY10,
+            "MULTIPOLYGON(((10 10 0 7,20 10 0 7,20 20 0 7,20 10 0 7,10 10 0 7),(5 5 0 7,5 6 0 7,6 6 0 7,6 5 0 7,5 5 0 7)),((10 10 0 7,20 10 0 7,20 20 0 7,20 10 0 7,10 10 0 7),(5 5 0 7,5 6 0 7,6 6 0 7,6 5 0 7,5 5 0 7)))"},
+        {
+            ALL,
+            "MULTILINESTRING((10 10,20 10,20 20,20 10,10 10),(5 5,5 6,6 6,6 5,5 5))"},
         {
             ALL,
-            "MULTILINESTRING((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0))"},
+            "MULTILINESTRING((10 10 5,20 10 5,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0))"},
+        {
+            ONLY10,
+            "MULTILINESTRINGM((10 10 7,20 10 7,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0))"},
+        {
+            ONLY10,
+            "MULTILINESTRING((10 10 0 7,20 10 0 7,20 20 0 7,20 10 0 7,10 10 0 7),(5 5 0 7,5 6 0 7,6 6 0 7,6 5 0 7,5 5 0 7))"},
+        {
+            ALL,
+            "GEOMETRYCOLLECTION(POINT(10 10),POINT(20 20))"},
         {
             ALL,
             "GEOMETRYCOLLECTION(POINT(10 10 20),POINT(20 20 20))"},
+        {
+            ONLY10,
+            "GEOMETRYCOLLECTIONM(POINT(10 10 20),POINT(20 20 20))"},
+        {
+            ONLY10,
+            "GEOMETRYCOLLECTION(POINT(10 10 20 7),POINT(20 20 20 7))"},
         {
             ALL,
             "GEOMETRYCOLLECTION(LINESTRING(10 10 20,20 20 20, 50 50 50, 34 34 34),LINESTRING(10 10 20,20 20 20, 50 50 50, 34 34 34))"},
@@ -75,10 +142,12 @@ public class TestParser {
             ONLY10, // Cannot be parsed by 0.X servers
             "GEOMETRYCOLLECTION(MULTIPOINT(10 10 10, 20 20 20),MULTIPOINT(10 10 10, 20 20 20))"},
         {
-            EQUAL10, // PostGIs 0.X "flattens" this geometry, so it is not equal after reparsing.
+            EQUAL10, // PostGIs 0.X "flattens" this geometry, so it is not equal
+            // after reparsing.
             "GEOMETRYCOLLECTION(MULTILINESTRING((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0)))"},
         {
-            EQUAL10,// PostGIs 0.X "flattens" this geometry, so it is not equal after reparsing.
+            EQUAL10,// PostGIs 0.X "flattens" this geometry, so it is not equal
+            // after reparsing.
             "GEOMETRYCOLLECTION(MULTIPOLYGON(((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0)),((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0))),MULTIPOLYGON(((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0)),((10 10 0,20 10 0,20 20 0,20 10 0,10 10 0),(5 5 0,5 6 0,6 6 0,6 5 0,5 5 0))))"},
         {
             ALL,
@@ -254,6 +323,7 @@ public class TestParser {
         for (int i = 0; i < dburls.getSize(); i++) {
             System.out.println("Creating JDBC connection to " + dburls.getToken(i));
             conns[i] = connect(dburls.getToken(i), dbuser, dbpass);
+            ((PGConnection) conns[i]).addDataType("geometry", "org.postgis.PGgeometry");
         }
 
         System.out.println("Performing tests...");
index b3e10b00b2226cc320195f7a127fdb0b5b7e5064..652a59ad96f809a713a85669c1e781d905e3277c 100644 (file)
@@ -64,6 +64,7 @@ public abstract class ComposedGeom extends Geometry {
         this.subgeoms = geoms;
         if (geoms.length > 0) {
             dimension = geoms[0].dimension;
+            haveMeasure = geoms[0].haveMeasure;
         } else {
             dimension = 0;
         }
index 4f1bc0a78599f2bf53d060fea4a280a28c808cac..c196436d250c45e17243a4d9aacb12207cbc46b5 100644 (file)
@@ -146,9 +146,16 @@ public abstract class Geometry implements Serializable {
      * geometry specific equals implementation
      */
     public boolean equals(Geometry other) {
-        return ((other != null) && (this.dimension == other.dimension) && (this.type == other.type)
-                && (this.srid == other.srid) && (this.haveMeasure == other.haveMeasure)
-                && other.getClass().equals(this.getClass()) && this.equalsintern(other));
+        boolean firstline = (other != null) && (this.dimension == other.dimension) && (this.type == other.type);
+        boolean sridequals = (this.srid == other.srid);
+        boolean measEquals = (this.haveMeasure == other.haveMeasure);
+        boolean secondline = sridequals && measEquals;
+        boolean classequals = other.getClass().equals(this.getClass());
+        boolean equalsintern = this.equalsintern(other);
+        boolean result = firstline
+                && secondline
+                && classequals && equalsintern;
+        return result;
     }
 
     /**
@@ -226,7 +233,7 @@ public abstract class Geometry implements Serializable {
             sb.append(srid);
             sb.append(';');
         }
-        outerWKT(sb);
+        outerWKT(sb, true);
         return sb.toString();
     }
 
@@ -234,14 +241,18 @@ public abstract class Geometry implements Serializable {
      * Render the WKT version of this Geometry (without SRID) into the given
      * StringBuffer.
      */
-    public void outerWKT(StringBuffer sb) {
+    public void outerWKT(StringBuffer sb, boolean putM) {
         sb.append(typestring);
-        if (haveMeasure && dimension == 2) {
+        if (putM && haveMeasure && dimension == 2) {
             sb.append('M');
         }
         mediumWKT(sb);
     }
 
+    public final void outerWKT(StringBuffer sb) {
+        outerWKT(sb, true);
+    }
+    
     /**
      * Render the WKT without the type name, but including the brackets into the
      * StringBuffer
index f40bca9a5a73e6becd99c69bb0d8817bfc25298d..07d188715d6fa53c55cec085c2454441cdaf9710 100644 (file)
@@ -52,29 +52,40 @@ public class GeometryCollection extends ComposedGeom {
     }
 
     public GeometryCollection(String value) throws SQLException {
+        this(value, false);
+    }
+
+    public GeometryCollection(String value, boolean haveM) throws SQLException {
         this();
         value = value.trim();
         if (value.equals(EmptyColl)) {
             //Do nothing
         } else if (value.startsWith(GeoCollID)) {
-            PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value.substring(
-                    GeoCollID.length()).trim()), ',');
+            int pfxlen = typestring.length();
+            if (value.charAt(pfxlen) == 'M') {
+                pfxlen += 1;
+                haveM = true;
+            }
+            value = value.substring(pfxlen).trim();
+
+            PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
             int ngeoms = t.getSize();
             subgeoms = new Geometry[ngeoms];
             for (int p = 0; p < ngeoms; p++) {
-                subgeoms[p] = PGgeometry.geomFromString(t.getToken(p));
+                subgeoms[p] = PGgeometry.geomFromString(t.getToken(p), haveM);
             }
             dimension = subgeoms[0].dimension;
+            haveMeasure = subgeoms[0].haveMeasure;
         } else {
             throw new SQLException("postgis.geocollection");
         }
     }
 
     protected void innerWKT(StringBuffer SB) {
-        subgeoms[0].outerWKT(SB);
+        subgeoms[0].outerWKT(SB, false);
         for (int i = 1; i < subgeoms.length; i++) {
             SB.append(',');
-            subgeoms[i].outerWKT(SB);
+            subgeoms[i].outerWKT(SB, false);
         }
     }
 }
\ No newline at end of file
index c79889232ba5bc511c74300de2b9e1a2bce40801..db283337b81ab748bdcc4886f2ffdffc10344f5b 100644 (file)
@@ -44,6 +44,10 @@ public class LineString extends PointComposedGeom {
         super(LINESTRING, value);
     }
 
+    public LineString(String value, boolean haveM) throws SQLException {
+        super(LINESTRING, value, haveM);
+    }
+
     public LineString reverse() {
         Point[] points = this.getPoints();
         int l = points.length;
index c47032e835f32902fc27c6fb1658f101f4bedfcc..3a72152de9780321de93de11a8361a1cb8d8b007 100644 (file)
@@ -47,14 +47,27 @@ public class LinearRing extends PointComposedGeom {
      * @param value Definition of this ring in the PostGIS string format.
      */
     public LinearRing(String value) throws SQLException {
+        this(value, false);
+    }
+
+    /**
+     * @param value The text representation of this LinearRing
+     * @param haveM Hint whether we have a measure. This is given to us by other
+     *            "parent" Polygon, and is passed further to our parent.
+     */
+
+    protected LinearRing(String value, boolean haveM) throws SQLException {
         super(LINEARRING);
         PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value.trim()), ',');
         int npoints = t.getSize();
         Point[] points = new Point[npoints];
         for (int p = 0; p < npoints; p++) {
-            points[p] = new Point(t.getToken(p));
+            points[p] = new Point(t.getToken(p), haveM);
         }
-        dimension = points[0].dimension;
+        this.dimension = points[0].dimension;
+        // fetch haveMeasure from subpoint because haveM does only work with
+        // 2d+M, not with 3d+M geometries
+        this.haveMeasure = points[0].haveMeasure;
         this.subgeoms = points;
     }
 }
\ No newline at end of file
index db7c9fde536d8b2c832569092d724c03b040e728..c6fe1f85265e653de29bced4a6bba51fe3b9431f 100644 (file)
@@ -47,16 +47,27 @@ public class MultiLineString extends ComposedGeom {
     }
 
     public MultiLineString(String value) throws SQLException {
+        this(value, false);
+    }
+    
+    protected MultiLineString(String value, boolean haveM) throws SQLException {
         this();
-        value = value.trim();
-        if (value.indexOf("MULTILINESTRING") == 0) {
-            PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value.substring(15).trim()), ',');
+        value = value.trim();        
+        if (value.indexOf(typestring) == 0) {
+            int pfxlen = typestring.length();
+            if (value.charAt(pfxlen) == 'M') {
+                pfxlen += 1;
+                haveM = true;
+            }
+            value = value.substring(pfxlen).trim();
+            PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
             int nlines = t.getSize();
             subgeoms = new LineString[nlines];
             for (int p = 0; p < nlines; p++) {
-                subgeoms[p] = new LineString(t.getToken(p));
+                subgeoms[p] = new LineString(t.getToken(p), haveM);
             }
             dimension = subgeoms[0].dimension;
+            haveMeasure = subgeoms[0].haveMeasure;
         } else {
             throw new SQLException("postgis.multilinestringgeometry");
         }
index e70bbe6176f1975893b0b2c16d55a226496cd037..63bff7954dd3ff008a2db847f91a953f2845c347 100644 (file)
@@ -39,6 +39,10 @@ public class MultiPoint extends PointComposedGeom {
     }
 
     public MultiPoint(String value) throws SQLException {
-        super(MULTIPOINT, value);
+        this(value, false);
+    }
+
+    protected MultiPoint(String value, boolean haveM) throws SQLException {
+        super(MULTIPOINT, value, haveM);
     }
 }
\ No newline at end of file
index 39fc5c826d419bd028354fd4dea5bcf94e9e3bbc..548b13c799b73955f72db8ebadf039ddc692a273 100644 (file)
@@ -41,16 +41,29 @@ public class MultiPolygon extends ComposedGeom {
     }
 
     public MultiPolygon(String value) throws SQLException {
+        this(value, false);
+    }
+
+    protected MultiPolygon(String value, boolean haveM) throws SQLException {
         this();
         value = value.trim();
         if (value.indexOf("MULTIPOLYGON") == 0) {
-            PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value.substring(12).trim()), ',');
+            int pfxlen = typestring.length();
+            if (value.charAt(pfxlen) == 'M') {
+                pfxlen += 1;
+                haveM = true;
+            }
+            value = value.substring(pfxlen).trim();
+            PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
             int npolygons = t.getSize();
             subgeoms = new Polygon[npolygons];
             for (int p = 0; p < npolygons; p++) {
-                subgeoms[p] = new Polygon(t.getToken(p));
+                subgeoms[p] = new Polygon(t.getToken(p), haveM);
             }
             dimension = subgeoms[0].dimension;
+            // fetch haveMeasure from subpoint because haveM does only work with
+            // 2d+M, not with 3d+M geometries
+            this.haveMeasure = subgeoms[0].haveMeasure;
         } else {
             throw new SQLException("postgis.multipolygongeometry");
         }
index c670fbbef6e12a233c040f243b7c13bf25681810..ee37aa5318df910005cd69d18040c32c749b6f75 100644 (file)
@@ -55,15 +55,24 @@ public class PGgeometry extends PGobject {
     }
 
     public static Geometry geomFromString(String value) throws SQLException {
+        return geomFromString(value, false);
+    }
+
+    public static Geometry geomFromString(String value, boolean haveM) throws SQLException {
         BinaryParser bp = new BinaryParser();
 
-        return geomFromString(value, bp);
+        return geomFromString(value, bp, haveM);
     }
 
     /**
      * Maybe we could add more error checking here?
      */
     public static Geometry geomFromString(String value, BinaryParser bp) throws SQLException {
+        return geomFromString(value, bp, false);
+    }
+
+    public static Geometry geomFromString(String value, BinaryParser bp, boolean haveM)
+            throws SQLException {
         value = value.trim();
 
         int srid = -1;
@@ -83,19 +92,19 @@ public class PGgeometry extends PGobject {
             // geometry which is to be parsed as an empty GeometryCollection.
             result = new GeometryCollection();
         } else if (value.startsWith("MULTIPOLYGON")) {
-            result = new MultiPolygon(value);
+            result = new MultiPolygon(value, haveM);
         } else if (value.startsWith("MULTILINESTRING")) {
-            result = new MultiLineString(value);
+            result = new MultiLineString(value, haveM);
         } else if (value.startsWith("MULTIPOINT")) {
-            result = new MultiPoint(value);
+            result = new MultiPoint(value, haveM);
         } else if (value.startsWith("POLYGON")) {
-            result = new Polygon(value);
+            result = new Polygon(value, haveM);
         } else if (value.startsWith("LINESTRING")) {
-            result = new LineString(value);
+            result = new LineString(value, haveM);
         } else if (value.startsWith("POINT")) {
-            result = new Point(value);
+            result = new Point(value, haveM);
         } else if (value.startsWith("GEOMETRYCOLLECTION")) {
-            result = new GeometryCollection(value);
+            result = new GeometryCollection(value, haveM);
         } else {
             throw new SQLException("Unknown type: " + value);
         }
index 152bb9155da4dd4330f31dea269bd97216ba4305..c3de048a0b88e74b391079c8415ab75857873a70 100644 (file)
@@ -45,8 +45,15 @@ public class Point extends Geometry {
 
     protected boolean equalsintern(Geometry otherg) {
         Point other = (Point) otherg;
-        return x == other.x && y == other.y && ((dimension == 2) || (z == other.z))
-                && ((haveMeasure == false) || (m == other.m));
+        boolean xequals = x == other.x;
+        boolean zequals = ((dimension == 2) || (z == other.z));
+        boolean mequals = ((haveMeasure == false) || (m == other.m));
+        boolean result = xequals && yequals(other) && zequals && mequals;
+        return result;
+    }
+
+    private boolean yequals(Point other) {
+        return y == other.y;
     }
 
     public Point getPoint(int index) {
@@ -111,28 +118,54 @@ public class Point extends Geometry {
         dimension = 2;
     }
 
+    /**
+     * Construct a Point from EWKT.
+     * 
+     * (3D and measures are legal, but SRID is not allowed).
+     */
     public Point(String value) throws SQLException {
+        this(value, false);
+    }
+
+    /**
+     * Construct a Point
+     * 
+     * @param value The text representation of this point
+     * @param haveM Hint whether we have a measure. This is used by other
+     *            geometries parsing inner points where we only get "1 2 3 4"
+     *            like strings without the "POINT(" and ")" stuff. If there
+     *            acutally is a POINTM prefix, this overrides the given value.
+     *            However, POINT does not set it to false, as they can be
+     *            contained in measured collections, as in
+     *            "GEOMETRYCOLLECTIONM(POINT(0 0 0))".
+     */
+    protected Point(String value, boolean haveM) throws SQLException {
         this();
         value = value.trim();
-        if (value.indexOf("POINT") == 0) {
+        if (value.indexOf("POINTM") == 0) {
+            haveM = true;
+            value = value.substring(6).trim();
+        } else if (value.indexOf("POINT") == 0) {
             value = value.substring(5).trim();
         }
         PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ' ');
         try {
-            if (t.getSize() == 3) {
-                x = Double.valueOf(t.getToken(0)).doubleValue();
-                y = Double.valueOf(t.getToken(1)).doubleValue();
+            x = Double.valueOf(t.getToken(0)).doubleValue();
+            y = Double.valueOf(t.getToken(1)).doubleValue();
+            haveM |= t.getSize() == 4;
+            if ((t.getSize() == 3 && !haveM) || (t.getSize() == 4)) {
                 z = Double.valueOf(t.getToken(2)).doubleValue();
                 dimension = 3;
             } else {
-                x = Double.valueOf(t.getToken(0)).doubleValue();
-                y = Double.valueOf(t.getToken(1)).doubleValue();
-                z = 0.0;
                 dimension = 2;
             }
+            if (haveM) {
+                m = Double.valueOf(t.getToken(dimension)).doubleValue();
+            }
         } catch (NumberFormatException e) {
             throw new SQLException("postgis.Point" + e.toString());
         }
+        haveMeasure = haveM;
     }
 
     public void innerWKT(StringBuffer sb) {
index 9474be3d6b303bb452c7d852903de5a03725eb38..8166d098f38b6d379f9bea2e29cb7387840246ce 100644 (file)
@@ -48,22 +48,32 @@ public abstract class PointComposedGeom extends ComposedGeom {
     }
 
     public PointComposedGeom(int type, String value) throws SQLException {
+        this(type, value, false);
+    }
+    public PointComposedGeom(int type, String value, boolean haveM) throws SQLException {
         this(type);
         value = value.trim();
         if (value.indexOf(typestring) == 0) {
-            value = value.substring(typestring.length()).trim();
+            int pfxlen = typestring.length();
+            if (value.charAt(pfxlen)=='M') {
+                pfxlen += 1;
+                haveM=true;
+            }
+            value = value.substring(pfxlen).trim();
         }
         if (value.charAt(0) == '(') {
             PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
             int npoints = t.getSize();
             subgeoms = new Point[npoints];
             for (int p = 0; p < npoints; p++) {
-                subgeoms[p] = new Point(t.getToken(p));
+                subgeoms[p] = new Point(t.getToken(p), haveM);                
             }
             dimension = subgeoms[0].dimension;
+            haveM |= subgeoms[0].haveMeasure;
         } else {
             throw new SQLException("postgis.multipointgeometry");
         }
+        this.haveMeasure = haveM;
     }
 
     protected void innerWKT(StringBuffer sb) {
index cef88dcec5a5a3acfd5a6a4848d6c9a449206d66..9269321faad3a1e60cf5e2c53523128df66b37e6 100644 (file)
@@ -41,18 +41,30 @@ public class Polygon extends ComposedGeom {
     }
 
     public Polygon(String value) throws SQLException {
+        this(value, false);
+    }
+    
+    public Polygon(String value, boolean haveM) throws SQLException{
         this();
         value = value.trim();
-        if (value.indexOf("POLYGON") == 0) {
-            value = value.substring(7).trim();
+        if (value.indexOf(typestring) == 0) {
+            int pfxlen = typestring.length();
+            if (value.charAt(pfxlen) == 'M') {
+                pfxlen += 1;
+                haveM = true;
+            }
+            value = value.substring(pfxlen).trim();
         }
         PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
         int nrings = t.getSize();
         subgeoms = new LinearRing[nrings];
         for (int r = 0; r < nrings; r++) {
-            subgeoms[r] = new LinearRing(t.getToken(r));
+            subgeoms[r] = new LinearRing(t.getToken(r), haveM);
         }
         dimension = subgeoms[0].dimension;
+        // fetch haveMeasure from subpoint because haveM does only work with
+        // 2d+M, not with 3d+M geometries
+        this.haveMeasure = subgeoms[0].haveMeasure;
     }
 
     public int numRings() {
index c852f1cf7227553ab735e8b04175d200b453b5e7..e4541d7f85ee36fb7d8051095ad9647abc9fa8b3 100644 (file)
@@ -2,8 +2,6 @@ Todo for PostGIS 1.0 compatible JDBC classes
 
 - Testing
 
-- WKT parsing of M and 4d geometries
-
 - Handling of length() - esp. with modifying the geometries
 
 - Handling of hashCode() - esp. with modifying the geometries