]> granicus.if.org Git - postgis/commitdiff
Convert java components to SRID<=0 being unknown and 0 being the official one [#1221]
authorSandro Santilli <strk@keybit.net>
Tue, 20 Dec 2011 19:35:35 +0000 (19:35 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 20 Dec 2011 19:35:35 +0000 (19:35 +0000)
NOTE: this is untested, as "make" didn't know what to do and so neither do I

git-svn-id: http://svn.osgeo.org/postgis/trunk@8481 b70326c6-7e19-0410-871a-916f4a2858ee

java/jdbc/jtssrc/org/postgis/jts/JtsBinaryParser.java
java/jdbc/jtssrc/org/postgis/jts/JtsBinaryWriter.java
java/jdbc/src/org/postgis/Geometry.java
java/jdbc/src/org/postgis/PGboxbase.java
java/jdbc/src/org/postgis/PGgeometry.java
java/jdbc/src/org/postgis/binary/BinaryParser.java
java/jdbc/src/org/postgis/binary/BinaryWriter.java
java/jdbc/src/org/postgis/java2d/PGShapeGeometry.java
java/jdbc/src/org/postgis/java2d/ShapeBinaryParser.java
java/pljava/src/org/postgis/pljava/PLJtsParser.java
java/pljava/src/org/postgis/pljava/PLJtsWriter.java

index b7edf4d1fa649726fc255e8f44eb4039311a56d4..5718d9ec928e16eb0e400facd2d94807f397dac4 100644 (file)
@@ -102,14 +102,14 @@ public class JtsBinaryParser {
         boolean haveS = (typeword & 0x20000000) != 0;
 
         if (haveS) {
-            int newsrid = data.getInt();
+            int newsrid = Geometry.parseSRID(data.getInt());
             if (inheritSrid && newsrid != srid) {
                 throw new IllegalArgumentException("Inconsistent srids in complex geometry: " + srid + ", " + newsrid);
             } else {
                 srid = newsrid;
             }
         } else if (!inheritSrid) {
-            srid = -1;
+            srid = Geometry.UNKNOWN_SRID;
         }
        
         Geometry result;
index 74b3c927092ff313ce806ee009d47710e4f6f246..b77c51f4a6e2f2319605a9c427d967cb4f80f178 100644 (file)
@@ -297,8 +297,7 @@ public class JtsBinaryWriter {
 
     private boolean checkSrid(Geometry geom) {
         final int srid = geom.getSRID();
-        // SRID is default 0 with jts geometries
-        return (srid != -1) && (srid != 0);
+        return (srid > 0);
     }
 
     private int estimatePoint(Point geom) {
index de139003071850e8779d24afe50fa797b2cdd37c..bcca446b44d319bd9cb985230fdc82f1cb1e2d0d 100644 (file)
@@ -113,9 +113,25 @@ public abstract class Geometry implements Serializable {
     public final int type;
 
     /**
-     * The spacial reference system id of this geometry, default (no srid) is -1
+     * Official UNKNOWN srid value 
      */
-    public int srid = -1;
+    public final final int UNKNOWN_SRID = 0;
+
+    /**
+     * The spacial reference system id of this geometry, default is no srid 
+     */
+    public int srid = UNKNOWN_SRID;
+
+    /**
+     * Parse a SRID value, anything <= 0 is unknown
+     */
+    public static int parseSRID(int srid) {
+        if ( srid < 0 ) {
+            /* TODO: raise a warning ? */
+            srid = 0;
+        }
+        return srid;
+    }
 
     /**
      * Constructor for subclasses
@@ -232,7 +248,7 @@ public abstract class Geometry implements Serializable {
 
     public String toString() {
         StringBuffer sb = new StringBuffer();
-        if (srid != -1) {
+        if (srid != UNKNOWN_SRID) {
             sb.append("SRID=");
             sb.append(srid);
             sb.append(';');
index 5766555eba10c76b7735eab2d899b4c0d3c0089b..10aeaae71da3a5a25e87882695c45c1ca3a1d0c5 100644 (file)
@@ -81,12 +81,12 @@ public abstract class PGboxbase extends PGobject {
     }
 
     public void setValue(String value) throws SQLException {
-        int srid = -1;
+        int srid = Geometry.UNKNOWN_SRID;
         value = value.trim();
         if (value.startsWith("SRID=")) {
             String[] temp = PGgeometry.splitSRID(value);
             value = temp[1].trim();
-            srid = Integer.parseInt(temp[0].substring(5));
+            srid = Geometry.parseSRID(Integer.parseInt(temp[0].substring(5)));
         }
         String myPrefix = getPrefix();
         if (value.startsWith(myPrefix)) {
@@ -95,7 +95,7 @@ public abstract class PGboxbase extends PGobject {
         PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(value), ',');
         llb = new Point(t.getToken(0));
         urt = new Point(t.getToken(1));
-        if (srid != -1) {
+        if (srid != Geometry.UNKNOWN_SRID) {
             llb.setSrid(srid);
             urt.setSrid(srid);
         }
index 4f877d91ef79928b8473c4b533454cf0aca95d34..db0000ee18d357a99040a3d999e87515b676d35c 100644 (file)
@@ -77,13 +77,13 @@ public class PGgeometry extends PGobject {
             throws SQLException {
         value = value.trim();
 
-        int srid = -1;
+        int srid = Geometry.UNKNOWN_SRID;
 
         if (value.startsWith(SRIDPREFIX)) {
             // break up geometry into srid and wkt
             String[] parts = PGgeometry.splitSRID(value);
             value = parts[1].trim();
-            srid = Integer.parseInt(parts[0].substring(5));
+            srid = Geometry.parseSRID(Integer.parseInt(parts[0].substring(5)));
         }
 
         Geometry result;
@@ -111,7 +111,7 @@ public class PGgeometry extends PGobject {
             throw new SQLException("Unknown type: " + value);
         }
 
-        if (srid != -1) {
+        if (srid != Geometry.UNKNOWN_SRID) {
             result.srid = srid;
         }
 
index 3454a213ecdb66bed6c3ff07a529d7dd867de47b..255e1a9b445e7c42b16a5fdabfdc21961dfd2586 100644 (file)
@@ -104,10 +104,10 @@ public class BinaryParser {
         boolean haveM = (typeword & 0x40000000) != 0;
         boolean haveS = (typeword & 0x20000000) != 0;
 
-        int srid = -1;
+        int srid = Geometry.UNKNOWN_SRID;
 
         if (haveS) {
-            srid = data.getInt();
+            srid = Geometry.parseSRID(data.getInt());
         }
         Geometry result1;
         switch (realtype) {
@@ -138,7 +138,7 @@ public class BinaryParser {
 
         Geometry result = result1;
 
-        if (haveS) {
+        if (srid != Geometry.UNKONWN_SRID) {
             result.setSrid(srid);
         }
         return result;
index cf136b6bed31bd21d07bfbf36209fe3d0eda1906..c9b56cec16777fc39bcb6b7fbc821650793ec236 100644 (file)
@@ -126,13 +126,13 @@ public class BinaryWriter {
         if (geom.haveMeasure) {
             typeword |= 0x40000000;
         }
-        if (geom.srid != -1) {
+        if (geom.srid != Geometry.UNKNOWN_SRID) {
             typeword |= 0x20000000;
         }
 
         dest.setInt(typeword);
 
-        if (geom.srid != -1) {
+        if (geom.srid != Geometry.UNKNOWN_SRID) {
             dest.setInt(geom.srid);
         }
 
@@ -244,7 +244,7 @@ public class BinaryWriter {
         // write typeword
         result += 4;
 
-        if (geom.srid != -1) {
+        if (geom.srid != Geometry.UNKNOWN_SRID) {
             result += 4;
         }
 
index 1f2ee20aff5478f3af3836cd5ac2950df8d7d4e8..327ffd911e9a557a60234d46e0ca1415961e92d9 100644 (file)
@@ -118,7 +118,7 @@ public class PGShapeGeometry extends PGobject implements Shape {
         return false;
     }
 
-    /** Return the SRID or -1 if none was available */
+    /** Return the SRID or Geometry.UNKNOWN_SRID if none was available */
     public int getSRID() {
         return srid;
     }
index 783634d24efae9cbb0dcd8bd83afc0aae30013ef..73c8979652349fad6bf1ad8ac9b93a835998843f 100644 (file)
@@ -70,7 +70,7 @@ public class ShapeBinaryParser {
      * Is synchronized to protect offset counter. (Unfortunately, Java does not
      * have neither call by reference nor multiple return values.)
      * 
-     * @return a potential SRID or -1 if not present
+     * @return a potential SRID or Geometry.UNKNOWN_SRID if not present
      */
     public synchronized int parse(String value, GeneralPath path) {
         StringByteGetter bytes = new ByteGetter.StringByteGetter(value);
@@ -83,7 +83,7 @@ public class ShapeBinaryParser {
      * Is synchronized to protect offset counter. (Unfortunately, Java does not
      * have neither call by reference nor multiple return values.)
      * 
-     * @return a potential SRID or -1 if not present
+     * @return a potential SRID or Geometry.UNKNOWN_SRID if not present
      */
     public synchronized int parse(byte[] value, GeneralPath path) {
         BinaryByteGetter bytes = new ByteGetter.BinaryByteGetter(value);
@@ -108,10 +108,10 @@ public class ShapeBinaryParser {
         boolean haveM = (typeword & 0x40000000) != 0;
         boolean haveS = (typeword & 0x20000000) != 0;
 
-        int srid = -1;
+        int srid = Geometry.UNKNOWN_SRID;
 
         if (haveS) {
-            srid = data.getInt();
+            srid = Geometry.parseSRID(data.getInt());
         }
 
         switch (realtype) {
index db535095f48d7f87a27178db38426cbd938ce381..7496197df0802ec113b930d1cce3096a05221297 100644 (file)
@@ -91,7 +91,7 @@ public class PLJtsParser {
                 srid = newsrid;
             }
         } else if (!inheritSrid) {
-            srid = -1;
+            srid = Geometry.UNKNOWN_SRID;
         }
        
         Geometry result;
index d2ec8100f89bf87c444794e731c2166682c314b2..c830295338793bf7dad1f4dbebd07cb4267edd2c 100644 (file)
@@ -240,7 +240,7 @@ public class PLJtsWriter {
     private boolean checkSrid(Geometry geom) {
         final int srid = geom.getSRID();
         // SRID is default 0 with jts geometries
-        return (srid != -1) && (srid != 0);
+        return (srid > 0); 
     }
 
     private int estimatePoint(Point geom) {