Skip to content

Commit e815077

Browse files
committedMay 15, 2024
- fixes null pointer issue where geometry points are null or an empty list
1 parent 413ff34 commit e815077

File tree

2 files changed

+34
-28
lines changed

2 files changed

+34
-28
lines changed
 

‎grails-app/services/au/org/ala/ecodata/ParatooService.groovy

+31-27
Original file line numberDiff line numberDiff line change
@@ -535,35 +535,39 @@ class ParatooService {
535535
// used by protocols like bird survey where a point represents a sight a bird has been observed in a
536536
// bird survey plot
537537
def location = output[model.name]
538-
if (location instanceof Map) {
539-
output[model.name] = [
540-
type : 'Feature',
541-
geometry : [
542-
type : 'Point',
543-
coordinates: [location.lng, location.lat]
544-
],
545-
properties: [
546-
name : "Point ${formName}-${featureId}",
547-
externalId: location.id,
548-
id: "${formName}-${featureId}"
549-
]
550-
]
551-
}
552-
else if (location instanceof List) {
553-
String name
554-
switch (config?.geometryType) {
555-
case "LineString":
556-
name = "LineString ${formName}-${featureId}"
557-
output[model.name] = ParatooProtocolConfig.createLineStringFeatureFromGeoJSON (location, name, null, name)
558-
break
559-
default:
560-
name = "Polygon ${formName}-${featureId}"
561-
output[model.name] = ParatooProtocolConfig.createFeatureFromGeoJSON (location, name, null, name)
562-
break
538+
if (location) {
539+
if (location instanceof Map) {
540+
output[model.name] = [
541+
type : 'Feature',
542+
geometry : [
543+
type : 'Point',
544+
coordinates: [location.lng, location.lat]
545+
],
546+
properties: [
547+
name : "Point ${formName}-${featureId}",
548+
externalId: location.id,
549+
id : "${formName}-${featureId}"
550+
]
551+
]
552+
} else if (location instanceof List) {
553+
String name
554+
switch (config?.geometryType) {
555+
case "LineString":
556+
name = "LineString ${formName}-${featureId}"
557+
output[model.name] = ParatooProtocolConfig.createLineStringFeatureFromGeoJSON(location, name, null, name)
558+
break
559+
default:
560+
name = "Polygon ${formName}-${featureId}"
561+
output[model.name] = ParatooProtocolConfig.createFeatureFromGeoJSON(location, name, null, name)
562+
break
563+
}
563564
}
564-
}
565565

566-
featureId ++
566+
featureId ++
567+
}
568+
else {
569+
output[model.name] = null
570+
}
567571
break
568572
case "image":
569573
case "document":

‎src/main/groovy/au/org/ala/ecodata/paratoo/ParatooProtocolConfig.groovy

+3-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ class ParatooProtocolConfig {
148148
List features = []
149149
paths.each { String name, node ->
150150
if (node instanceof Boolean) {
151-
features.add(output[name])
151+
if (output[name])
152+
features.add(output[name])
152153
// todo later: add featureIds and modelId for compliance with feature behaviour of reports
153154
}
154155

@@ -335,6 +336,7 @@ class ParatooProtocolConfig {
335336
}
336337

337338
static Map createConvexHullGeoJSON (List features, String name, String externalId = "", String notes = "") {
339+
features = features.findAll { it.geometry != null }
338340
List featureGeometries = features.collect { it.geometry }
339341
Geometry geometry = GeometryUtils.getFeatureCollectionConvexHull(featureGeometries)
340342
[

0 commit comments

Comments
 (0)
Failed to load comments.