Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- fixes null pointer issue where geometry points are null or an empty list
  • Loading branch information
temi committed May 15, 2024
1 parent 413ff34 commit e815077
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
58 changes: 31 additions & 27 deletions grails-app/services/au/org/ala/ecodata/ParatooService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
[
Expand Down

0 comments on commit e815077

Please sign in to comment.