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

public final Class EWKTUtils

extends Object
Class Inheritance
Static Imports
org.h2.util.geometry.GeometryUtils.DIMENSION_SYSTEM_XY, .GeometryUtils.DIMENSION_SYSTEM_XYM, .GeometryUtils.DIMENSION_SYSTEM_XYZ, .GeometryUtils.DIMENSION_SYSTEM_XYZM, .GeometryUtils.GEOMETRY_COLLECTION, .GeometryUtils.LINE_STRING, .GeometryUtils.M, .GeometryUtils.MULTI_LINE_STRING, .GeometryUtils.MULTI_POINT, .GeometryUtils.MULTI_POLYGON, .GeometryUtils.POINT, .GeometryUtils.POLYGON, .GeometryUtils.X, .GeometryUtils.Y, .GeometryUtils.Z

EWKT format support for GEOMETRY data type.

This class provides limited support of EWKT. EWKT is based on Well-known Text Representation (WKT) from OGC 06-103r4 and includes additional PostGIS extensions. SRID support from EWKT is implemented.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
EWKTUtils.EWKTSource

Helper source object for EWKT reading.

public static class
EWKTUtils.EWKTTarget

Converter output target that writes a EWKT.

Field Summary

Modifier and TypeField and Description
private static final String[]
DIMENSION_SYSTEMS

Names of dimension systems.

pack-priv static final String[]
TYPES

0-based type names of geometries, subtract 1 from type code to get index in this array.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
addCoordinate(EWKTUtils.EWKTSource source, GeometryUtils.Target target, int dimensionSystem, int index, int total)

private static void
addRing(ArrayList<double[]> ring, GeometryUtils.Target target)

public static String

Returns:

EWKT representation
ewkb2ewkt
(byte[]
source EWKB
ewkb
)

Converts EWKB to EWKT.

public static String

Returns:

EWKT representation
ewkb2ewkt
(byte[]
source EWKB
ewkb
,
int
dimension system
dimensionSystem
)

Converts EWKB to EWKT.

public static byte[]

Returns:

EWKB representation
ewkt2ewkb
(String
source EWKT
ewkt
)

Converts EWKT to EWKB.

public static byte[]

Returns:

EWKB representation
ewkt2ewkb
(String
source EWKT
ewkt
,
int
dimension system
dimensionSystem
)

Converts EWKT to EWKB.

public static StringBuilder

Returns:

the specified string builder
formatGeometryTypeAndDimensionSystem
(StringBuilder
string builder
builder
,
int
OGC geometry code format (type + dimensionSystem * 1000)
type
)

Formats type and dimension system as a string.

public static int

Returns:

the dimension system
getDimensionSystem
(String
EWKT source
ewkt
)

Reads the dimension system from EWKT.

private static void
parseCollection(EWKTUtils.EWKTSource source, GeometryUtils.Target target, int type, int parentType, int dimensionSystem)

public static int

Returns:

dimension system, one of XYZ, XYM, or XYZM
parseDimensionSystem
(String
string to parse
s
)

Parses a dimension system from the given string.

public static void
parseEWKT(String
source EWKT
ewkt
,
GeometryUtils.Target
output target
target
)

Parses a EWKT.

private static void
parseEWKT(EWKTUtils.EWKTSource
EWKT source
source
,
GeometryUtils.Target
output target
target
,
int
type of parent geometry collection, or 0 for the root geometry
parentType
,
int
dimension system of parent geometry
dimensionSystem
)

Parses a EWKB.

public static int

Returns:

geometry type and dimension system in OGC geometry code format (type + dimensionSystem * 1000)
parseGeometryType
(String
string to parse
s
)

Parses geometry type and dimension system from the given string.

private static void
private static double[]
readCoordinate(EWKTUtils.EWKTSource source, int dimensionSystem)

private static ArrayList<double[]>
readRing(EWKTUtils.EWKTSource source, int dimensionSystem)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DIMENSION_SYSTEMSback to summary
private static final String[] DIMENSION_SYSTEMS

Names of dimension systems.

TYPESback to summary
pack-priv static final String[] TYPES

0-based type names of geometries, subtract 1 from type code to get index in this array.

Constructor Detail

EWKTUtilsback to summary
private EWKTUtils()

Method Detail

addCoordinateback to summary
private static void addCoordinate(EWKTUtils.EWKTSource source, GeometryUtils.Target target, int dimensionSystem, int index, int total)
addRingback to summary
private static void addRing(ArrayList<double[]> ring, GeometryUtils.Target target)
ewkb2ewktback to summary
public static String ewkb2ewkt(byte[] ewkb)

Converts EWKB to EWKT.

Parameters
ewkb:byte[]

source EWKB

Returns:String

EWKT representation

ewkb2ewktback to summary
public static String ewkb2ewkt(byte[] ewkb, int dimensionSystem)

Converts EWKB to EWKT.

Parameters
ewkb:byte[]

source EWKB

dimensionSystem:int

dimension system

Returns:String

EWKT representation

ewkt2ewkbback to summary
public static byte[] ewkt2ewkb(String ewkt)

Converts EWKT to EWKB.

Parameters
ewkt:String

source EWKT

Returns:byte[]

EWKB representation

ewkt2ewkbback to summary
public static byte[] ewkt2ewkb(String ewkt, int dimensionSystem)

Converts EWKT to EWKB.

Parameters
ewkt:String

source EWKT

dimensionSystem:int

dimension system

Returns:byte[]

EWKB representation

formatGeometryTypeAndDimensionSystemback to summary
public static StringBuilder formatGeometryTypeAndDimensionSystem(StringBuilder builder, int type)

Formats type and dimension system as a string.

Parameters
builder:StringBuilder

string builder

type:int

OGC geometry code format (type + dimensionSystem * 1000)

