0
1

Dear all,

Working hard in the Collect Survey Designer ( found a video to design Collect Earth surveys in youtube ) and I am trying to design a couple of new surveys.

I have managed to get a few XPath validation expressions working but I must admit I am a bit lost... could anyone point me in the right direction of what should I learn, or what are kind of general XPath functions one can use???

Validations, default values and the possibility to show/hide attributes in the interface depending on other values is a strong feature, but documentation is weak...

Thanks!!

asked 11 May '16, 20:24

collector's gravatar image

collector
2671626
accept rate: 0%


Hi...I have written a document with some XPath examples, based on two inheritance hierarchies among the entities: one more complex (cluster->plot) and one simpler (only plot). See below:

Link to document : HERE

EXAMPLES OF CODE IN OPEN FORIS Collect

General hierarchical structures (either cluster or plot-based)

Comparison checks (i.e., start_date, start_time, end_time, tree_no, azimuth, tree distance,dbh, total_height and bole_height):

Example attribute (number type): Path: /plot/details/elevation

Severity Error

Message Elevation must be between 0 and 4000 m 0 <= elevation <= 4000

Example attribute (date type): Path: /cluster/start_date

Severity Error

Message You have written the starting date in the future!

start_date <= idm:currentDate()

Example attribute (time type): Path: /cluster/start_time

Severity Warning

Message Working hours for the survey should be from 06:00 to 19:00!

0600 < start_time <= 1900

Example attribute (time type): Path: /cluster/end_time

Severity Error

Message End time should be always after start time

start_time <= end_time

(Here we assume that start_time and end_time are under the same entity, i.e., cluster, or plot)

Example attribute (number type): Path: /cluster/plot/tree/tree_no

Severity Error

Message tree number must be >0

0 < tree_no

Example attribute (number type): Path: /cluster/plot/tree/azimuth

Severity Error

Message angle must be between 0 (inclusive) and 360 (exclusive)

0 <= azimuth < 360

Example attribute (number type, refers to tree distance): Path: /cluster/plot/tree/distance

Severity Error

Message tree distance must be positive

0 <= distance

Severity Error

Message tree outside of plot. Plot radius is 12 m.

distance <= 12

Example attribute (number type): Path: /cluster/plot/tree/dbh

Severity Warning

Message Unusually large dbh

dbh < 200

Severity Error

Message dbh must be positive

0 <= dbh

Severity Error

Message tree must be at least 20 cm if distance>2 m

20 <= dbh Apply when distance>2

Severity Error

Message tree must be at least 5 cm in any case

5 <= dbh

Example attribute (number type): Path: /cluster/plot/tree/total_height

Severity Warning

Message Unusually tall tree

total_height < 80

Severity Error

Message Impossibly tall tree

total_height < 150

Severity Error

Message height must be positive

0 <= total_height

Example attribute (number type): Path: /cluster/plot/tree/bole_height

Severity Error

Message bole height must be positive

0 <= bole_height

Severity Error

Message bole height must be less or equal than total height

bole_height <= total_height

Default values (i.e., start_date, start_time and tree_no):

Example attribute (date type): Path: /cluster/start_date

Calculated value expressions: Expression: idm:currentDate()

Example attribute (time type): Path: /cluster/start_time

Calculated value expressions: Expression: idm:currentTime()

Example attribute (number type): Path: /plot/tree/tree_id

Calculated value expressions:
Expression: math:max(parent()/tree/tree_id) + 1

(it will automatically increase the number every time a new tree is recorded in the plot) Surveys with Plot as sampling unit or root entity and tree as sub-entity

Distance checks (i.e., plot position):

Example attribute: Path: /plot/details/position

Severity Error

Message You are more than 50 m from plot location

Destination point idm:samplingPointCoordinate(parent()/plot_id)

Max distance (m) 50

Severity Warning

Message You are more than 20 m from plot location

Destination point

idm:samplingPointCoordinate( parent()/plot_id)

Max distance (m) 20

Autocompletion (click Calculated in the General tab fot the variable) in optional variables from sample design file (i.e., province as a column after design point coordinates in the sampling_design imported file):

Example attribute (text type): Path: /plot/details/province

Calculated value expressions:
Expression: idm:samplingPointData('province', parent()/plot_id)

Requirednes of variable if expression is satisfied (i.e., tree_height only required every three third tree):

Example attribute (text type): Path: /plot/tree/tree_height Required only when expression is verified: tree_id mod 3 = 0

Surveys with Cluster as sampling unit or root entity and plot and tree as sub-entities

Distance checks (i.e., plot position):

Example attribute: Path: /cluster/plot/details/position Severity Error Message You are more than 100 m from plot location Destination point idm:samplingPointCoordinate(parent()/parent()/cluster_no, parent()/plot_no) Max distance (m) 100 Severity Warning Message You are more than 20 m from plot location Destination point idm:samplingPointCoordinate(parent()/parent()/cluster_no, parent()/plot_no) Max distance (m) 20

Autocompletion(click Calculated in the General tab fot the variable) in optional variables from sample design file (i.e., province as a column after design point coordinates in the sampling_design imported file):

Example attribute (text type): Path: /cluster/location/province

Calculated value expressions:
Expression: idm:samplingPointData('province', parent()/cluster_no)

Example attribute (text type): Path: /cluster/plot/details/province

Calculated value expressions:
Expression: idm:samplingPointData('province', parent()/plot_no) Autocompletion (click Calculated in the General tab fot the variable) in tree-related variable (i.e., tree count):

Example attribute (number type): Path: /cluster/plot/tree_count

Calculated value expressions: Expression: math:max(parent()/plot/tree/tree_no)

Relevance of variable if expression is satisfied (i.e., tree_count, plot position, and tree entity):

Example attribute (number type): Path: /cluster/plot/tree_count

Relevant only when expression is verified: parent()/plot/details/accessibility=0

Example attribute (coordinates type): Path: /cluster/plot/details/position

Relevant only when expression is verified: accessibility=0 (here we don’t need a hierarchical path since position and accessibility belong to the same hierarchy, i.e: parent()/plot/details/position and parent()/plot/details/accessibility)

Example entity (multiple table layout): Path: /cluster/plot/tree

Relevant only when expression is verified: details/accessibility=0

permanent link

answered 12 May '16, 11:34

javier's gravatar image

javier
412
accept rate: 0%

edited 12 May '16, 11:51

Open%20Foris's gravatar image

Open Foris ♦♦
9995714

This is a common question, as the XPath is a language that can be a bit complex for non-programmers, but don't panic, it is really not that hard (and actually quite logical)

You can start by looking into the Collect documentation here :

Open Foris Wiki : XPath documentation

W3Schools also has some more in-depth tutorial in XPath

permanent link

answered 11 May '16, 20:54

collectearth's gravatar image

collectearth ♦
1.0k16
accept rate: 17%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×493
×170

question asked: 11 May '16, 20:24

question was seen: 7,406 times

last updated: 12 May '16, 11:51