Skip to content

Commit 12b6dc2

Browse files
committed
- more geometry fixes - fixed null pointer exception - fixed issue with searching for an object by name and subsequent caching of null value
1 parent 8bcc854 commit 12b6dc2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

grails-app/services/au/org/ala/ecodata/SpatialService.groovy

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,22 @@ class SpatialService {
5656
if (geoJson.type != 'GeometryCollection') {
5757
int length = geoJson?.toString().size()
5858
if (length > threshold) {
59+
geo = GeometryUtils.geoJsonMapToGeometry (geoJson)
5960
geoJson = GeometryUtils.geometryToGeoJsonMap(geo.getEnvelope())
6061
}
6162

6263
geo = GeometryUtils.geoJsonMapToGeometry (geoJson)
64+
if (!geo.isValid()) {
65+
geo = geo.buffer(0)
66+
}
6367
wkt = geo.toText()
6468
} else {
6569
geo = GeometryUtils.geoJsonMapToGeometry (geoJson)
6670
GeometryCollection geometryCollection = (GeometryCollection)geo
71+
if(!geometryCollection.isValid()) {
72+
geometryCollection = geometryCollection.buffer(0)
73+
}
74+
6775
Geometry convexHullGeometry = geometryCollection.union().convexHull()
6876
wkt = convexHullGeometry.toText()
6977
}
@@ -308,13 +316,13 @@ class SpatialService {
308316

309317
@Cacheable(value = "spatialSearchObject", key = { query.toUpperCase() + fids.toUpperCase() })
310318
Map searchObject(String query, String fids = "") {
311-
query = URLEncoder.encode(query, 'UTF-8').replaceAll('\\+', '%20')
312-
String url = grailsApplication.config.getProperty('spatial.baseUrl')+"/ws/search?q=$query&include=$fids"
319+
String urlquery = URLEncoder.encode(query, 'UTF-8').replaceAll('\\+', '%20')
320+
String url = grailsApplication.config.getProperty('spatial.baseUrl')+"/ws/search?q=$urlquery&include=$fids"
313321
def resp = webService.getJson(url)
314322
if ((resp instanceof Map) || !resp)
315-
return
323+
return [:]
316324

317-
def result = resp?.find { it.name?.toUpperCase() == query?.toUpperCase() }
325+
def result = resp?.find { it.name?.toUpperCase() == query?.toUpperCase() } ?: [:]
318326
deepCopy(result)
319327
}
320328

0 commit comments

Comments
 (0)