Skip to content

Commit ee67d84

Browse files
committed
Updated README
1 parent f9e7dcd commit ee67d84

File tree

1 file changed

+134
-47
lines changed

1 file changed

+134
-47
lines changed

README.md

Lines changed: 134 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,158 @@
22

33
# Geolatte-geom
44

5-
A geometry model for Java that conforms to the Simple Features For SQL specification 1.2.1.
6-
7-
It is intended as a drop-in replacement for the Java Topology Suite (JTS) geometry model. GeoLatte-geom is fully
8-
interoperable with JTS but offers the following additional features:
9-
* immutable data structures (Geometries are value objects).
5+
A geometry model for Java with:
6+
* immutable data structures
107
* support for 2D, 3D, 2DM and 3DM geometries
11-
* support for several dialects of WKT/WKB (Postgis, Sql Server, SFS 1.21)
12-
* pluggable, extendable Geometry operations
13-
* CRS-awareness (knowledge of coordinate reference system (projected/geodetic, angular units of metres)
14-
* geodetic operations (length, distance and area calculations)
8+
* A DSL for creating Geometries
9+
* support for several dialects of WKT/WKB (Postgis, Sql Server, SFA 1.1.0 and 1.2.1)
10+
* Codecs for translating from/to native database formats for Postgis, Mysql, Oracle, and Microsoft SQL Server.
11+
* Pluggable, extendable Geometry operations
12+
* Coordinate reference system aware
13+
* space filling curves
14+
15+
The library's geometry model is largely based on the
16+
[Simple Feature Access (1.2.1) specification](https://portal.ogc.org/files/?artifact_id=25355).
17+
18+
GeoLatte-geom is fully interoperable with [the Java Topology Suite (JTS)](https://github.com/locationtech/jts).
19+
20+
# Using Geolatte-geom
21+
22+
Currently we require Java 1.8 or later.
23+
24+
The library is published on Maven Central. For Maven, you can include the following dependency.
25+
26+
```xml
27+
<dependency>
28+
<groupId>org.geolatte</groupId>
29+
<artifactId>geolatte-geom</artifactId>
30+
<version>1.17</version>
31+
</dependency>
32+
```
33+
34+
# Quick start
35+
36+
## Creating Geometries
37+
To create a Geometry we first need to specify the Coordinate Reference System we will be working in. Let's say we use
38+
WGS84 (for other options, see [below](#coordinate-reference-systems)).
39+
40+
```java
41+
import org.geolatte.geom.*;
42+
import static org.geolatte.geom.crs.CoordinateReferenceSystems.WGS84;
43+
44+
```
45+
46+
The easiest way to create `Geometry` instances is by using the built-in builder DSL. This allows you to specify 2D `Position`s
47+
(coordinates) using `c(x,y)`for Cartesian or projected coordinates, and
48+
`g(long,lat)` for geodetic or spherical coordinates. (There are also variants for the higher dimensions).
49+
50+
```java
51+
import static org.geolatte.geom.builder.DSL.*;
52+
```
53+
Now we can create geometries like so.
54+
```java
55+
...
56+
Point<G2D> pnt = point(WGS84, g(4.33,53.21));
57+
58+
LineString<G2D> lstr = linestring(WGS84, g(4.43, 53.21), g(4.44, 53.20), g(4.45, 53.19));
59+
60+
Polygon<G2D> pgn = polygon(WGS84, ring(g(4.43, 53.21), g(4.44, 53.22), g(4.43, 53.21)));
61+
```
62+
We can also create Geometries in a higher-dimensional space. Let's do it in 3D.
63+
64+
First we again need to specify the coordinate reference system we will be working in. In this case, we derive
65+
the system from WGS84 by adding a Vertical system for the elevation.
1566

67+
```java
1668

17-
# Redesign 0.x to 1.0
69+
CoordinateReferenceSystem<G3D> wgs84E = WGS84.addVerticalSystem(LinearUnit.METER, G3D.class);
70+
...
71+
72+
Point<G3D> pntWithElevation = point(wgs84E, g(4.33, 53.21, 350));
1873

19-
This version is a complete redesign. The redesign is aimed at:
20-
* increasing the level of type-safety in the API;
21-
* the ability to incorporate geographic (or geodetic) data without duplication of the Geometry class hierarchy;
22-
* making full use of the information on coordinate reference systems that is now available in the CRSRegistry.
74+
```
2375

24-
## The Coordinate Reference System model (crs package)
76+
## Encoding and Decoding Geometries to WKT/WKB
2577

26-
The availability of the CRSRegistry, and the explicit modelling of coordinate reference systems,
27-
made it obvious that a better way was available for handling the different dimensions of a Geometry's coordinate space.
28-
In previous versions this dimensionality was specified with a DimensionalFlag. Having a complete model of the
29-
Coordinate Reference System, including it's coordinate space, means we no longer need this. Rather than
30-
associating a DimensionalFlag with the Geometry, we only need it's Coordinate Reference System.
78+
Now let's write these out as WKT string.
79+
```java
80+
import org.geolatte.geom.codec.Wkt;
3181

32-
Since in the Coordinate Reference System model Projected and Geographic systems are distinguished, we can use a
33-
single Geometry class-hierarchy, and let the implementations inspect the associated Coordinate Reference System
34-
to determine which operations are valid, or which algorithms are selected (e.g. geodetic length rather than length in 2D plane).
82+
String wkt = Wkt.toWkt(pnt);
83+
// "SRID=4326;POINT(4.33 53.21)"
3584

36-
## Base and compound Coordinate Reference Systems
85+
// or maybe using a specific dialect such as SFA 1.2.1
86+
String wktZ = Wkt.toWkt(pntWithElevation, Wkt.Dialect.SFA_1_2_1);
87+
// "POINT Z (4.33 53.21 350)"
88+
```
3789

38-
The CRSRegistry only provides access to base systems, which are always 2D. Users can add axes (Vertical or Measure) to
39-
a base system, and so create a Compound system. Vertical axes are axes with a Direction of UP (DOWN), measure axes have
40-
direction OTHER or UNKNOWN. Although it is possible to add several Measure axes, many measure operations will only take the first
41-
such axis into account.
90+
There is a very similar API for WKB encoding/decoding (see the `Wkb` codec class).
4291

92+
For historical and practical reasons. The default dialects for WKB/WKT are those
93+
used in [Postgis](http://postgis.org).
94+
95+
## Geometry operations
96+
97+
[TODO]
98+
99+
# The Geometry model
43100

44101
## Positions
45102

46-
A Position is essentially a tuple of coordinates which together with a Coordinate Reference System specify
47-
a position in that Coordinate Reference System.
103+
A `Position` is a tuple of coordinates that specify a position relative to a coordinate reference system.
104+
It corresponds with to the concept of **direct position** in the Simple Feature
105+
and ISO-19107 specifications.
106+
107+
The coordinate space can be 2-, 3- or 4-dimensional. The first two dimensions are used to specify a
108+
point on the earth's surface. The third dimension usually represent altitude or elevation,
109+
and the fourth a measurement.
110+
111+
There are two major types of 2D coordinate reference systems. `GeographicCoordinateReferenceSystem`s specify
112+
points on the earth's surface using spherical coordinates (i.e. latitude` and longitude).
113+
`ProjectedCoordinateReferenceSystem`s use cartesian coordinates (x and y) on a projected plane.
114+
115+
From these 2D-spaces the higher-dimensional spaces can be constructed by adding a
116+
`VerticalCoordinateReferenceSystem` and/or a `LinearCoordinateReferenceSystem`.
117+
118+
Consequently, the instantiable (2D) types of `Position` are `G2D` (spherical coordinates) and `C2D` (cartesian coordinates) in a
119+
geographic, resp. projected coordinate reference system. From these the higher-dimensional subtypes
120+
can be derived. E.g. from `C2D`, we can build `C3D`, `C2DM` and `C3DM` positions.
121+
122+
123+
## Geometry
124+
125+
A `Geometry` is a topologically closed set (in the mathematical sense) of `Position`s. The instantiable `Geometry`
126+
subclasses all specify this set using one or more boundaries. The boundaries in turn are specified by
127+
interpolation between consecutive elements in a list of `Position`s. These `Position`s are called the _vertices_ of the
128+
`Geometry`.
129+
130+
A distinctive feature of this library is that `Geometry` class is parameterized by `Position` type. This means that e.g.
131+
a `Point<C2D>` is a different type than `Point<G2D>`. This ensures that it is always explicit what the coordinates mean
132+
(projected or spherical), and what types of operation make sense. E.g. the euclydian distance on the plane works for
133+
projected coordinates, but makes no sense for spherical coordinates.
134+
135+
136+
The instantiable subclasses of `Geometry` are:
137+
138+
- `Point` a single position
139+
- `LineString` a 1-dimensional curve specified by linear interpolation between its vertices
140+
- `Polygon` a 2-dimensional space enclosed by an outer `LinearRing` (a closed `LineString`), minus the space enclosed
141+
by any inner `LinearRing`s.
142+
- `MultiPoint` a collection of `Point`s
143+
- `MultiLineString` a collection of `LineString`s
144+
- `MultiPolygon` a collection of `Polygon`s
145+
- `GeometryCollection` a collection of `Geometry`s
146+
147+
## Coordinate Reference Systems
148+
[TODO]
149+
150+
# JTS interop
48151

49-
In previous versions, Points played the role of Positions. The concept of a Position, distinguished from
50-
a Point, was introduced to have different types of Positions, each corresponding to a type of
51-
Coordinate Reference System.
152+
[TODO]
52153

53-
In this new model, a Geometry is conceptually a set of Positions (all associated with the same Coordinate Reference System).
54-
The set is determined by one or more sequences of Positions and a type enum value (GeometryType) that determine how the
55-
sequence(s) determine the Geometry (e.g. for LineString it is by linear interpolation between the consecutive positions).
56154

57-
## De-emphasizing the Simple Features Specification (SFS)
58155

59-
This library started as an attempt to have a JTS-interoperable library that is SFS-compliant, but has a more
60-
modern design and better support for geometries not in the 2-dimensional projected plane. As design progressed, it became
61-
no longer obvious what the advantage of SFS compliance are.
62156

63-
With open source and more expressive languages, the advantage of standardisation on the API level
64-
are becoming less-and-less obvious. The only advantages to the SFS model (or it's more complicated cousin SQL/MM-Part 3)
65-
that I can see are a familiar Geometry model and a precise specification of topological relations. These advantages are
66-
offset by the disadvantages of a bias to 2D planar coordinate systems, and a (by current tastes) problematic API design.
67-
(Should complex operations really be part of the Geometry interface? What with alternative algorithm implementations?)
68-
69-
Because of these misgivings, we will de-emphasize SFS compliance.
70157

71158

72159

0 commit comments

Comments
 (0)