Top Description Inners Fields Constructors Methods
org.h2.util.geometry

public final Class EWKBUtils

extends Object
Class Inheritance
Static Imports
org.h2.util.Bits.DOUBLE_VH_BE, .Bits.DOUBLE_VH_LE, .Bits.INT_VH_BE, .Bits.INT_VH_LE, org.h2.util.geometry.GeometryUtils.DIMENSION_SYSTEM_XYM, .GeometryUtils.DIMENSION_SYSTEM_XYZ, .GeometryUtils.DIMENSION_SYSTEM_XYZM, .GeometryUtils.GEOMETRY_COLLECTION, .GeometryUtils.LINE_STRING, .GeometryUtils.MAX_X, .GeometryUtils.MAX_Y, .GeometryUtils.MIN_X, .GeometryUtils.MIN_Y, .GeometryUtils.MULTI_LINE_STRING, .GeometryUtils.MULTI_POINT, .GeometryUtils.MULTI_POLYGON, .GeometryUtils.POINT, .GeometryUtils.POLYGON, .GeometryUtils.checkFinite, .GeometryUtils.toCanonicalDouble

EWKB format support for GEOMETRY data type.

This class provides limited support of EWKB. EWKB is based on Well-known Binary Representation (WKB) from OGC 06-103r4 and includes additional PostGIS extensions. This class can read dimension system marks in both OGC WKB and EWKB formats, but always writes them in EWKB format. SRID support from EWKB is implemented. As an addition POINT EMPTY is stored with NaN values as specified in OGC 12-128r15.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
EWKBUtils.EWKBSource

Helper source object for EWKB reading.

public static class
EWKBUtils.EWKBTarget

Converter output target that writes a EWKB.

Field Summary

Modifier and TypeField and Description
public static final int
EWKB_M

Geometry type mask that indicates presence of dimension M.

public static final int
EWKB_SRID

Geometry type mask that indicates presence of SRID.

public static final int
EWKB_Z

Geometry type mask that indicates presence of dimension Z.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
addCoordinate(EWKBUtils.EWKBSource source, GeometryUtils.Target target, boolean useZ, boolean useM, int index, int total)

private static void
addRing(EWKBUtils.EWKBSource source, GeometryUtils.Target target, boolean useZ, boolean useM, int size)

public static byte[]

Returns:

WKB, or null
envelope2wkb
(double[]
envelope, or null
envelope
)

Converts an envelope to a WKB.

public static byte[]

Returns:

canonical EWKB, may be the same as the source
ewkb2ewkb
(byte[]
source EWKB
ewkb
)

Converts any supported EWKB to EWKB representation that is used by this class.

public static byte[]

Returns:

canonical EWKB, may be the same as the source
ewkb2ewkb
(byte[]
source EWKB
ewkb
,
int
dimension system
dimensionSystem
)

Converts any supported EWKB to EWKB representation that is used by this class.

public static int

Returns:

the dimension system
getDimensionSystem
(byte[]
EWKB
ewkb
)

Reads the dimension system from EWKB.

public static void
parseEWKB(byte[]
EWKB representation
ewkb
,
GeometryUtils.Target
output target
target
)

Parses a EWKB.

private static void
parseEWKB(EWKBUtils.EWKBSource
EWKB source
source
,
GeometryUtils.Target
output target
target
,
int
type of parent geometry collection, or 0 for the root geometry
parentType
)

Parses a EWKB.

public static int

Returns:

dimension system
type2dimensionSystem
(int
geometry type with flags
type
)

Converts geometry type with flags to a dimension system.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EWKB_Mback to summary
public static final int EWKB_M

Geometry type mask that indicates presence of dimension M.

EWKB_SRIDback to summary
public static final int EWKB_SRID

Geometry type mask that indicates presence of SRID.

EWKB_Zback to summary
public static final int EWKB_Z

Geometry type mask that indicates presence of dimension Z.

Constructor Detail

EWKBUtilsback to summary
private EWKBUtils()

Method Detail

addCoordinateback to summary
private static void addCoordinate(EWKBUtils.EWKBSource source, GeometryUtils.Target target, boolean useZ, boolean useM, int index, int total)
addRingback to summary
private static void addRing(EWKBUtils.EWKBSource source, GeometryUtils.Target target, boolean useZ, boolean useM, int size)
envelope2wkbback to summary
public static byte[] envelope2wkb(double[] envelope)

Converts an envelope to a WKB.

Parameters
envelope:double[]

envelope, or null

Returns:byte[]

WKB, or null

ewkb2ewkbback to summary
public static byte[] ewkb2ewkb(byte[] ewkb)

Converts any supported EWKB to EWKB representation that is used by this class. Reduces dimension system to minimal possible and uses EWKB flags for dimension system indication. May also perform other changes.

Parameters
ewkb:byte[]

source EWKB

