Skip to content

Commit

Permalink
Merge pull request #1024 from AtlasOfLivingAustralia/feature/issue3292
Browse files Browse the repository at this point in the history
update sites of a list of projects AtlasOfLivingAustralia/fieldcapture#3292
  • Loading branch information
chrisala authored Sep 26, 2024
2 parents 97a23de + 76c9a3d commit 872d75d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
13 changes: 10 additions & 3 deletions grails-app/controllers/au/org/ala/ecodata/AdminController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ class AdminController {
dateFormat.setTimeZone(timeZoneUTC)
def isMERIT = params.getBoolean('isMERIT', true)
Date startDate = params.getDate("startDate", ["yyyy", "yyyy-MM-dd"]) ?: dateFormat.parse(defaultStartDate)
List siteIds = params.get("siteId")?.split(",")
List siteIds = params.get("siteId")?.split(",") ?: []
List projectIds = params.get("projectId")?.split(",") ?: []
def code = 'success'
def total = 0
def offset = 0
Expand All @@ -281,8 +282,14 @@ class AdminController {
List<String> defaultFids = metadataService.getSpatialLayerIdsToIntersect()
log.debug("Number of fids to intersect: ${defaultFids.size()}; they are - ${defaultFids}")
def totalSites
List projectIds = []
if (siteIds) {
if (projectIds) {
projectIds.each {
siteIds.addAll(siteService.findAllSiteIdsForProject(it))
}

totalSites = siteIds.size()
}
else if (siteIds) {
totalSites = siteIds.size()
}
else if (isMERIT) {
Expand Down
18 changes: 12 additions & 6 deletions grails-app/services/au/org/ala/ecodata/SpatialService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import grails.core.GrailsApplication
import grails.plugin.cache.Cacheable
import groovy.json.JsonParserType
import groovy.json.JsonSlurper
import org.locationtech.jts.geom.Coordinate
import org.locationtech.jts.geom.Geometry
import org.locationtech.jts.geom.GeometryCollection
import org.locationtech.jts.geom.GeometryFactory
import org.locationtech.jts.geom.*
import org.locationtech.jts.io.WKTReader

import static ParatooService.deepCopy
Expand Down Expand Up @@ -73,8 +70,17 @@ class SpatialService {
correctGeometry = geometryCollection.buffer(0)
}

Geometry convexHullGeometry = correctGeometry.union().convexHull()
wkt = convexHullGeometry.toText()
Geometry convexHullGeometry
try {
convexHullGeometry = correctGeometry.union().convexHull()
}
catch (TopologyException e) {
log.error("Error creating convex hull for geometry collection")
convexHullGeometry = correctGeometry.buffer(0).union().convexHull()
}
finally {
wkt = convexHullGeometry?.toText()
}
}

String url = grailsApplication.config.getProperty('spatial.baseUrl')+WKT_INTERSECT_URL_PREFIX
Expand Down

0 comments on commit 872d75d

Please sign in to comment.