org.geotools.data.postgis.attributeio
Class WKBEncoder

java.lang.Object
  extended byorg.geotools.data.postgis.attributeio.WKBEncoder
All Implemented Interfaces:
org.wkb4j.engine.WKBGeometryTypes

public class WKBEncoder
extends java.lang.Object
implements org.wkb4j.engine.WKBGeometryTypes

This class is a JTS <->WKB converter that will convert JTS Geometry objects into Strings of hexadecimal characters that represent their Well Known Binary (WKB) equivalents.

For example, in a Postgres database with PostGIS capabilities, the following statements can be executed:

 
  
    select asbinary('POINT(1 1)'::geometry, 'XDR');
                     asbinary                  
    --------------------------------------------
     00000000013FF00000000000003FF0000000000000
    (1 row)
   
    select geomfromwkb('00000000013FF00000000000003FF0000000000000'::wkb);
        geomfromwkb    
    -------------------
     SRID=0;POINT(1 1)
    (1 row)
   
  
 

The WKBParser#WKB2Geometry(String) method will create a new JTS POINT object when passed "00000000013FF00000000000003FF0000000000000" as a parameter. Further, the WKBParser#Geometry2WKB(Geometry) method will create the string "00000000013FF00000000000003FF0000000000000" when passed a JTS POINT(1 1) geometry object.

Note: when using PostGIS's asbinary(...) method, use 'XDR' as a parameter to use BigEndian format in the WKB representation.


Field Summary
 
Fields inherited from interface org.wkb4j.engine.WKBGeometryTypes
linearRing, wkbGeometryCollection, wkbLineString, wkbMultiLineString, wkbMultiPoint, wkbMultiPolygon, wkbPoint, wkbPolygon
 
Constructor Summary
WKBEncoder()
           
 
Method Summary
static java.lang.String bytesToString(byte[] bytes)
          This method will convert a byte[] to a string of hex characters that represent the byte[]
static byte[] encodeGeometry(com.vividsolutions.jts.geom.Geometry geom)
          This method will convert a JTS Geometry to a an array of bytes that represent Well Known Binary representation of the geometry object in big endian encoding.
static java.lang.String encodeGeometryHex(com.vividsolutions.jts.geom.Geometry geom)
          This method will convert a JTS Geometry to a string of hex characters that represent Well Known Binary representation of the geometry object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WKBEncoder

public WKBEncoder()
Method Detail

encodeGeometry

public static byte[] encodeGeometry(com.vividsolutions.jts.geom.Geometry geom)
                             throws java.io.IOException
This method will convert a JTS Geometry to a an array of bytes that represent Well Known Binary representation of the geometry object in big endian encoding.

Parameters:
geom - - a standard JTS geometry subclass, custom extensions are not supported
Returns:
a byte array that represent the Well Know Binary representation of the param geom in big endian encoding.
Throws:
java.io.IOException - if an I/O error occurs with the data output stream

encodeGeometryHex

public static java.lang.String encodeGeometryHex(com.vividsolutions.jts.geom.Geometry geom)
                                          throws java.io.IOException
This method will convert a JTS Geometry to a string of hex characters that represent Well Known Binary representation of the geometry object.

Parameters:
geom - Either Point, LineString, Polygon, MultiPoint, MultiLineString, or MultiPolygon
Returns:
a String of characters that represent the Well Know Binary representation of the param geom. In particular, each character is a value of 0-9, A, B ,C, D, E, or F.
Throws:
java.lang.Exception - if an I/O error occurs with the EndianDataOutputStream or the parser doesn't have any implementation for the specifed Geometry.
java.io.IOException

bytesToString

public static java.lang.String bytesToString(byte[] bytes)
This method will convert a byte[] to a string of hex characters that represent the byte[]

Parameters:
bytes - an array of bytes
Returns:
a String that represents the byte[]. In particular, each character has a value of 0-9, A, B, C, D, E, or F. The characters can be read by grouping them by pairs (ie. the first two characters represent the first byte in the array).


Copyright © GeoTools. All Rights Reserved.