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

public final Class GeoJsonUtils

extends Object
Class Inheritance
Static Imports
org.h2.util.geometry.GeometryUtils.DIMENSION_SYSTEM_XYM, .GeometryUtils.DIMENSION_SYSTEM_XYZ, .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

GeoJson format support for GEOMETRY data type.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
GeoJsonUtils.GeoJsonTarget

Converter output target that writes a GeoJson.

Field Summary

Modifier and TypeField and Description
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
public static byte[]

Returns:

GeoJson representation of the specified geometry
ewkbToGeoJson
(byte[]
geometry object in EWKB format
ewkb
,
int
dimension system of the specified object, may be the same or smaller than its real dimension system. M dimension system is not supported.
dimensionSystem
)

Converts EWKB with known dimension system to GeoJson.

public static byte[]

Returns:

GeoJson representation of the specified geometry
geoJsonToEwkb
(byte[]
geometry object in GeoJson format
json
,
int
the SRID of geometry
srid
)

Converts EWKB with known dimension system to GeoJson.

private static void
private static void
parse(JSONObject o, GeometryUtils.Target target, int type)

private static void
parseCoordinate(JSONValue v, GeometryUtils.Target target, int index, int total)

private static void
private static void
private static void
private static void
private static double
readCoordinate(JSONValue[] values, int index)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

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

GeoJsonUtilsback to summary
private GeoJsonUtils()

Method Detail

ewkbToGeoJsonback to summary
public static byte[] ewkbToGeoJson(byte[] ewkb, int dimensionSystem)

Converts EWKB with known dimension system to GeoJson.

Parameters
ewkb:byte[]

geometry object in EWKB format

dimensionSystem:int

dimension system of the specified object, may be the same or smaller than its real dimension system. M dimension system is not supported.

Returns:byte[]

GeoJson representation of the specified geometry

Exceptions
DbException:
on unsupported dimension system
geoJsonToEwkbback to summary
public static byte[] geoJsonToEwkb(byte[] json, int srid)

Converts EWKB with known dimension system to GeoJson.

Parameters
json:byte[]

geometry object in GeoJson format

srid:int

the SRID of geometry

Returns:byte[]

GeoJson representation of the specified geometry

Exceptions
DbException:
on unsupported dimension system
parseback to summary
private static void parse(JSONValue v, GeometryUtils.Target target)
parseback to summary
private static void parse(JSONObject o, GeometryUtils.Target target, int type)
parseCoordinateback to summary
private static void parseCoordinate(JSONValue v, GeometryUtils.Target target, int index, int total)
parseGeometryCollectionback to summary
private static void parseGeometryCollection(JSONObject o, GeometryUtils.Target target)
parseLineStringback to summary
private static void parseLineString(JSONArray a, GeometryUtils.Target target)
parsePolygonback to summary
private static void parsePolygon(JSONArray a, GeometryUtils.Target target)
parseRingback to summary
private static void parseRing(JSONValue[] points, GeometryUtils.Target target)
readCoordinateback to summary
private static double readCoordinate(JSONValue[] values, int index)
org.h2.util.geometry back to summary

public final Class GeoJsonUtils.GeoJsonTarget

extends Target
Class Inheritance

Converter output target that writes a GeoJson.

Field Summary

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

Constructor Summary

AccessConstructor and Description
public
GeoJsonTarget(JSONByteArrayTarget
output JSON target
output
,
int
dimension system to use
dimensionSystem
)

Creates new GeoJson 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
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
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
writeStartObject(int type)

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

Field Detail

dimensionSystemback to summary
private final int dimensionSystem
inMultiback to summary
private boolean inMulti
inMultiLineback to summary
private boolean inMultiLine
outputback to summary
private final JSONByteArrayTarget output
typeback to summary
private int type
wasEmptyback to summary
private boolean wasEmpty

Constructor Detail

GeoJsonTargetback to summary
public GeoJsonTarget(JSONByteArrayTarget output, int dimensionSystem)

Creates new GeoJson output target.

Parameters
output:JSONByteArrayTarget

output JSON target

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
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
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)
writeStartObjectback to summary
private void writeStartObject(int type)