Returns:StringBuilder

the specified string builder

Exceptions
IllegalArgumentException:
if type is not valid
getDimensionSystemback to summary
public static int getDimensionSystem(String ewkt)

Reads the dimension system from EWKT.

Parameters
ewkt:String

EWKT source

Returns:int

the dimension system

parseCollectionback to summary
private static void parseCollection(EWKTUtils.EWKTSource source, GeometryUtils.Target target, int type, int parentType, int dimensionSystem)
parseDimensionSystemback to summary
public static int parseDimensionSystem(String s)

Parses a dimension system from the given string.

Parameters
s:String

string to parse

Returns:int

dimension system, one of XYZ, XYM, or XYZM

Exceptions
IllegalArgumentException:
if input is not valid
See Also
GeometryUtils#DIMENSION_SYSTEM_XYZ, GeometryUtils#DIMENSION_SYSTEM_XYM, GeometryUtils#DIMENSION_SYSTEM_XYZM
parseEWKTback to summary
public static void parseEWKT(String ewkt, GeometryUtils.Target target)

Parses a EWKT.

Parameters
ewkt:String

source EWKT

target:GeometryUtils.Target

output target

parseEWKTback to summary
private static void parseEWKT(EWKTUtils.EWKTSource source, GeometryUtils.Target target, int parentType, int dimensionSystem)

Parses a EWKB.

Parameters
source:EWKTUtils.EWKTSource

EWKT source

target:GeometryUtils.Target

output target

parentType:int

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

dimensionSystem:int

dimension system of parent geometry

parseGeometryTypeback to summary
public static int parseGeometryType(String s)

Parses geometry type and dimension system from the given string.

Parameters
s:String

string to parse

Returns:int

geometry type and dimension system in OGC geometry code format (type + dimensionSystem * 1000)

Exceptions
IllegalArgumentException:
if input is not valid
parseMultiPointAlternativeback to summary
private static void parseMultiPointAlternative(EWKTUtils.EWKTSource source, GeometryUtils.Target target, int dimensionSystem)
readCoordinateback to summary
private static double[] readCoordinate(EWKTUtils.EWKTSource source, int dimensionSystem)
readRingback to summary
private static ArrayList<double[]> readRing(EWKTUtils.EWKTSource source, int dimensionSystem)
org.h2.util.geometry back to summary

private final Class EWKTUtils.EWKTSource

extends Object
Class Inheritance

Helper source object for EWKT reading.

Field Summary

Modifier and TypeField and Description
private final String
private int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
checkStringEnd(int len)

pack-priv int
public boolean
pack-priv boolean
public boolean
private static boolean
isNumberPart(char ch)

private static boolean
isNumberStart(char ch)

private int
match(String token, int code)

pack-priv void
read(char symbol)

public double
pack-priv int
pack-priv boolean
pack-priv int
pack-priv int
private void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

ewktback to summary
private final String ewkt
offsetback to summary
private int offset

Constructor Detail

EWKTSourceback to summary
pack-priv EWKTSource(String ewkt)

Method Detail

checkStringEndback to summary
private void checkStringEnd(int len)
getItemCountback to summary
pack-priv int getItemCount()
hasCoordinateback to summary
public boolean hasCoordinate()
hasDataback to summary
pack-priv boolean hasData()
hasMoreCoordinatesback to summary
public boolean hasMoreCoordinates()
isNumberPartback to summary
private static boolean isNumberPart(char ch)
isNumberStartback to summary
private static boolean isNumberStart(char ch)
matchback to summary
private int match(String token, int code)
readback to summary
pack-priv void read(char symbol)
readCoordinateback to summary
public double readCoordinate()
readDimensionSystemback to summary
pack-priv int readDimensionSystem()
readEmptyback to summary
pack-priv boolean readEmpty()
readSRIDback to summary
pack-priv int readSRID()
readTypeback to summary
pack-priv int readType()
skipWSback to summary
private void skipWS()
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 EWKTUtils.EWKTTarget

extends Target
Class Inheritance

Converter output target that writes a EWKT.

Field Summary

Modifier and TypeField and Description
private final int
private boolean
private final StringBuilder
private int

Constructor Summary

AccessConstructor and Description
public
EWKTTarget(StringBuilder
output stream
output
,
int
dimension system to use
dimensionSystem
)

Creates a new EWKT 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
endCollectionItem(GeometryUtils.Target target, int
type of collection
type
,
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.endCollectionItem.

Invoked after writing of a collection item.

protected void
endNonEmptyPolygon()

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

Invoked after writing of non-empty POLYGON.

protected void
endObject(int
type of the object
type
)

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

Invoked after writing of the object.

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)

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

Field Detail

dimensionSystemback to summary
private final int dimensionSystem
inMultiback to summary
private boolean inMulti
outputback to summary
private final StringBuilder output
typeback to summary
private int type

Constructor Detail

EWKTTargetback to summary
public EWKTTarget(StringBuilder output, int dimensionSystem)

Creates a new EWKT output target.

Parameters
output:StringBuilder

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
endCollectionItemback to summary
protected void endCollectionItem(GeometryUtils.Target target, int type, int index, int total)

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

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

Invoked after writing of a collection item. This method is invoked on the same target that was used for startCollectionItem(int, int).

Parameters
target:GeometryUtils.Target

the result of startCollectionItem(int, int)

type:int

type of collection

index:int

0-based index of this item in the collection

total:int

total number of items in the collection

Annotations
@Override
endNonEmptyPolygonback to summary
protected void endNonEmptyPolygon()

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

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

Invoked after writing of non-empty POLYGON.

Annotations
@Override
endObjectback to summary
protected void endObject(int type)

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

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

Invoked after writing of the object.

Parameters
type:int

type of the object

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)