You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: web/docs/developer/index.md
+86-42Lines changed: 86 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,33 +25,38 @@ This document is intended for developers who would like to use JTS to accomplish
25
25
26
26
The most common JTS tasks involve creating and using Geometry objects. The easiest way to create a Geometry by hand is to use a WKTReader to generate one from a Well-Known Text (WKT) string. For example:
A precise specification for WKT is given in the *JTS Technical Specifications*. And many examples of WKT may be found in the files in the *test* directory.
31
33
32
34
In a real program, it’s easier to use a GeometryFactory, because you don’t need to build up a WKT string; rather, you work with the objects directly:
Once you’ve made your Geometry, there are many things you can do with it. You can easily find the intersection of two Geometries:
42
43
44
+
```java
43
45
Geometry g3 = g1.intersection(g2);
46
+
```
44
47
45
-
Other computations built into Geometries include: area, envelope, centroid, and buffer. For more information about what a Geometry can do, see the JavaDoc for Geometry in the com.vividsolutions.jts.geom package, as well as subsequent sections in this document.
48
+
Other computations built into Geometries include: area, envelope, centroid, and buffer. For more information
49
+
about what a Geometry can do, see the JavaDoc for Geometry in the `org.loctiontech.jts.geom`
50
+
package, as well as subsequent sections in this document.
46
51
47
52
# **3. COMPUTING SPATIAL RELATIONSHIPS**
48
53
49
54
An important application of JTS is computing the spatial relationships between Geometries. Various methods of computing relationships are provided. JTS follows the **Dimensionally Extended 9 Intersection Matrix** model specified by the OGC. To compute the DE-9IM for two Geometries, use the relate method:
50
55
51
56
```java
52
-
Geometry a =...
53
-
Geometry b =...
54
-
IntersectionMatrix m = a.relate(b);
57
+
Geometry a =...
58
+
Geometry b =...
59
+
IntersectionMatrix m = a.relate(b);
55
60
```
56
61
57
62
Most relationships of interest can be specified as a pattern which matches a set of intersection matrices. JTS also provides a set of boolean predicates which compute common spatial relationships directly. These are:
@@ -99,9 +104,18 @@ As with the spatial relationships described in the previous section, these overl
99
104
100
105
In GIS, buffering is an operation which in GIS is used to compute the area containing all points within a given distance of a Geometry. In mathematical terms, this is called computing the **Minkowski sum** of the Geometry with a disc of radius equal to the buffer distance. Finding positive and negative buffers is sometimes referred to as the operations of **erosion** and **dilation**. In CAD/CAM buffer curves are called **offset curves**.
101
106
102
-
You can use JTS to compute the **buffer** of a Geometry using the Geometry buffer method or the BufferOp class. The input Geometry to the buffer operation may be of any type (including arbitrary GeometryCollections). The result of a buffer operation is always an area type (Polygon or MultiPolygon). The result may be empty (for example, a negative buffer of a LineString).
107
+
You can use JTS to compute the **buffer** of a Geometry using the
108
+
Geometry buffer method or the `BufferOp` class. The input Geometry
109
+
to the buffer operation may be of any type (including arbitrary
110
+
`GeometryCollection`s). The result of a buffer operation is always an area
111
+
type (`Polygon` or `MultiPolygon`). The result may be empty (for example,
112
+
a negative buffer of a `LineString`).
103
113
104
-
You can compute buffers with both positive and negative buffer distances. Buffers with a positive buffer distance always contain the input Geometry. Buffers with a negative buffer distance are always contained within the input Geometry. A negative buffer of a LineString or a Point results in an empty Geometry.
114
+
You can compute buffers with both positive and negative buffer
115
+
distances. Buffers with a positive buffer distance always contain the
116
+
input `Geometry`. Buffers with a negative buffer distance are always
117
+
contained within the input `Geometry`. A negative buffer of a `LineString`
118
+
or a `Point` results in an empty `Geometry`.
105
119
106
120