Returns:byte[]

canonical EWKB, may be the same as the source

ewkb2ewkbback to summary
public static byte[] ewkb2ewkb(byte[] ewkb, int dimensionSystem)

Converts any supported EWKB to EWKB representation that is used by this class. Reduces dimension system to minimal possible and uses EWKB flags for dimension system indication. May also perform other changes.

Parameters
ewkb:byte[]

source EWKB

dimensionSystem:int

dimension system

Returns:byte[]

canonical EWKB, may be the same as the source

getDimensionSystemback to summary
public static int getDimensionSystem(byte[] ewkb)

Reads the dimension system from EWKB.

Parameters
ewkb:byte[]

EWKB

Returns:int

the dimension system

parseEWKBback to summary
public static void parseEWKB(byte[] ewkb, GeometryUtils.Target target)

Parses a EWKB.

Parameters
ewkb:byte[]

EWKB representation

target:GeometryUtils.Target

output target

parseEWKBback to summary
private static void parseEWKB(EWKBUtils.EWKBSource source, GeometryUtils.Target target, int parentType)

Parses a EWKB.

Parameters
source:EWKBUtils.EWKBSource

EWKB source

target:GeometryUtils.Target

output target

parentType:int

type of parent geometry collection, or 0 for the root geometry

type2dimensionSystemback to summary
public static int type2dimensionSystem(int type)

Converts geometry type with flags to a dimension system.

Parameters
type:int

geometry type with flags

Returns:int

dimension system

org.h2.util.geometry back to summary

private final Class EWKBUtils.EWKBSource

extends Object
Class Inheritance

Helper source object for EWKB reading.

Field Summary

Modifier and TypeField and Description
pack-priv boolean
bigEndian

Whether current byte order is big-endian.

private final byte[]
private int

Constructor Summary

AccessConstructor and Description
pack-priv
EWKBSource(byte[]
EWKB
ewkb
)

Creates new instance of EWKB source.

Method Summary

Modifier and TypeMethod and Description
pack-priv byte

Returns:

next byte
readByte
()

Reads one byte.

pack-priv double

Returns:

next 64-bit floating point
readCoordinate
()

Reads a 64-bit floating point using current byte order.

pack-priv int

Returns:

next 32-bit integer
readInt
()

Reads a 32-bit integer using current byte order.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

bigEndianback to summary
pack-priv boolean bigEndian

Whether current byte order is big-endian.

ewkbback to summary
private final byte[] ewkb
offsetback to summary
private int offset

Constructor Detail

EWKBSourceback to summary
pack-priv EWKBSource(byte[] ewkb)

Creates new instance of EWKB source.

Parameters
ewkb:byte[]

EWKB

Method Detail

readByteback to summary
pack-priv byte readByte()

Reads one byte.

Returns:byte

next byte

readCoordinateback to summary
pack-priv double readCoordinate()

Reads a 64-bit floating point using current byte order.

Returns:double

next 64-bit floating point

readIntback to summary
pack-priv int readInt()

Reads a 32-bit integer using current byte order.

Returns:int

next 32-bit integer

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.h2.util.geometry back to summary

public final Class EWKBUtils.EWKBTarget

extends Target
Class Inheritance

Converter output target that writes a EWKB.

Field Summary

Modifier and TypeField and Description
private final byte[]
private final int
private final ByteArrayOutputStream
private int
private int

Constructor Summary

AccessConstructor and Description
public
EWKBTarget(ByteArrayOutputStream
output stream
output
,
int
dimension system to use
dimensionSystem
)

Creates a new EWKB output target.

Method Summary

Modifier and TypeMethod and Description
protected void
addCoordinate(double
X coordinate
x
,
double
Y coordinate
y
,
double
Z coordinate (NaN if not used)
z
,
double
M coordinate (NaN if not used)
m
,
int
0-based index of coordinate in the current sequence
index
,
int
total number of coordinates in the current sequence
total
)

Implements abstract org.h2.util.geometry.GeometryUtils.Target.addCoordinate.

Invoked to add a coordinate to a geometry.

protected void
init(int
SRID
srid
)

Overrides org.h2.util.geometry.GeometryUtils.Target.init.

Initializes top-level target.

protected void
startCollection(int type, int
number of items in this collection
numItems
)

Overrides org.h2.util.geometry.GeometryUtils.Target.startCollection.

Invoked before writing of a collection.

protected GeometryUtils.Target
startCollectionItem(int
0-based index of this item in the collection
index
,
int
total number of items in the collection
total
)

Overrides org.h2.util.geometry.GeometryUtils.Target.startCollectionItem.

Invoked before writing of a collection item.

protected void
startLineString(int
number of points in line string
numPoints
)

Overrides org.h2.util.geometry.GeometryUtils.Target.startLineString.

Invoked before writing a LINESTRING.

protected void
startPoint()

