Th:ความสัมพันธ์

ความสัมพันธ์ (Relation) เป็นการรวบรวมที่มีโครงสร้างของวัตถุ ซึ่งได้แก่โหนด ทาง และความสัมพันธ์อื่น โดยความสัมพันธ์เป็นหนึ่งในองค์ประกอบหลักของแบบจำลองข้อมูล OpenStreetMap โดยองค์ประกอบอื่นนั้นได้แก่ โหนด และทาง
องค์ประกอบความสัมพันธ์ โดยอยางน้อยต้องมีแท็ก type=*
และกลุ่มของ สมาชิก ซึ่งจะประกอบไปด้วยรายการของโหนด ทาง และความสัมพันธ์อื่น ทั้งหมด 1 อย่างหรือมากกว่า ความสัมพันธ์นั้นใช้ในการนิยามความสัมพันธ์ทางภูมิศาสตร์ หรือทางตรรกะระหว่างวัตถุที่แตกต่างกัน (อาทิเช่น ทะเลสาบและเกาะในทะเลสาบ หรือถนนหลายเส้นที่ร่วมกันเป็นเส้นทางเดินรถโดยสารประจำทาง) สมาชิกของความสัมพันธ์อาจมีบทบาท ซึ่งจะเป็นการอธิบายถึงบทบาทที่มีในความสัมพันธ์นั้น ความสัมพันธ์อาจมีแท็กเพิ่มเติมที่อธิบายถึงกลุ่มทั้งหมด (เช่น name=*
, wikidata=*
, destination=*
, ฯลฯ)
ณ เดือนกรกฎาคม พ.ศ. 2567 OpenStreetMap นั้นประกอบด้วยความสัมพันธ์มากกว่า 13 ล้านชุด
การใช้งาน
ความสัมพันธ์ใช้เพื่อจําลองความสัมพันธ์เชิงตรรกะ (มักเป็นแบบท้องที่) หรือทางภูมิศาสตร์ระหว่างวัตถุ
ความสัมพันธ์ไม่ได้ออกแบบมาเพื่อรวบรวมสิ่งของต่างๆ ที่เกี่ยวข้องกันอย่างหลวมๆ แต่กระจายกันเป็นวงกว้าง เช่นความสัมพันธ์กับการจัดกลุ่ม 'ถนนทุกเส้นในกรุงเทพมหานคร' นั้นจะไม่เหมาะสม ดูที่ความสัมพันธ์นั้นไม่ใช่หมวดหมู่
ความสัมพันธ์พื้นฐาน และพบได้ครั้งนั้นจะมีเพียงสมาชิกทางเรขาคณิตเท่านั้น (โหนดหรือทาง) ความสัมพันธ์อาจมีความสัมพันธ์(ลูก) อื่นๆ ซึ่งในกรณีนี้จะเรียกว่า "มหาความสัมพันธ์" อย่างไม่เป็นทางการ
The most common, simple relations contain only members of geometric types (nodes or ways). Relations may also contain other (child) relations, in which case they are informally called "super-relations". It is not usual for a relation to contain both geometric members and child relations, but it is not forbidden.
To be useful, a relation tree should eventually contain geometric members; otherwise, it would be basically invisible, because it is not attached to anything concrete on the map. An empty relation is permitted to exist in the database, but it is not very useful, except maybe as a placeholder for a future expansion. iD editor automatically deletes empty relations obtained by removing members, since they are in most cases inadvertent.
Size
There is a technical limit of 32,000 elements in a relation. It is recommended not to use more than about 300 members per relation: the more members are stuffed into a single relation, the harder it is to handle, the easier it breaks, the easier conflicts can show up and the more resources it consumes on the database and server. If you have to handle more than that amount, some recommend creating several relations and combining them in a super-relation (a good concept on paper but software support is poor).
However, having large relations is sometimes inevitable. For example, boundary relation for Russia, the largest country in the world, has over 5000 ways as outer members.
Roles 
A role is an optional textual field describing the function of a member in the relation.
For example, in a multipolygon relation,
and outer
are used to specify whether a way forms an outer or an inner part of that multipolygon.
inner
For a waterway relation of a river (a relation with all the waterway=river
of the river and optionally of its tributaries), main_stream on a way will indicate that this is the main part of the river while side_stream is for a branch which will come back in the main stream.
Examples of relation 
Multipolygon
Multipolygons are one of two methods to represent areas in OpenStreetMap. While most areas are represented as a single
closed way, almost all area features can also be mapped using multipolygon relations. This is needed when the area needs to exclude inner rings (holes), has multiple outer areas (exclaves), or uses more than ~2000 nodes.
In the multipolygon relation, the
and outer
roles are used to specify whether a member way forms an outer or an inner part of that area.
inner
For example, for a lake with an island, you will map this as a multipolygon with 2 ways, one way (with no tags) with the role "outer" for the outer border of the lake and one way with the role "inner" for the island (which could have some tags like natural=bare_rock
if the island is a rocky area).
Bus route
Each variation of a bus route itinerary is represented by a relation with type=route
, route=bus
and some recommended tags like name=*
, ref=*
, from=*
, to=*
and operator=*
.
The first members in the route relation are the nodes representing the stops with the role 'stop'. These are ordered in the way the vehicles travel along them. Then the ways are added and will form an ordered sequence along the stop nodes. The ways don't get roles.
Other examples
- Relation:boundary to define different kind of boundaries (administrative, protected areas, etc.)
- Relation:restriction to describe a restriction such as 'no left turn', 'no U-turn' etc.
- see Types of relation and Category:Relations for more
Tools
- iD: [1]
- JOSM/Advanced_editing#Relations: to work with relations in JOSM
- Potlatch 2/relations: to work with relations in Potlatch
- Relatify: simple edition of bus and tram routes (in Public Transport v2 (PTv2) standard)
- Show a relation: Example id=11
- Show history of a relation: Example id=11
- Rendering a relation: Example id=11
- Relation Analyzer (ra.osmsurround.org) - to analyse a relation (e.g. show gaps in route relations) or to look for a relation by name, type, operator...
- Mapki's Deep Diff - to analyse: e.g. show role changes individual members, show modifications of the memberlist via object history view for each object version
- Relation Diff - to compare relations
- Create a gpx file from a relation - for example to visualise the relation on a map
- Rel2gpx - to filter ways of a relation
- OSM Inspector (Geofabrik) - PTv2 route relations errors on ways - for checking gaps and member list disorder of PTv2 relations
- Public Transport Network Analysis - for checking gaps, order of ways, one-way rules and inconsistent data between route and master in Public Transport v2 relations (also basic support for PTv1 routes).
OSRM and Valhalla can use certain route relation roles to influence guidance instructions when a route represents both directions of travel.
For example, some bicycle routers prefer to route on roads with existing bicycle route (as indicator of cycling usability). An application may also follow a pilgrimage=*
route relation or, more generally, try to route along the minimum number of numbered road routes.
OSM XML
- บทความหลัก: OSM XML
<relation id="13092746" visible="true" version="7" changeset="118825758" timestamp="2022-03-23T15:05:48Z" user="" uid="">
<member type="node" ref="5690770815" role="stop"/>
<member type="node" ref="5751940550" role="stop"/>
...
<member type="node" ref="1764649495" role="stop"/>
<member type="way" ref="96562914" role=""/>
...
<member type="way" ref="928474550" role=""/>
<tag k="from" v="Encre"/>
<tag k="name" v="9-Montagnes de Guyane"/>
<tag k="network" v="Agglo'bus"/>
<tag k="not:network:wikidata" v="Q3537943"/>
<tag k="operator" v="CACL"/>
<tag k="ref" v="9"/>
<tag k="route" v="bus"/>
<tag k="source" v="https://www.cacl-guyane.fr/wp-content/uploads/2021/01/PLAN-RESEAU-URBAIN-AGGLO-BUS-1.pdf"/>
<tag k="to" v="Lycée Balata"/>
<tag k="type" v="route"/>
<tag k="website" v="https://www.cacl-guyane.fr/lagglo-au-quotidien/se-deplacer/transport-urbain-2/"/>
</relation>
ดูเพิ่ม
|