[OSM-talk] Finding what country something is in (new website)
Roland Olbricht
roland.olbricht at gmx.de
Sat Aug 1 14:08:55 BST 2009
> Something that would also be very cool would be if the script told you
> all polygons or multipolygons you're in regardless of whether they are
> a relation or normal polygon, and you could filter the result for
> country boundaries or other type of areas. It could for example tell
> you you're in a building in a school area in a residential area in a
> county in a province in a country on an island.
It's a question of a proper specification. Then you can add the rules by
yourself. Please have a look at
http://78.46.81.38/#section.rule_example
Currently, the areas are created based on the two rules
<osm-script name="Area::Create_from_admin_level">
<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>
and
<osm-script name="Area::Create_from_multipolygon">
<query type="relation">
<has-kv k="type" v="multipolygon"/>
<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>
These rules translate as follows:
Consider every relation that has a tag with key "admin_level" and a tag with
key "name". Create a polygon from all the member ways. If this fails, attach
a message "In relation $Rel, the node $Node is contained in an odd number of
segments" to this relation.
and
Consider every relation that has a tag with key "type" value "multipolygon"
and a tag with key "name". Create a polygon from all the member ways. If
this fails ...
Thus, if you think of a rule like
Consider every way that has a tag with key "type" and value "multipolygon"
and a tag with key "name". Create a polygon from this way. If this fails ...
this translates to
<osm-script name="Area::Create_from_multipolygon">
<query type="way">
<has-kv k="type" v="multipolygon"/>
<has-kv k="name"/>
</query>
<foreach into="way">
<union>
<item set="way"/>
<recurse type="way-node" from="way"/>
</union>
<make-area pivot="way" into="odd"/>
<detect-odd-nodes into="odd"/>
<foreach from="odd" into="i">
<union><item set="i"/><item set="way"/></union>
<conflict>In <item set="rel"/>, the <item set="i"/> is contained in an odd
number of segments.</conflict>
</foreach>
</foreach>
</osm-script>
You just can submit the rule (or any other rule) as described on
http://78.46.81.38/#section.rule_example
and some hours later it should be processed. Feel free to ask if you have any
questions.
Cheers,
Roland
More information about the talk
mailing list