-
Notifications
You must be signed in to change notification settings - Fork 37
OSM Data from the Overpass API
OpenMapKit can read any valid OSM XML. The two primary APIs that you can get this data from are the main OpenStreetMap 0.6 API and the Overpass API. While both sources give us the same format of OSM data, the Overpass API is more useful for our purposes, because it has it's own query language, the Overpass QL, that allows us to get specific subsets of data for a given area.
You may want to have a data set that only contains roads or only contains buildings in a given area. The depth of specific queries you can ask the API is amazing. To learn how to write your own queries, the Overpass API Language Guide is a good resource to digest. We have included in this wiki several examples appropriate to use to get data for an OpenMapKit survey.
Overpass Turbo provides a great UI for executing queries, seeing their result, as well as saving and downloading that data.
The following query gets all of the roads within the bounding box of the map in turbo as well as the node with the name "Spatial Development International".
(
// get all roads
way[highway]({{bbox}});
// get SpatialDev
node["name"="Spatial Development International"];
);
out meta;
>;
out meta qt;
A link to turbo with this query and the map in the right place can be found here.
If you look at other example queries that Overpass provides, some of the queries have [out:json];
in it. You DO NOT want this. This gives you a response in JSON, not XML, and this format is not supported by any known applications, so we see no reason to support this in OpenMapKit. Also, the final output statement is out skel qt;
. We always want to have out meta qt;
. skel
is an incomplete output that does not include tags. meta
is the verbose output that has everything we need.
We need to make sure our queries include all of the nodes for a way, because without this we can not draw a geometry. This is where the >
operator comes in. This does the forward membership resolution of a given output. This final segment:
out meta;
>;
out meta qt;
is saying that with whatever output we have seen so far, get all of the referred members as well. You can do the opposite with the <
operator which does backwards resolution of membership. If you had a way, <
can get you all of the relations that the way is in.
The important takeaway is that you need >
to get all of the nodes you need for a given way.
(
// get all buildings
way[building]({{bbox}});
);
out meta;
>;
out meta qt;
(
// get all buildings
way[building]({{bbox}});
// get all roads
way[highway]({{bbox}});
);
out meta;
>;
out meta qt;
(
// not a road or building
way["highway"!~"."]["building"!~"."]({{bbox}});
);
out meta;
>;
out meta qt;
(
// get all hospital ways
way[amenity=hospital]({{bbox}});
// get all hospital nodes
node[amenity=hospital]({{bbox}});
);
out meta;
>;
out meta qt;
Typically speaking, administrative boundaries are relations composed of many ways. If you want the complete border of a city, you should get the relation and all of the ways and nodes that make up that relation. you can do the following as such:
(
relation[place=city]({{bbox}})
);
out meta;
>;
out meta qt;
This will get you all of the cities in Oregon:
(
relation[place=city]["is_in:state_code"="OR"]
);
out meta;
>;
out meta qt;
Similarly, you can get counties:
(
relation[border_type=county]({{bbox}})
);
out meta;
>;
out meta qt;
You can export OSM XML by clicking on the Export Button in Overpass Turbo and selecting:
You can save your queries by clicking the Save Button, but this only stores them in your browser's local storage. We recommend either saving the query yourself somewhere or selecting the Share Button and keeping the permalink generated. This permalink will provide a reference to the query you made.
Re-name your export OSM XML with a descriptive name and add a .osm extension to your file. Now transfer it into your device and put your file inside the osm folder of your openmapkit folder. Your OSM XML Layer should now appear as one of the choices in your menu.
tip: you might now be able to see your vectors unless you are zoomed in far enough.