• 简单学习OSM(OpenStreetMap)文件格式的最基础结构


    目标

    获取一个最简单的OSM文件,并学习其最基础的结构。

    获取OSM数据的步骤

    操作很简单:
    进入官网:https://www.openstreetmap.org/
    点击左上角的 “导出” 按钮。
    在这里插入图片描述
    然后,填入坐标范围,点击按钮即可导出osm文件:
    在这里插入图片描述
    当然,直接填坐标范围是不直观的,为此,可以点击 “手动选择不同的区域”,这样即可手动选择范围了:
    在这里插入图片描述

    学习OSM文件格式的最基础结构

    Wiki上有关于OSM格式的简单介绍,可见附录。不过这里将通过例子来学习:

    例1:最简单的例子

    在这里插入图片描述
    导出后的osm文件内容如下:

    
    <osm version="0.6" generator="CGImap 0.8.8 (2798843 spike-07.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
     <bounds minlat="31.3618700" minlon="121.8012200" maxlat="31.3620700" maxlon="121.8015200"/>
     <node id="7603536329" visible="true" version="1" changeset="86368470" timestamp="2020-06-08T19:00:07Z" user="Reboot01" uid="9856191" lat="31.3618772" lon="121.8012886"/>
     <node id="7603536330" visible="true" version="1" changeset="86368470" timestamp="2020-06-08T19:00:07Z" user="Reboot01" uid="9856191" lat="31.3619399" lon="121.8014870"/>
     <node id="7603536331" visible="true" version="1" changeset="86368470" timestamp="2020-06-08T19:00:07Z" user="Reboot01" uid="9856191" lat="31.3620542" lon="121.8014375"/>
     <node id="7603536332" visible="true" version="1" changeset="86368470" timestamp="2020-06-08T19:00:07Z" user="Reboot01" uid="9856191" lat="31.3619915" lon="121.8012390"/>
     <way id="813970381" visible="true" version="1" changeset="86368470" timestamp="2020-06-08T19:00:07Z" user="Reboot01" uid="9856191">
      <nd ref="7603536329"/>
      <nd ref="7603536330"/>
      <nd ref="7603536331"/>
      <nd ref="7603536332"/>
      <nd ref="7603536329"/>
      <tag k="building" v="yes"/>
     way>
    osm>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    可以看到有以下信息:

    • 经度(longitude)和纬度(latitude)缩写为lonlat
    • bounds节点记录了这个文件的范围
    • 4个node节点代表了4个位置。
    • way节点引用了node节点(通过id),以这样的方式表示出了一个范围。以此可见way节点并不仅表示“路(way)”。
    • tag指出了这个way节点是一个建筑(building)

    例2:不同的way

    在这里插入图片描述
    这里就出现了多个way节点,并且根据tag可以区分出各自的种类:
    在这里插入图片描述
    比如这里不仅有建筑,还有操场,和跑道。

    例3:relation的一个例子

    在这里插入图片描述
    这是横沙岛的一个边界。可以在文件中找到一个relation节点,它指明了自己的边界包含了哪些way节点:
    在这里插入图片描述

    总结

    结合这些简单的例子,以及Wiki的介绍,我学到关于OSM文件的一些最基础的结构:

    1. 每个node节点代表空间中的一个位置,具有经纬度属性。
    2. way节点引用了node,以有序列表的方式定义了一个范围。
    3. relation节点(关系)引用了way节点(wiki指出还可能引用node或其他relation)作为成员(member),并且指出了每个成员在这个关系中所扮演的角色。
    4. 每个节点都可能包含tag属性,来附带上额外的信息。

    附录:Wiki上关于OSM格式的介绍

    Wiki地址:https://en.wikipedia.org/wiki/OpenStreetMap

    OpenStreetMap uses a topological data structure, with four core elements (also known as data primitives):

    • Nodes are points with a geographic position, stored as coordinates (pairs of a latitude and a longitude) according to WGS 84.[106] Outside of their usage in ways, they are used to represent map features without a size, such as points of interest or mountain peaks.
    • Ways are ordered lists of nodes, representing a polyline, or possibly a polygon if they form a closed loop. They are used both for representing linear features such as streets and rivers, and areas, like forests, parks, parking areas and lakes.
    • Relations are ordered lists of nodes, ways and relations (together called "members"), where each member can optionally have a "role" (a string). Relations are used for representing the relationship of existing nodes and ways. Examples include turn restrictions on roads, routes that span several existing ways (for instance, a long-distance motorway), and areas with holes.
    • Tags are key-value pairs (both arbitrary strings). They are used to store metadata about the map objects (such as their type, their name and their physical properties). Tags are not free-standing, but are always attached to an object: to a node, a way or a relation. A recommended ontology of map features (the meaning of tags) is maintained on a wiki. New tagging schemes can always be proposed by a popular vote of a written proposal in OpenStreetMap wiki, however, there is no requirement to follow this process. There are over 89 million different kinds of tags in use as of June 2017.[107]
  • 相关阅读:
    python - 闭包与装饰器
    docker系统笔记-03镜像的创建管理和发布
    App测试时常用的adb命令你都掌握了哪些呢?
    前端面试-浏览器相关
    【蓝桥杯选拔赛真题78】python电话号码 第十五届青少年组蓝桥杯python选拔赛真题 算法思维真题解析
    【开发者必看】【push kit】推送服务典型问题合集2
    聊聊并发编程的10个坑,千万小心!!!
    前端权限管理方案之精确到按钮级别
    聊聊 iOS 出海 App 中的多语言和 ASO 优化和雷区
    J2Cache
  • 原文地址:https://blog.csdn.net/u013412391/article/details/127876063