Skip to content

Commit

Permalink
Merge pull request #963 from AtlasOfLivingAustralia/feature/issue962
Browse files Browse the repository at this point in the history
Calculate area of compound site using features #962
  • Loading branch information
temi authored May 29, 2024
2 parents be58424 + 2ac2681 commit d216915
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
14 changes: 13 additions & 1 deletion grails-app/services/au/org/ala/ecodata/SiteService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,19 @@ class SiteService {

def populateLocationMetadataForSite(Map site) {

def siteGeom = geometryAsGeoJson(site)
Map siteGeom
if (site.type == Site.TYPE_COMPOUND) {
siteGeom = [
type:'GeometryCollection',
geometries: [
site.features.collect{it.geometry}
]
]
}
else {
siteGeom = geometryAsGeoJson(site)
}

if (siteGeom) {
GeometryJSON gjson = new GeometryJSON()
Geometry geom = gjson.read((siteGeom as JSON).toString())
Expand Down
37 changes: 37 additions & 0 deletions src/test/groovy/au/org/ala/ecodata/SiteServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,43 @@ class SiteServiceSpec extends MongoSpec implements ServiceUnitTest<SiteService>
sites.externalIds.idType == [[ExternalId.IdType.MONITOR_PLOT_GUID], [ExternalId.IdType.MONITOR_PLOT_GUID]]
}
def "The site area is calculated from the FeatureCollection for a compound site"() {
setup:
def coordinates = [[148.260498046875, -37.26530995561874], [148.260498046875, -37.26531995561874], [148.310693359375, -37.26531995561874], [148.310693359375, -37.26531995561874], [148.260498046875, -37.26530995561874]]
def extent = buildExtent('drawn', 'Polygon', coordinates)
Map site = [type: Site.TYPE_COMPOUND, extent: extent, features: [
[
type : "Feature",
geometry: [
type : "Polygon",
coordinates: coordinates
]
],
[
type : "Feature",
geometry: [
type : "Polygon",
coordinates: coordinates
]
]
]]
when:
service.populateLocationMetadataForSite(site)
then:
1 * spatialServiceMock.intersectGeometry(_, _) >> [:]
site.extent.geometry.aream2 == 4938.9846950349165d
when:
site.type = Site.TYPE_WORKS_AREA
service.populateLocationMetadataForSite(site)
then:
1 * spatialServiceMock.intersectGeometry(_, _) >> [:]
site.extent.geometry.aream2 == 2469.492347517461
}
private Map buildExtent(source, type, coordinates, pid = '') {
return [source:source, geometry:[type:type, coordinates: coordinates, pid:pid]]
Expand Down

0 comments on commit d216915

Please sign in to comment.