Wolfram Computation Meets Knowledge

OSMImport

Contributed by: Christopher Wolfram

Imports OSM (OpenStreetMap) data from XML files or the OSM API

ResourceFunction["OSMImport"][path]

imports the OSM XML file at path

ResourceFunction["OSMImport"][GeoBoundsRegion[]]

imports OSM data within the specified region

ResourceFunction["OSMImport"][entity]

imports OSM data within the bounding box of entity

Details and Options

OSMImport outputs an association containing data on Nodes and Ways. Nodes represent places, buildings, streetlamps, etc, while Ways represent roads, bike paths, sidewalks, etc.
Every node and way has a unique ID.
Nodes and ways contain a Tags field which contains information about the type of node or way.
The Nodes field of each way contains the IDs for the sequence of nodes that make up that way.
When not importing from a path, OSMImport will use the OSM API.
The OSM API will not allow requests containing more than 50000 nodes, or spanning more than 0.5 degrees latitude and longitude.
For larger regions, OSM XML should be downloaded separately and then imported from a file.
OSMImport[entity] uses GeoBounds to find the bounding box of entity.
OSMImport returns all ways that intersect the specified bounding box.

Examples

Basic Examples

Import OSM data from a region:

In[1]:=
osm = ResourceFunction["OSMImport"][
   GeoBoundsRegion[{{40.0923, 40.0991}, {-88.2586, -88.2479}}]];

Visualize the ways:

In[2]:=
GeoGraphics[
 Values[Line[Values[osm[["Nodes", #Nodes, "Position"]]]] & /@ osm["Ways"]]]
Out[2]=

Scope

Use the Tags field to select only rivers:

In[3]:=
osm = ResourceFunction["OSMImport"][
   GeoBoundsRegion[{{40.0111, 40.0526}, {-88.0891, -88.0180}}]];
In[4]:=
Select[osm[
   "Ways"], #[["Tags", "waterway"]] === "river" &][[All, "Nodes"]]
In[5]:=
GeoGraphics[
 Values[Line[Values[osm[["Nodes", #Nodes, "Position"]]]] & /@ Select[osm["Ways"], #[["Tags", "waterway"]] === "river" &]]]
Out[5]=

Select only power lines:

In[6]:=
GeoGraphics[
 Values[Line[Values[osm[["Nodes", #Nodes, "Position"]]]] & /@ Select[osm["Ways"], #[["Tags", "power"]] === "line" &]]]
Out[6]=

Select only railway:

In[7]:=
GeoGraphics[
 Values[Line[Values[osm[["Nodes", #Nodes, "Position"]]]] & /@ Select[osm["Ways"], KeyExistsQ[#Tags, "railway"] &]]]
Out[7]=

Resource History