Skip to content

Commit

Permalink
Merge pull request #1022 from AtlasOfLivingAustralia/feature/issue3292
Browse files Browse the repository at this point in the history
more geometry fixes and others - AtlasOfLivingAustralia/fieldcapture#3292
  • Loading branch information
chrisala authored Sep 25, 2024
2 parents 02ebb01 + 12b6dc2 commit 3fedd33
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions grails-app/services/au/org/ala/ecodata/SpatialService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,22 @@ class SpatialService {
if (geoJson.type != 'GeometryCollection') {
int length = geoJson?.toString().size()
if (length > threshold) {
geo = GeometryUtils.geoJsonMapToGeometry (geoJson)
geoJson = GeometryUtils.geometryToGeoJsonMap(geo.getEnvelope())
}

geo = GeometryUtils.geoJsonMapToGeometry (geoJson)
if (!geo.isValid()) {
geo = geo.buffer(0)
}
wkt = geo.toText()
} else {
geo = GeometryUtils.geoJsonMapToGeometry (geoJson)
GeometryCollection geometryCollection = (GeometryCollection)geo
if(!geometryCollection.isValid()) {
geometryCollection = geometryCollection.buffer(0)
}

Geometry convexHullGeometry = geometryCollection.union().convexHull()
wkt = convexHullGeometry.toText()
}
Expand Down Expand Up @@ -308,13 +316,13 @@ class SpatialService {

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

def result = resp?.find { it.name?.toUpperCase() == query?.toUpperCase() }
def result = resp?.find { it.name?.toUpperCase() == query?.toUpperCase() } ?: [:]
deepCopy(result)
}

Expand Down

0 comments on commit 3fedd33

Please sign in to comment.