8
8
9
9
package org .locationtech .spatial4j .io ;
10
10
11
+ import java .io .IOException ;
12
+ import java .io .Writer ;
13
+ import java .math .RoundingMode ;
14
+ import java .text .NumberFormat ;
15
+ import java .util .Iterator ;
11
16
import org .locationtech .spatial4j .shape .Circle ;
12
17
import org .locationtech .spatial4j .shape .Point ;
13
18
import org .locationtech .spatial4j .shape .Rectangle ;
16
21
import org .locationtech .spatial4j .shape .impl .BufferedLine ;
17
22
import org .locationtech .spatial4j .shape .impl .BufferedLineString ;
18
23
19
- import java .io .IOException ;
20
- import java .io .Writer ;
21
- import java .math .RoundingMode ;
22
- import java .text .NumberFormat ;
23
- import java .util .Iterator ;
24
-
25
24
public class WKTWriter implements ShapeWriter {
26
25
27
26
@ Override
@@ -42,8 +41,13 @@ protected NumberFormat getNumberFormat() {
42
41
public String toString (Shape shape ) {
43
42
NumberFormat nf = getNumberFormat ();
44
43
if (shape instanceof Point ) {
44
+ Point point = (Point )shape ;
45
+ if (point .isEmpty ()) {
46
+ return "POINT EMPTY" ;
47
+ }
48
+
45
49
StringBuilder buffer = new StringBuilder ();
46
- return append (buffer .append ("POINT (" ),( Point ) shape , nf ).append (")" ).toString ();
50
+ return append (buffer .append ("POINT (" ), point , nf ).append (")" ).toString ();
47
51
}
48
52
if (shape instanceof Rectangle ) {
49
53
NumberFormat nfMIN = nf ;
@@ -103,10 +107,17 @@ public String toString(Shape shape) {
103
107
return str .toString ();
104
108
}
105
109
if (shape instanceof ShapeCollection ) {
110
+ @ SuppressWarnings ("unchecked" )
111
+ ShapeCollection <? extends Shape > collection = (ShapeCollection <? extends Shape >) shape ;
112
+
113
+ if (collection .isEmpty ()) {
114
+ return "GEOMETRYCOLLECTION EMPTY" ;
115
+ }
116
+
106
117
StringBuilder buffer = new StringBuilder ();
107
118
buffer .append ("GEOMETRYCOLLECTION (" );
108
119
boolean first = true ;
109
- for (Shape sub : (( ShapeCollection <? extends Shape >) shape ) .getShapes ()) {
120
+ for (Shape sub : collection .getShapes ()) {
110
121
if (!first ) {
111
122
buffer .append ("," );
112
123
}
0 commit comments