107
121
@@ -111,16 +125,19 @@ Buffer distances of 0 are also supported. You can use this to perform an efficie
111
125
112
126
## **5.1 BASIC BUFFERING**
113
127
114
-
To compute a buffer for a given distance, call the buffer() method on the Geometry:
128
+
To compute a buffer for a given distance, call the `buffer()` method on the `Geometry`:
115
129
116
130
```java
117
-
Geometry g =...
118
-
Geometry buffer = g.buffer(100.0);
131
+
Geometry g =...
132
+
Geometry buffer = g.buffer(100.0);
119
133
```
120
134
121
135
## **5.2 END CAP STYLES**
122
136
123
-
Buffer polygons can be computed with different line **end cap styles**. The end cap style determines how the linework for the buffer polygon is constructed at the ends of linestrings. The following different kinds of end cap styles are supported:
137
+
Buffer polygons can be computed with different line **end cap
138
+
styles**. The end cap style determines how the line work for the buffer
139
+
polygon is constructed at the ends of `lineString`s. The following
140
+
different kinds of end cap styles are supported:
124
141
125
142
|*Style Name*|*Description*|
126
143
| :---- | :---- |
@@ -136,26 +153,32 @@ The following diagrams illustrate the effects of specifying different end cap st
136
153
137
154
**Figure 5-2 \- Different End Cap Styles**
138
155
139
-
To specify the buffer end cap style, the BufferOp class in the package
156
+
To specify the buffer end cap style, the `BufferOp` class in the package
140
157
141
-
com.vividsolutions.jts.operation.buffer is used directly:
158
+
`org.locationtech.jts.operation.buffer` is used directly:
## **5.3 SPECIFYING THE APPROXIMATION QUANTIZATION**
151
168
152
-
Since the exact buffer outline of a Geometry usually contains circular sections, the buffer must be approximated by the linear Geometry supported by JTS. The degree of approximation may be controlled by the user. In JTS this is done by specifying the number of quadrant segments used to approximate a quarter-circle. Specifying a larger number of segments results in a better approximation to the actual area, but also results in a larger number of line segments in the computed polygon.
169
+
Since the exact buffer outline of a Geometry usually contains circular
170
+
sections, the buffer must be approximated by the linear Geometry
171
+
supported by JTS. The degree of approximation may be controlled by the
172
+
user. In JTS this is done by specifying the number of quadrant segments
173
+
used to approximate a quarter-circle. Specifying a larger number of
174
+
segments results in a better approximation to the actual area, but also
175
+
results in a larger number of line segments in the computed polygon.
153
176
154
177
To specify a value for the quadrant segments, use the Geometry buffer method with a second argument:
155
178
156
179
```java
157
-
Geometry g =...
158
-
Geometry buffer = g.buffer(100.0, 16);
180
+
Geometry g =...
181
+
Geometry buffer = g.buffer(100.0, 16);
159
182
```
160
183
161
184
The default number of segments is 8. This gives less than a 2% maximum error in the distance of the computed curve approximation to the actual buffer curve. This error can be reduced to less than 1% by using a value of 12. The diagram below shows the effect of increasing the number of approximation curve segments.
@@ -170,12 +193,16 @@ The default number of segments is 8. This gives less than a 2% maximum error in
170
193
171
194
Polygonization is the process of forming polygons from linework which encloses areas. Linework to be formed into polygons must be fully noded – that is, linestrings must not cross and must touch only at endpoints.
172
195
173
-
JTS provides the Polygonizer class to perform Polygonization. The Polygonizer takes a set of fully noded LineStrings and forms all the polygons which are enclosed by the lines. Polygonization errors such as dangling lines or cut lines can be identified and reported.
196
+
JTS provides the `Polygonizer` class to perform polygonization. The `Polygonizer` takes a set of fully noded
197
+
LineStrings and forms all the polygons which are enclosed by the lines. Polygonization errors such as
198
+
dangling lines or cut lines can be identified and reported.
@@ -205,11 +232,17 @@ Sometimes a spatial operation such as \#union will produce chains of small LineS
205
232
206
233
**Figure 7-1 – The Line-Merging Operation**
207
234
208
-
The LineMerger assumes that the input LineStrings are *noded* (i.e. they do not cross; only their endpoints can touch. See *9.1 Noding A Set Of LineStrings* on page 11). Note that the output LineStrings are also noded.
235
+
The `LineMerger` assumes that the input `LineStrings` are *noded* (i.e. they do not cross; only their
209
236
210
-
If LineStrings to be merged do not have the same direction, the direction of the resulting LineString will be that of the majority.
237
+
**TODO** fix this link
211
238
212
-
The LineMerger is used as follows:
239
+
endpoints can touch. See *9.1 Noding A Set Of `LineStrings`* on page 11). Note that the output `LineStrings`
240
+
are also noded.
241
+
242
+
If `LineStrings` to be merged do not have the same direction, the direction of the resulting `LineString`
By default JTS uses arrays of Coordinates to represent the points and lines of Geometries. There are some cases in which you might want Geometries to store their points using some other implementation. For example, to save memory you may want to use a more compact sequence implementation, such as an array of x’s and an array of y’s. Another possibility is to use a custom coordinate class to store extra information on each coordinate, such as measures for linear referencing.
224
257
225
-
You can do this by implementing the CoordinateSequence and
226
-
227
-
CoordinateSequenceFactory interfaces. You would then create a GeometryFactory parameterized by your CoordinateSequenceFactory, and use this GeometryFactory to create new Geometries. All of these new Geometries will use your CoordinateSequence implementation.
258
+
You can do this by implementing the `CoordinateSequence` and
259
+
`CoordinateSequenceFactory` interfaces. You would then create a `GeometryFactory` parameterized by your
260
+
`CoordinateSequenceFactory`, and use this `GeometryFactory` to create new `Geometries`. All of these new
261
+
`Geometries` will use your `CoordinateSequence` implementation.
228
262
229
263
For an example, see the following sample programs in the
230
264
231
-
com.vividsolutions.jtsexample.geom package:
265
+
org.locationtech.jtsexample.geom package:
232
266
233
267
| ExtendedCoordinateExample | An example of using adding information to the basic coordinate representation |
234
268
| :---- | :---- |
235
269
| TwoArrayCoordinateSequenceExample | An example of using a more memory-efficient sequence implementation |
236
270
237
-
A note on performance: If your CoordinateSequence is not based on an array of the standard JTS Coordinates (or a subclass of Coordinate), it may incur a small performance penalty. This is due to the marshalling and unmarshalling required for JTS to convert the user coordinates into arrays of JTS coordinates.
271
+
A note on performance: If your `CoordinateSequence` is not based on an array of the standard JTS
272
+
`Coordinates` (or a subclass of Coordinate), it may incur a small performance penalty. This is due to the
273
+
marshalling and unmarshalling required for JTS to convert the user coordinates into arrays of JTS
274
+
coordinates.
238
275
239
276
# **9. TIPS & TECHNIQUES**
240
277
241
278
## **9.1 NODING A SET OF LINESTRINGS**
242
279
243
-
Many spatial operations assume that their input data is **noded**, meaning that LineStrings never cross. For example, the JTS Polygonizer and the JTS LineMerger described earlier assume that their input is noded.
280
+
Many spatial operations assume that their input data is **noded**, meaning that `LineStrings` never cross. For
281
+
example, the JTS `Polygonizer` and the JTS `LineMerger` described earlier assume that their input is noded.
244
282
245
-
The noding process splits LineStrings that cross into smaller LineStrings that meet at a point, or **node**, as illustrated below.
283
+
The noding process splits `LineStrings` that cross into smaller `LineStrings` that meet at a point, or
A simple trick for noding a group of LineStrings is to union them together. It turns out that the unioning process will node the LineStrings for us. For example, the following code will node a collection of LineStrings:
292
+
A simple trick for noding a group of `LineStrings` is to union them together. It turns out that the unioning
293
+
process will node the `LineStrings` for us. For example, the following code will node a collection of
294
+
`LineStrings`:
254
295
255
296
```java
256
297
Collection lineStrings =...
@@ -262,11 +303,14 @@ for (int i = 1; i \< lineStrings.size(); i++) {
262
303
263
304
# **10. UNIONING MANY POLYGONS EFFICIENTLY**
264
305
265
-
Calling Polygon\#union repeatedly is one way to union several Polygons together. But here’s a trick that can be significantly faster (seconds rather than minutes) – add the Polygons to a GeometryCollection, then apply a buffer with zero distance:
306
+
Calling `Polygon.union` repeatedly is one way to union several `Polygons`
307
+
together. But here’s a trick that can be significantly faster (seconds
308
+
rather than minutes) – add the `Polygons` to a `GeometryCollection`,
0 commit comments