From d951340fb311b6b231430820c52074edcf9f52b2 Mon Sep 17 00:00:00 2001
From: Roland Olbricht The following examples are some sample use cases to give you an idea
what you can do with the system. Of course, there are many more useful
-use cases, and you are kindly invited to add other use cases.
Concepts
Data structures
+ Scripts and Rules
Control Flow
Variables
Other Sets in Scripts
@@ -84,7 +85,7 @@ Use Cases
@@ -138,7 +139,7 @@
-If you prefer to receive additionally all nodes any way refers to, you can change the script to: This script also will take some time before it gives a response depending on server load.
+If you prefer to receive additionally all nodes any way refers to, you can change the script to: This script also will take some time depending on server load before it gives a response.
+You may get into the situation that you don't find an area where you expect one. In particular, a coord-query like the first use case doesn't contain the data of an area although there exists for example a relation to create it. In this case, you can query the conflicts that prevented the respective area creation rule to create an area from this. The following script will try to find conflicts related to the relation of the German city "Wuppertal": You should replace "Wuppertal, Stadt" by a suitable value for you relation. +
+If you get an empty result from the first query, check whether there exists a relation at all: +
+If you already know the id of your relation, you can use instead the following to find conflicts: +
+We give a short overview of the used statement: the query <query type="relation"><has-kv k="name" v="Wuppertal, Stadt"/></query> searches for relations (this is specified by the parameter type) that have a tag with key "name" and value "Wuppertal, Stadt" (this condition is specified by the tag <has-kv k="name" v="Wuppertal, Stadt"/>. A full explanation of the quite versatile syntax of the query statement can be found in its documentation. The <id-query type="relation" ref="62478"/> by contrast finds the single relation with id 62478 as specified by the parameter ref. Both store their result into the default set because there is no other set specified. Then, the statement <report/> prints to the user all conflicts that are related to an item in its input, again the default set. It doesn't change any values in the script. Alternatively, the <print mode="body"/> simply prints the entire content of the default set. +
+ ++Not all relations that refer to ways give automatically rise to a relation. The server recognizes a certain relation (or any other designated set of ways) as an area if a rule matches this relation or set of ways. The amazing thing is that you (or anybody else) can add rules or change the existing ones. Now assume that you want to designate all relations with a tag with key "foo" and value "bar" to represent areas. +
+ ++You can retrieve an existing rule to get a blueprint for our new rule. For example, the following query will return the rule that creates areas from administrative units: +
+<osm-script name="Area::Create_from_admin_level" version="1">
+
+<query type="relation">
+ <has-kv k="admin_level"/>
+ <has-kv k="name"/>
+</query>
+<foreach into="rel">
+ <union>
+ <recurse type="relation-way" from="rel"/>
+ <recurse type="way-node"/>
+ </union>
+ <make-area pivot="rel" into="odd"/>
+ <detect-odd-nodes into="odd"/>
+ <foreach from="odd" into="i">
+ <union><item set="i"/><item set="rel"/></union>
+ <conflict>In <item set="rel"/>, the <item set="i"/> is contained in an odd number of segments.</conflict>
+ </foreach>
+</foreach>
+
+</osm-script>
+
+
+
++We take the following modifications: In the first line, we replace the name of the rule by a new, descriptive name because we are adding a new rule. We remove the version tag because this will be chosen by the server. Then, we replace the two lines starting with has-kv by a single line that describes the designation for the relations in question. Then we post the new rule to add_rule: +
+To avoid cluttering the server, please complete this tutorial with removing your rule. Just call update_rule with the empty rule and the parameter replace set to the version number just recieved: +
+We conclude by explaining the statements in the rule "Area::Create_from_admin_level": The first line <osm-script name="Area::Create_from_admin_level" version="1"> is an explicit statement of the root element because a rule needs always a name and the name is provided as parameter of the root element. The version tag is added by the server to indicate which version of the rule it has returned - in our example the most recent version which is by incidence 1. +
+ ++The first executable statement in the rule is the query-block <query type="relation"><has-kv k="admin_level"/><has-kv k="name"/></query>. This query-block searches for relations as specified by the parameter "type". It returns only relations that have a tag with key "admin_level" and a tag with key "name". For both tags, any values match the search criteria as there are no values specified in the has-kv tags. The results of the query are stored into the default set. A detailed description of the query syntax can be found in its documentation. +
+ ++The <foreach into="rel"> statement regulates the control flow: The body is executed once for each element in the input set. As there is no input set specified, the input is taken from the default set. The output set "rel" contains during each loop solely the respective element from the input set. +
+ ++The foreach-body starts with an union-block, containing the two statements <recurse type="relation-way" from="rel"/> and <recurse type="way-node"/>. The first one sets the default set to the set of all ways that are members of the relation in the input set "rel". The second sets the default set to the set of all nodes that are referred by ways from the default set. Because of the union-block wrapped around, the default set contains afterwards the ways that are members of the relation and their associated nodes. +
+ ++The statement <make-area pivot="rel" into="odd"/> now creates the area: It takes input from two different sets. The first one not specified, thus being the default set, contains the ways and nodes that decribe the spatial extent of the area; it contains any point that is separated from the south pole by an odd number of way segments. The second input set is specified by the pivot parameter. It should contain exactly one element, and the set "rel", set by foreach, does so. The area's id and tags are derived from this element. The output of make-area is the created area if any. It is simultanenously written to the output set as well as the database. The set is in our case redirected to the set "odd" as we don't need the area anymore. +
+ ++The <detect-odd-nodes into="odd"/> statement detects nodes that appear an odd times as starting or end points of a way. These nodes are exactly the nodes that prevent make-area from making an area. The detect-odd-nodes statement takes its input from the default set because there is no other set specified. The default set still contains the ways and nodes to produce an area from. The odd nodes are returned into the specified output set "odd". +
+ ++The <foreach from="odd" into="i"> statement loops over these nodes, which are stored in the input set "odd". Each node is during one loop available as content of the set "i". In the loop, the line <union><item set="i"/><item set="rel"/></union> sets the default set to the node of the inner loop and the relation from the outer loop: The <item set="i"/> statement returns the content of the set "i" as output, hence the node of the current inner loop. The <item set="rel"/> returns the set "rel" that contains the relation of the current outer loop. +
+ +
+Finally, the line <conflict>In <item set="rel"/>, the <item set="i"/> is contained in an odd number of segments.</conflict>
writes the conflict message into the database for the elements of the current inner and current outer loop. It obtains these elements from its input set, the default set. In the conflict message, the subtags <item set="rel"/> and <item set="i"/> are replaced by their contents. The conflict statement does not return anything. Then the script continues with another inner loop or outer loop respectively.
+
Data structures
+Scripts and Rules
Control Flow
Variables
Other Sets in Scripts
@@ -329,6 +834,11 @@