I've got a patch that allows direct selection of a PostGis geometry
column without needing to use ST_AsBinary() to get past that "unknown
WKB type 48" error.  The patch also supports continued use of
ST_AsBinary.   Can someone commit the patch for me or give me write
access to the repository?

Thanks.............                lreeder

Patch below:

Index: datastore/postgis/PostgisValueConverterFactory.java
===================================================================
--- datastore/postgis/PostgisValueConverterFactory.java (revision 2241)
+++ datastore/postgis/PostgisValueConverterFactory.java (working copy)
@@ -69,8 +69,36 @@
         throws IOException, SQLException, ParseException
     {
       byte[] bytes = rs.getBytes(columnIndex);
-      if (bytes == null) return wktReader.read("GEOMETRYCOLLECTION EMPTY");
-      else return wkbReader.read(bytes);
+
+      //so rs.getBytes will be one of two things:
+      //1. The actual bytes of the WKB if someone did ST_AsBinary
+      //2. The bytes of hex representation of the WKB.
+
+      //in the case of #1, according to the WKB spec, the byte value
+      //can only be 0 or 1.
+      //in the case of #2, it's a hex string, so values range from ascii 0-F
+      //use this logic to determine how to process the bytes.
+
+      Geometry geometry = null;
+      if(bytes == null || bytes.length <= 0)
+      {
+         geometry = wktReader.read("GEOMETRYCOLLECTION EMPTY");
+      }
+      else
+      {
+          //assume it's the actual bytes (from ST_AsBinary)
+          byte[] realWkbBytes = bytes;
+          if(bytes[0] >= '0')
+          {
+              //ok, it's hex, convert hex string to actual bytes
+              String hexString = new String(bytes);
+              realWkbBytes = WKBReader.hexToBytes(hexString);
+          }
+
+          geometry = wkbReader.read(realWkbBytes);
+      }
+
+      return geometry;
     }
   }
 }

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to