Skip to content

Commit

Permalink
Updated project area indexing to retrieve valid geoJSON & simplify if…
Browse files Browse the repository at this point in the history
… necessary
  • Loading branch information
jack-brinkman committed Sep 19, 2024
1 parent b7b3818 commit 72d129b
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions grails-app/conf/application.groovy
Original file line number Diff line number Diff line change
@@ -1042,6 +1042,8 @@ license.default = "https://creativecommons.org/licenses/by-nc/3.0/au/"
projectActivity.notifyOnChange=true
biocollect.baseURL="https://biocollect.ala.org.au"
biocollect.projectActivityDataURL="${biocollect.baseURL}/bioActivity/projectRecords"
biocollect.projectArea.simplificationThreshold=10000
biocollect.projectArea.simplificationTolerance=0.1

// elasticsearch cluster setting
// can transport layer connection be made from apps outside JVM
Original file line number Diff line number Diff line change
@@ -1093,7 +1093,7 @@ class ElasticSearchService {
// GeoServer requires a single attribute with project area. Cannot use `sites` property (above) since it has
// all sites associated with project.
// todo: Check if BioCollect requires all sites in `sites` property. If no, merge `projectArea` with `sites`.
projectMap.projectArea = siteService.get(project.projectSiteId, [SiteService.FLAT, SiteService.INDEXING])
projectMap.projectArea = siteService.getSimpleProjectArea(projectMap.projectSiteId)
projectMap.containsActivity = activityService.searchAndListActivityDomainObjects([projectId: projectMap.projectId], null, null, null, [max: 1, offset: 0])?.totalCount > 0
}
projectMap.sites?.each { site ->
3 changes: 2 additions & 1 deletion grails-app/services/au/org/ala/ecodata/ProjectService.groovy
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import au.org.ala.ecodata.converter.SciStarterConverter
import grails.converters.JSON
import grails.core.GrailsApplication
import groovy.json.JsonSlurper
import org.codehaus.jackson.map.ObjectMapper
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.context.MessageSource
import org.springframework.web.servlet.i18n.SessionLocaleResolver

@@ -746,6 +746,7 @@ class ProjectService {
* And link artifacts to the project. TODO: creating project extent.
* @return
*/
@Scheduled(cron = "0 0 * * 0")
Map importProjectsFromSciStarter() {
int ignoredProjects = 0, createdProjects = 0, updatedProjects = 0, page = 1
JsonSlurper slurper = new JsonSlurper()
23 changes: 23 additions & 0 deletions grails-app/services/au/org/ala/ecodata/SiteService.groovy
Original file line number Diff line number Diff line change
@@ -255,6 +255,29 @@ class SiteService {
site
}

def getSimpleProjectArea(projectSiteId) {
def threshold = grailsApplication.config.getProperty('biocollect.projectArea.simplificationThreshold')
def tolerance = grailsApplication.config.getProperty('biocollect.projectArea.simplificationTolerance')
log.info("Threshhold ${threshold} Tolerance ${tolerance}")

def site = get(projectSiteId, [SiteService.FLAT, SiteService.INDEXING])

if (site != null) {
def projectArea = geometryAsGeoJson(site)

if (projectArea?.coordinates != null) {
def coordsSize = projectArea.coordinates.flatten().size()
if (coordsSize > threshold) {
GeometryUtils.simplify(projectArea, tolerance)
} else {
projectArea
}
}
}

site
}

def create(props) {
// assert getCommonService()
def site = new Site(siteId: Identifiers.getNew(true,''))

0 comments on commit 72d129b

Please sign in to comment.