@@ -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
@@ -135,7 +148,8 @@ class ParatooProtocolConfig {
135
148
List features = []
136
149
paths. each { String name , node ->
137
150
if (node instanceof Boolean ) {
138
- features. add(output[name])
151
+ if (output[name])
152
+ features. add(output[name])
139
153
// todo later: add featureIds and modelId for compliance with feature behaviour of reports
140
154
}
141
155
@@ -201,31 +215,17 @@ class ParatooProtocolConfig {
201
215
Map geoJson = null
202
216
if (usesPlotLayout) {
203
217
geoJson = extractSiteDataFromPlotVisit(output)
204
- // get list of all features associated with observation
205
- if (geoJson && form && output) {
206
- geoJson. features = extractFeatures(output, form)
207
- }
208
218
}
209
219
else if (geometryPath) {
210
220
geoJson = extractSiteDataFromPath(output)
211
221
}
212
222
else if (form && output) {
213
223
List features = extractFeatures(output, form)
214
224
if (features) {
215
- List featureGeometries = features. collect { it. geometry }
216
- Geometry geometry = GeometryUtils . getFeatureCollectionConvexHull(featureGeometries)
217
225
String startDateInString = getStartDate(output)
218
226
startDateInString = DateUtil . convertUTCDateToStringInTimeZone(startDateInString, clientTimeZone?: TimeZone . default)
219
227
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
- ]
228
+ geoJson = createConvexHullGeoJSON(features, name)
229
229
}
230
230
}
231
231
@@ -307,12 +307,13 @@ class ParatooProtocolConfig {
307
307
308
308
private Map extractSiteDataFromPlotVisit (Map survey ) {
309
309
Map surveyData = getSurveyData(survey)
310
- def plotLayoutId = getProperty(surveyData, plotLayoutIdPath) // Currently an int, may become uuid?
310
+ String plotLayoutId = getProperty(surveyData, plotLayoutIdPath) // Currently an int, may become uuid?
311
311
312
312
if (! plotLayoutId) {
313
313
log. warn(" No plot_layout found in survey at path ${ plotLayoutIdPath} " )
314
314
return null
315
315
}
316
+
316
317
List plotLayoutPoints = getProperty(surveyData, plotLayoutPointsPath)
317
318
Map plotSelection = getProperty(surveyData, plotSelectionPath)
318
319
Map plotSelectionGeoJson = plotSelectionToGeoJson(plotSelection)
@@ -322,22 +323,41 @@ class ParatooProtocolConfig {
322
323
323
324
String name = plotSelectionGeoJson. properties. name + ' - ' + plotLayoutTypeLabel + ' (' + plotLayoutDimensionLabel + ' )'
324
325
325
- Map plotGeoJson = createFeatureFromGeoJSON(plotLayoutPoints, name, plotLayoutId, plotSelectionGeoJson?. properties?. notes)
326
-
327
- // Map faunaPlotGeoJson = toGeometry(plotLayout.fauna_plot_point)
326
+ Map plotGeoJson = createFeatureFromGeoJSON(plotLayoutPoints, name, plotLayoutId, " ${ CORE_PLOT} ${ plotSelectionGeoJson?.properties?.notes?:""} " )
327
+ List faunaPlotPoints = getProperty(surveyData, faunaPlotPointPath)
328
328
329
- // TODO maybe turn this into a feature with properties to distinguish the fauna plot?
330
- // Or a multi-polygon?
329
+ if (faunaPlotPoints) {
330
+ Map faunaPlotGeoJson = createFeatureFromGeoJSON(faunaPlotPoints, name, plotLayoutId, " ${ FAUNA_PLOT} ${ plotSelectionGeoJson?.properties?.notes?:""} " )
331
+ List features = [plotGeoJson, faunaPlotGeoJson]
332
+ plotGeoJson = createConvexHullGeoJSON(features, name, plotLayoutId, plotGeoJson. properties. notes)
333
+ }
331
334
332
335
plotGeoJson
333
336
}
334
337
335
- static Map createFeatureFromGeoJSON (List plotLayoutPoints , String name , def plotLayoutId , String notes = " " ) {
338
+ static Map createConvexHullGeoJSON (List features , String name , String externalId = " " , String notes = " " ) {
339
+ features = features. findAll { it. geometry != null }
340
+ List featureGeometries = features. collect { it. geometry }
341
+ Geometry geometry = GeometryUtils . getFeatureCollectionConvexHull(featureGeometries)
342
+ [
343
+ type : ' Feature' ,
344
+ geometry : GeometryUtils . geometryToGeoJsonMap(geometry),
345
+ properties : [
346
+ name : name,
347
+ externalId : externalId,
348
+ notes : notes,
349
+ description : " ${ name} (convex hull of all features)" ,
350
+ ],
351
+ features : features
352
+ ]
353
+ }
354
+
355
+ static Map createFeatureFromGeoJSON (List plotLayoutPoints , String name , String plotLayoutId , String notes = " " ) {
336
356
Map plotGeometry = toGeometry(plotLayoutPoints)
337
357
createFeatureObject(plotGeometry, name, plotLayoutId, notes)
338
358
}
339
359
340
- static Map createFeatureObject (Map plotGeometry , String name , plotLayoutId , String notes = " " ) {
360
+ static Map createFeatureObject (Map plotGeometry , String name , String plotLayoutId , String notes = " " ) {
341
361
[
342
362
type : ' Feature' ,
343
363
geometry : plotGeometry,
@@ -362,7 +382,7 @@ class ParatooProtocolConfig {
362
382
plotGeometry
363
383
}
364
384
365
- static Map createLineStringFeatureFromGeoJSON (List plotLayoutPoints , String name , def plotLayoutId , String notes = " " ) {
385
+ static Map createLineStringFeatureFromGeoJSON (List plotLayoutPoints , String name , String plotLayoutId , String notes = " " ) {
366
386
Map plotGeometry = toLineStringGeometry(plotLayoutPoints)
367
387
createFeatureObject(plotGeometry, name, plotLayoutId, notes)
368
388
}
0 commit comments