Skip to content

Commit c2a7de6

Browse files
committed
The CsvReader was not finding geometry fields where the WKT did not have a space after the geometry type: POINT( instead of POINT (
1 parent d4de45e commit c2a7de6

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
@@ -322,7 +322,11 @@ class CsvReader implements Reader {
322322
* @return The geometry type (point, linestring, polygon, ect...)
323323
*/
324324
private String getGeometryTypeFromWKT(String wkt) {
325-
wkt.substring(0, wkt.indexOf(" (")).toLowerCase()
325+
int i = wkt.indexOf(" (")
326+
if (i == -1) {
327+
i = wkt.indexOf("(")
328+
}
329+
wkt.substring(0, i).toLowerCase()
326330
}
327331

328332
/**
@@ -331,9 +335,14 @@ class CsvReader implements Reader {
331335
* @return Whether the input value looks like WKT
332336
*/
333337
private boolean isWKT(String str) {
334-
if (str.startsWith("POINT (") || str.startsWith("LINESTRING (") || str.startsWith("POLYGON") ||
335-
str.startsWith("MULTIPOINT (") || str.startsWith("MULTILINESTRING (") || str.startsWith("MULTIPOLYGON") ||
336-
str.startsWith("GEOMETRYCOLLECTION (") || str.startsWith("LINEARRING (")
338+
if (str.startsWith("POINT (") || str.startsWith("POINT(") ||
339+
str.startsWith("LINESTRING (") || str.startsWith("LINESTRING(") ||
340+
str.startsWith("POLYGON") || str.startsWith("POLYGON(") ||
341+
str.startsWith("MULTIPOINT (") || str.startsWith("MULTIPOINT(") ||
342+
str.startsWith("MULTILINESTRING (") || str.startsWith("MULTILINESTRING(") ||
343+
str.startsWith("MULTIPOLYGON") || str.startsWith("MULTIPOLYGON(") ||
344+
str.startsWith("GEOMETRYCOLLECTION (") || str.startsWith("GEOMETRYCOLLECTION(") ||
345+
str.startsWith("LINEARRING (") || str.startsWith("LINEARRING(")
337346
) {
338347
return true
339348
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,4 +428,19 @@ ak,10501917,?,"Thursday, June 28, 2012 02:30:58 UTC",60.0233,-152.9946,2,2.9,?,"
428428
assertEquals(0, layer.count)
429429
assertEquals("csv geom: Point(EPSG:4326), id: Integer, name: String", layer.schema.toString())
430430
}
431+
432+
@Test void readFromWktWithNoSpace() {
433+
String csv = """the_geom,ADMIN_NAME
434+
POINT(10.1999998092651 59.7000007629395),Buskerud
435+
POINT(-2.96670007705688 56.4667015075684),Scotland
436+
POINT(-4.85678577423096 55.736743927002),Scotland
437+
POINT(14.7166996002197 55.11669921875),Bornholm
438+
POINT(69.2166976928711 54.88330078125),North Kazakhstan
439+
POINT(-1.16670000553131 54.5999984741211),England
440+
"""
441+
CsvReader reader = new CsvReader()
442+
Layer layer = reader.read(csv)
443+
assertEquals(6, layer.count)
444+
assertEquals("csv the_geom: Point, ADMIN_NAME: String", layer.schema.toString())
445+
}
431446
}

0 commit comments

Comments
 (0)