DSL
GeoJson DSL
It's recommended to construct GeoJson objects in-code using the GeoJson DSL.
Positions
Convenience functions to construct latitude/longitude Position instances is included.
These functions will check for valid latitude and longitude values and will throw an IllegalArgumentException
otherwise.
Geometry
Each geometry type has a corresponding DSL.
A GeoJson object's bbox value can be assigned in any of the DSLs.
foreignMembers property can be set via AdditionalFieldsBuilder
Point
MultiPoint
The MultiPoint DSL creates a MultiPoint from many Points, or by using the unary plus operator to add Position
instances as positions in the geometry.
Point geometries can also be added to the multi point using the unary plus operator.
LineString
A LineString contains main points. Like with MultiPoint, a LineString can also be built using the unary plus
operator to add positions as part of the line.
The order in which positions are added to the LineString is the order that the LineString will follow.
MultiLineString
The MultiLineString DSL uses the unary plus operator to add multiple line strings. The LineString DSL can be used to
create LineString objects to add.
Polygon
The Polygon DSL is used by specifying linear rings that make up the polygon's shape and holes.
The first ring is the exterior ring with four or more positions. The last position must be the same as the first
position.
All rings that follow will represent interior rings (i.e. holes) in the polygon.
For convenience, the complete() function can be used to "complete" a ring.
It adds the last position in the ring by copying the first position that was added.
MultiPolygon
Like with previous "Multi" geometries, the unary plus operator is used to add multiple Polygon objects.
The Polygon DSL can also be used here.
Geometry Collection
The unary plus operator can be used to add any geometry instance to a GeometryCollection.
{
"type": "GeometryCollection",
"geometries": [
{
"type": "Point",
"coordinates": [-75.0, 45.0, 100.0]
},
{
"type": "LineString",
"coordinates": [
[45.0, 45.0],
[0.0, 0.0]
]
},
{
"type": "Polygon",
"coordinates": [
[
[45.0, 45.0],
[0.0, 0.0],
[12.0, 12.0],
[45.0, 45.0]
],
[
[4.0, 4.0],
[2.0, 2.0],
[3.0, 3.0],
[4.0, 4.0]
]
]
}
]
}
Feature
The Feature DSL can construct a Feature object with a geometry, a bounding box, and an id. Properties can be
specified
in the PropertiesBuilder block by calling put(key, value) to add properties.
Feature Collection
A FeatureCollection is constructed by adding multiple Feature objects using the unary plus operator.