Overrides org.h2.util.geometry.GeometryUtils.Target.startPoint.

Invoked before writing a POINT.

protected void
startPolygon(int
number of inner polygons
numInner
,
int
number of points in outer polygon
numPoints
)

Overrides org.h2.util.geometry.GeometryUtils.Target.startPolygon.

Invoked before writing a POLYGON.

protected void
startPolygonInner(int
number of points in inner polygon
numInner
)

Overrides org.h2.util.geometry.GeometryUtils.Target.startPolygonInner.

Invoked before writing an inner polygon in POLYGON.

private void
writeDouble(double v)

private void
writeHeader(int type)

private void
writeInt(int v)

Inherited from org.h2.util.geometry.GeometryUtils.Target:
dimensionSystemendCollectionItemendNonEmptyPolygonendObject

Field Detail

bufback to summary
private final byte[] buf
dimensionSystemback to summary
private final int dimensionSystem
outputback to summary
private final ByteArrayOutputStream output
sridback to summary
private int srid
typeback to summary
private int type

Constructor Detail

EWKBTargetback to summary
public EWKBTarget(ByteArrayOutputStream output, int dimensionSystem)

Creates a new EWKB output target.

Parameters
output:ByteArrayOutputStream

output stream

dimensionSystem:int

dimension system to use

Method Detail

addCoordinateback to summary
protected void addCoordinate(double x, double y, double z, double m, int index, int total)

Implements abstract org.h2.util.geometry.GeometryUtils.Target.addCoordinate.

Doc from org.h2.util.geometry.GeometryUtils.Target.addCoordinate.

Invoked to add a coordinate to a geometry.

Parameters
x:double

X coordinate

y:double

Y coordinate

z:double

Z coordinate (NaN if not used)

m:double

M coordinate (NaN if not used)

index:int

0-based index of coordinate in the current sequence

total:int

total number of coordinates in the current sequence

Annotations
@Override
initback to summary
protected void init(int srid)

Overrides org.h2.util.geometry.GeometryUtils.Target.init.

Doc from org.h2.util.geometry.GeometryUtils.Target.init.

Initializes top-level target.

Parameters
srid:int

SRID

Annotations
@Override
startCollectionback to summary
protected void startCollection(int type, int numItems)

Overrides org.h2.util.geometry.GeometryUtils.Target.startCollection.

Doc from org.h2.util.geometry.GeometryUtils.Target.startCollection.

Invoked before writing of a collection.

Parameters
type:int

type of collection, one of GeometryUtils#MULTI_POINT, GeometryUtils#MULTI_LINE_STRING, GeometryUtils#MULTI_POLYGON, GeometryUtils#GEOMETRY_COLLECTION

numItems:int

number of items in this collection

Annotations
@Override
startCollectionItemback to summary
protected GeometryUtils.Target startCollectionItem(int index, int total)

Overrides org.h2.util.geometry.GeometryUtils.Target.startCollectionItem.

Doc from org.h2.util.geometry.GeometryUtils.Target.startCollectionItem.

Invoked before writing of a collection item.

Parameters
index:int

0-based index of this item in the collection

total:int

total number of items in the collection

Returns:GeometryUtils.Target

output target that should be used for processing of this collection item. May return this target or an custom sub-target.

Annotations
@Override
startLineStringback to summary
protected void startLineString(int numPoints)

Overrides org.h2.util.geometry.GeometryUtils.Target.startLineString.

Doc from org.h2.util.geometry.GeometryUtils.Target.startLineString.

Invoked before writing a LINESTRING.

Parameters
numPoints:int

number of points in line string

Annotations
@Override
startPointback to summary
protected void startPoint()

Overrides org.h2.util.geometry.GeometryUtils.Target.startPoint.

Doc from org.h2.util.geometry.GeometryUtils.Target.startPoint.

Invoked before writing a POINT.

Annotations
@Override
startPolygonback to summary
protected void startPolygon(int numInner, int numPoints)

Overrides org.h2.util.geometry.GeometryUtils.Target.startPolygon.

Doc from org.h2.util.geometry.GeometryUtils.Target.startPolygon.

Invoked before writing a POLYGON. If polygon is empty, both parameters are 0.

Parameters
numInner:int

number of inner polygons

numPoints:int

number of points in outer polygon

Annotations
@Override
startPolygonInnerback to summary
protected void startPolygonInner(int numInner)

Overrides org.h2.util.geometry.GeometryUtils.Target.startPolygonInner.

Doc from org.h2.util.geometry.GeometryUtils.Target.startPolygonInner.

Invoked before writing an inner polygon in POLYGON.

Parameters
numInner:int

number of points in inner polygon

Annotations
@Override
writeDoubleback to summary
private void writeDouble(double v)
writeHeaderback to summary
private void writeHeader(int type)
writeIntback to summary
private void writeInt(int v)