@@ -12,7 +12,8 @@ import org.locationtech.jts.geom.Geometry
12
12
@Slf4j
13
13
@JsonIgnoreProperties ([' metaClass' , ' errors' , ' expandoMetaClass' ])
14
14
class ParatooProtocolConfig {
15
-
15
+ static final String FAUNA_PLOT = ' Fauna plot'
16
+ static final String CORE_PLOT = ' Core monitoring plot'
16
17
String name
17
18
String apiEndpoint
18
19
boolean usesPlotLayout = true
@@ -26,7 +27,9 @@ class ParatooProtocolConfig {
26
27
String plotVisitPath = ' plot_visit'
27
28
String plotLayoutPath = " ${ plotVisitPath} .plot_layout"
28
29
String plotLayoutIdPath = " ${ plotLayoutPath} .id"
30
+ String plotLayoutUpdatedAtPath = " ${ plotLayoutPath} .updatedAt"
29
31
String plotLayoutPointsPath = " ${ plotLayoutPath} .plot_points"
32
+ String faunaPlotPointPath = " ${ plotLayoutPath} .fauna_plot_point"
30
33
String plotSelectionPath = " ${ plotLayoutPath} .plot_selection"
31
34
String plotLayoutDimensionLabelPath = " ${ plotLayoutPath} .plot_dimensions.label"
32
35
String plotLayoutTypeLabelPath = " ${ plotLayoutPath} .plot_type.label"
@@ -79,6 +82,16 @@ class ParatooProtocolConfig {
79
82
return removeMilliseconds(date)
80
83
}
81
84
85
+ Date getPlotLayoutUpdatedAt (Map surveyData ) {
86
+ def date = getProperty(surveyData, plotLayoutUpdatedAtPath)
87
+ if (! date) {
88
+ date = getPropertyFromSurvey(surveyData, plotLayoutUpdatedAtPath)
89
+ }
90
+
91
+ date = getFirst(date)
92
+ date ? DateUtil . parseWithMilliseconds(date) : null
93
+ }
94
+
82
95
Map getSurveyId (Map surveyData ) {
83
96
if (surveyIdPath == null || surveyData == null ) {
84
97
return null
@@ -203,7 +216,11 @@ class ParatooProtocolConfig {
203
216
geoJson = extractSiteDataFromPlotVisit(output)
204
217
// get list of all features associated with observation
205
218
if (geoJson && form && output) {
206
- geoJson. features = extractFeatures(output, form)
219
+ List features = extractFeatures(output, form)
220
+ if (features) {
221
+ features. addAll(geoJson. features?: [])
222
+ geoJson = createConvexHullGeoJSON(features, geoJson. properties. name, geoJson. properties. externalId)
223
+ }
207
224
}
208
225
}
209
226
else if (geometryPath) {
@@ -212,20 +229,10 @@ class ParatooProtocolConfig {
212
229
else if (form && output) {
213
230
List features = extractFeatures(output, form)
214
231
if (features) {
215
- List featureGeometries = features. collect { it. geometry }
216
- Geometry geometry = GeometryUtils . getFeatureCollectionConvexHull(featureGeometries)
217
232
String startDateInString = getStartDate(output)
218
233
startDateInString = DateUtil . convertUTCDateToStringInTimeZone(startDateInString, clientTimeZone?: TimeZone . default)
219
234
String name = " ${ form.name} site - ${ startDateInString} "
220
- geoJson = [
221
- type : ' Feature' ,
222
- geometry : GeometryUtils . geometryToGeoJsonMap(geometry),
223
- properties : [
224
- name : name,
225
- description : " ${ name} (convex hull of all features)" ,
226
- ],
227
- features : features
228
- ]
235
+ geoJson = createConvexHullGeoJSON(features, name)
229
236
}
230
237
}
231
238
@@ -313,6 +320,8 @@ class ParatooProtocolConfig {
313
320
log. warn(" No plot_layout found in survey at path ${ plotLayoutIdPath} " )
314
321
return null
315
322
}
323
+ else
324
+ plotLayoutId = plotLayoutId. toString()
316
325
List plotLayoutPoints = getProperty(surveyData, plotLayoutPointsPath)
317
326
Map plotSelection = getProperty(surveyData, plotSelectionPath)
318
327
Map plotSelectionGeoJson = plotSelectionToGeoJson(plotSelection)
@@ -322,16 +331,33 @@ class ParatooProtocolConfig {
322
331
323
332
String name = plotSelectionGeoJson. properties. name + ' - ' + plotLayoutTypeLabel + ' (' + plotLayoutDimensionLabel + ' )'
324
333
325
- Map plotGeoJson = createFeatureFromGeoJSON(plotLayoutPoints, name, plotLayoutId, plotSelectionGeoJson?. properties?. notes)
326
-
327
- // Map faunaPlotGeoJson = toGeometry(plotLayout.fauna_plot_point )
334
+ Map plotGeoJson = createFeatureFromGeoJSON(plotLayoutPoints, name, plotLayoutId, " ${ CORE_PLOT } ${ plotSelectionGeoJson?.properties?.notes?:"" } " )
335
+ List faunaPlotPoints = getProperty(surveyData, faunaPlotPointPath)
336
+ Map faunaPlotGeoJson = createFeatureFromGeoJSON(faunaPlotPoints, name, plotLayoutId, " ${ FAUNA_PLOT } ${ plotSelectionGeoJson?.properties?.notes?:"" } " )
328
337
329
- // TODO maybe turn this into a feature with properties to distinguish the fauna plot?
330
- // Or a multi-polygon?
338
+ if (faunaPlotGeoJson) {
339
+ List features = [plotGeoJson, faunaPlotGeoJson]
340
+ plotGeoJson = createConvexHullGeoJSON(features, name, plotLayoutId)
341
+ }
331
342
332
343
plotGeoJson
333
344
}
334
345
346
+ static Map createConvexHullGeoJSON (List features , String name , String externalId = " " ) {
347
+ List featureGeometries = features. collect { it. geometry }
348
+ Geometry geometry = GeometryUtils . getFeatureCollectionConvexHull(featureGeometries)
349
+ [
350
+ type : ' Feature' ,
351
+ geometry : GeometryUtils . geometryToGeoJsonMap(geometry),
352
+ properties : [
353
+ name : name,
354
+ externalId : externalId,
355
+ description : " ${ name} (convex hull of all features)" ,
356
+ ],
357
+ features : features
358
+ ]
359
+ }
360
+
335
361
static Map createFeatureFromGeoJSON (List plotLayoutPoints , String name , def plotLayoutId , String notes = " " ) {
336
362
Map plotGeometry = toGeometry(plotLayoutPoints)
337
363
createFeatureObject(plotGeometry, name, plotLayoutId, notes)
0 commit comments