Skip to content

Commit 22880e3

Browse files
author
Adam Collins
committed
#237 Fix for POINT MULTIPOINT LINESTRING MULTILINESTRING geometry export
1 parent 3f4e6c7 commit 22880e3

File tree

2 files changed

+23
-42
lines changed

2 files changed

+23
-42
lines changed

grails-app/services/au/org/ala/spatial/SpatialObjectsService.groovy

+2-23
Original file line numberDiff line numberDiff line change
@@ -270,18 +270,7 @@ class SpatialObjectsService {
270270
FileUtils.copyFile(zippedShapeFile, os)
271271
} else if ("kml" == geomtype) {
272272
String wktString = l.get(0).geometry.toText()
273-
String wkttype = "POLYGON"
274-
if (wktString.startsWith("MULTIPOLYGON")) {
275-
wkttype = "MULTIPOLYGON"
276-
} else if (wktString.startsWith("GEOMETRYCOLLECTION")) {
277-
wkttype = "GEOMETRYCOLLECTION"
278-
} else if (wktString.startsWith("MULTIPOINT")) {
279-
wkttype = "MULTIPOINT"
280-
} else if (wktString.startsWith("POINT")) {
281-
wkttype = "POINT"
282-
}
283-
284-
final SimpleFeatureType TYPE = SpatialConversionUtils.createFeatureType(wkttype)
273+
final SimpleFeatureType TYPE = SpatialConversionUtils.createFeatureType(wktString)
285274
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE)
286275
featureBuilder.add(l.get(0).geometry)
287276
SimpleFeature feature = featureBuilder.buildFeature(null)
@@ -300,17 +289,7 @@ class SpatialObjectsService {
300289
StringWriter writer = new StringWriter()
301290

302291
String wktString = l.get(0).geometry.toText()
303-
String wkttype = "POLYGON"
304-
if (wktString.startsWith("MULTIPOLYGON")) {
305-
wkttype = "MULTIPOLYGON"
306-
} else if (wktString.startsWith("GEOMETRYCOLLECTION")) {
307-
wkttype = "GEOMETRYCOLLECTION"
308-
} else if (wktString.startsWith("MULTIPOINT")) {
309-
wkttype = "MULTIPOINT"
310-
} else if (wktString.startsWith("POINT")) {
311-
wkttype = "POINT"
312-
}
313-
final SimpleFeatureType TYPE = SpatialConversionUtils.createFeatureType(wkttype)
292+
final SimpleFeatureType TYPE = SpatialConversionUtils.createFeatureType(wktString)
314293
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(TYPE)
315294
featureBuilder.add(l.get(0).geometry)
316295
SimpleFeature feature = featureBuilder.buildFeature(null)

src/main/groovy/au/org/ala/spatial/util/SpatialConversionUtils.groovy

+21-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import groovy.transform.CompileStatic
55
import groovy.util.logging.Slf4j
66
import org.apache.commons.io.FileUtils
77
import org.apache.commons.io.IOUtils
8-
import org.apache.commons.io.filefilter.IOFileFilter
98
import org.apache.commons.lang3.tuple.Pair
109
import org.geotools.data.DefaultTransaction
1110
import org.geotools.data.FileDataStore
@@ -26,7 +25,11 @@ import org.geotools.referencing.CRS
2625
import org.geotools.referencing.crs.DefaultGeographicCRS
2726
import org.locationtech.jts.geom.Geometry
2827
import org.locationtech.jts.geom.GeometryCollection
28+
import org.locationtech.jts.geom.LineString
29+
import org.locationtech.jts.geom.MultiLineString
30+
import org.locationtech.jts.geom.MultiPoint
2931
import org.locationtech.jts.geom.MultiPolygon
32+
import org.locationtech.jts.geom.Point
3033
import org.locationtech.jts.geom.Polygon
3134
import org.locationtech.jts.io.ParseException
3235
import org.locationtech.jts.io.WKTReader
@@ -49,13 +52,6 @@ import java.util.zip.ZipOutputStream
4952
@CompileStatic
5053
class SpatialConversionUtils {
5154

52-
public final static String WKT_MAP_KEY = "WKT_MAP_KEY_****"
53-
//works as long as this is not uploaded as a field in the shapefile
54-
/**
55-
* log4j logger
56-
*/
57-
//private static final Logger logger = log.getLogger(SpatialConversionUtils.class);
58-
5955
static List<String> getGeometryCollectionParts(String wkt) {
6056
if (wkt.matches("GEOMETRYCOLLECTION\\(.+\\)")) {
6157
String parts = wkt.substring(19, wkt.length() - 1)
@@ -207,7 +203,10 @@ class SpatialConversionUtils {
207203
manifestData.add(pairList)
208204
}
209205

210-
// it.close();
206+
try {
207+
store.dispose()
208+
} catch (Exception ignored) {
209+
}
211210

212211
return manifestData
213212
}
@@ -242,8 +241,7 @@ class SpatialConversionUtils {
242241
SimpleFeatureCollection featureCollection = featureSource.getFeatures()
243242
it = featureCollection.features()
244243

245-
//transform CRS to the same as the shapefile (at least try)
246-
//default to 4326
244+
//transform CRS to the same as the shapefile (at least try) default to 4326
247245
CoordinateReferenceSystem crs = null
248246
try {
249247
crs = store.getSchema().getCoordinateReferenceSystem()
@@ -448,26 +446,30 @@ class SpatialConversionUtils {
448446
}
449447
}
450448

451-
private static SimpleFeatureType createFeatureType(String type) {
449+
static SimpleFeatureType createFeatureType(String type) {
452450

453451
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder()
454452
builder.setName("ActiveArea")
455-
builder.setCRS(DefaultGeographicCRS.WGS84) // <- Coordinate reference
456-
// system
453+
builder.setCRS(DefaultGeographicCRS.WGS84) // <- Coordinate reference system
457454

458455
// add attributes in order
459456
if ("GEOMETRYCOLLECTION".equalsIgnoreCase(type)) {
460457
builder.add("the_geom", MultiPolygon.class)
461458
} else if ("MULTIPOLYGON".equalsIgnoreCase(type)) {
462459
builder.add("the_geom", MultiPolygon.class)
460+
} else if ("LINESTRING".equalsIgnoreCase(type)) {
461+
builder.add("the_geom", LineString.class)
462+
} else if ("MULTILINESTRING".equalsIgnoreCase(type)) {
463+
builder.add("the_geom", MultiLineString.class)
464+
} else if ("POINT".equalsIgnoreCase(type)) {
465+
builder.add("the_geom", Point.class)
466+
} else if ("MULTIPOINT".equalsIgnoreCase(type)) {
467+
builder.add("the_geom", MultiPoint.class)
463468
} else {
464469
builder.add("the_geom", Polygon.class)
465470
}
466-
builder.length(50).add("name", String.class) // <- 50 chars width for
467-
// name field
468-
builder.length(100).add("desc", String.class) // 100 chars width
469-
// for description
470-
// field
471+
builder.length(50).add("name", String.class) // <- 50 chars width for name field
472+
builder.length(100).add("desc", String.class) // 100 chars width for description field
471473

472474
// build the type
473475
return builder.buildFeatureType()

0 commit comments

Comments
 (0)