From e8150775f1c521828a2b24b12fe7cd2cbb39bd89 Mon Sep 17 00:00:00 2001 From: temi Date: Wed, 15 May 2024 16:29:47 +1000 Subject: [PATCH] #941 - fixes null pointer issue where geometry points are null or an empty list --- .../au/org/ala/ecodata/ParatooService.groovy | 58 ++++++++++--------- .../paratoo/ParatooProtocolConfig.groovy | 4 +- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/grails-app/services/au/org/ala/ecodata/ParatooService.groovy b/grails-app/services/au/org/ala/ecodata/ParatooService.groovy index 8118981cc..687d96936 100644 --- a/grails-app/services/au/org/ala/ecodata/ParatooService.groovy +++ b/grails-app/services/au/org/ala/ecodata/ParatooService.groovy @@ -535,35 +535,39 @@ class ParatooService { // used by protocols like bird survey where a point represents a sight a bird has been observed in a // bird survey plot def location = output[model.name] - if (location instanceof Map) { - output[model.name] = [ - type : 'Feature', - geometry : [ - type : 'Point', - coordinates: [location.lng, location.lat] - ], - properties: [ - name : "Point ${formName}-${featureId}", - externalId: location.id, - id: "${formName}-${featureId}" - ] - ] - } - else if (location instanceof List) { - String name - switch (config?.geometryType) { - case "LineString": - name = "LineString ${formName}-${featureId}" - output[model.name] = ParatooProtocolConfig.createLineStringFeatureFromGeoJSON (location, name, null, name) - break - default: - name = "Polygon ${formName}-${featureId}" - output[model.name] = ParatooProtocolConfig.createFeatureFromGeoJSON (location, name, null, name) - break + if (location) { + if (location instanceof Map) { + output[model.name] = [ + type : 'Feature', + geometry : [ + type : 'Point', + coordinates: [location.lng, location.lat] + ], + properties: [ + name : "Point ${formName}-${featureId}", + externalId: location.id, + id : "${formName}-${featureId}" + ] + ] + } else if (location instanceof List) { + String name + switch (config?.geometryType) { + case "LineString": + name = "LineString ${formName}-${featureId}" + output[model.name] = ParatooProtocolConfig.createLineStringFeatureFromGeoJSON(location, name, null, name) + break + default: + name = "Polygon ${formName}-${featureId}" + output[model.name] = ParatooProtocolConfig.createFeatureFromGeoJSON(location, name, null, name) + break + } } - } - featureId ++ + featureId ++ + } + else { + output[model.name] = null + } break case "image": case "document": diff --git a/src/main/groovy/au/org/ala/ecodata/paratoo/ParatooProtocolConfig.groovy b/src/main/groovy/au/org/ala/ecodata/paratoo/ParatooProtocolConfig.groovy index 5fe58fd2f..68bc3277e 100644 --- a/src/main/groovy/au/org/ala/ecodata/paratoo/ParatooProtocolConfig.groovy +++ b/src/main/groovy/au/org/ala/ecodata/paratoo/ParatooProtocolConfig.groovy @@ -148,7 +148,8 @@ class ParatooProtocolConfig { List features = [] paths.each { String name, node -> if (node instanceof Boolean) { - features.add(output[name]) + if (output[name]) + features.add(output[name]) // todo later: add featureIds and modelId for compliance with feature behaviour of reports } @@ -335,6 +336,7 @@ class ParatooProtocolConfig { } static Map createConvexHullGeoJSON (List features, String name, String externalId = "", String notes = "") { + features = features.findAll { it.geometry != null } List featureGeometries = features.collect { it.geometry } Geometry geometry = GeometryUtils.getFeatureCollectionConvexHull(featureGeometries) [