Skip to content

Commit bd82f52

Browse files
committed
Fix CsvReader missing WKT where the space after geometry type and ( is missing.
1 parent cb03fa8 commit bd82f52

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/main/groovy/geoscript/layer/io/CsvReader.groovy

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,11 @@ class CsvReader implements Reader {
279279
* @return The geometry type (point, linestring, polygon, ect...)
280280
*/
281281
private String getGeometryTypeFromWKT(String wkt) {
282-
wkt.substring(0, wkt.indexOf(" (")).toLowerCase()
282+
int i = wkt.indexOf(" (")
283+
if (i == -1) {
284+
i = wkt.indexOf("(")
285+
}
286+
wkt.substring(0, i).toLowerCase()
283287
}
284288

285289
/**
@@ -288,9 +292,14 @@ class CsvReader implements Reader {
288292
* @return Whether the input value looks like WKT
289293
*/
290294
private boolean isWKT(String str) {
291-
if (str.startsWith("POINT (") || str.startsWith("LINESTRING (") || str.startsWith("POLYGON") ||
292-
str.startsWith("MULTIPOINT (") || str.startsWith("MULTILINESTRING (") || str.startsWith("MULTIPOLYGON") ||
293-
str.startsWith("GEOMETRYCOLLECTION (") || str.startsWith("LINEARRING (")
295+
if (str.startsWith("POINT (") || str.startsWith("POINT(") ||
296+
str.startsWith("LINESTRING (") || str.startsWith("LINESTRING(") ||
297+
str.startsWith("POLYGON") || str.startsWith("POLYGON(") ||
298+
str.startsWith("MULTIPOINT (") || str.startsWith("MULTIPOINT(") ||
299+
str.startsWith("MULTILINESTRING (") || str.startsWith("MULTILINESTRING(") ||
300+
str.startsWith("MULTIPOLYGON") || str.startsWith("MULTIPOLYGON(") ||
301+
str.startsWith("GEOMETRYCOLLECTION (") || str.startsWith("GEOMETRYCOLLECTION(") ||
302+
str.startsWith("LINEARRING (") || str.startsWith("LINEARRING(")
294303
) {
295304
return true
296305
}

src/test/groovy/geoscript/layer/io/CsvReaderTestCase.groovy

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,19 @@ ak,10501917,?,"Thursday, June 28, 2012 02:30:58 UTC",60.0233,-152.9946,2,2.9,?,"
242242
assertEquals(0, layer.count)
243243
assertEquals("csv geom: Point, id: String, name: String", layer.schema.toString())
244244
}
245+
246+
@Test void readFromWktWithNoSpace() {
247+
String csv = """the_geom,ADMIN_NAME
248+
POINT(10.1999998092651 59.7000007629395),Buskerud
249+
POINT(-2.96670007705688 56.4667015075684),Scotland
250+
POINT(-4.85678577423096 55.736743927002),Scotland
251+
POINT(14.7166996002197 55.11669921875),Bornholm
252+
POINT(69.2166976928711 54.88330078125),North Kazakhstan
253+
POINT(-1.16670000553131 54.5999984741211),England
254+
"""
255+
CsvReader reader = new CsvReader()
256+
Layer layer = reader.read(csv)
257+
assertEquals(6, layer.count)
258+
assertEquals("csv the_geom: Point, ADMIN_NAME: String", layer.schema.toString())
259+
}
245260
}

0 commit comments

Comments
 (0)