.. _download_osm:
Download OSM data
###################################
Download OpenStreetMap data
*****************************************************
You can use the following two methods to download the OpenStreetMap
data:
1. `OpenStreetMapOfficial `_:
choose ``Export`` -> ``OverpassAPI``
(otherwise the size of the bounding box size is limited).
.. image:: ../_static/map_related/osm_official.png
:width: 100%
:align: center
:alt: OpenStreetMap Official
By this way, you will get the *complete* OSM data (xml),
then you can use ``osm_filter.osm_way_filter()`` to get
the layer you need.
2. `Overpass API `_ (recommended):
directly use overpass API to download the layer you need.
The sample query code is attached in the appendix :ref:`query_code`.
.. image:: ../_static/map_related/overpass.png
:width: 100%
:align: center
:alt: Overpass API
In this way, you will directly get the layer you need.
Parse OpenStreetMap data
*****************************************************
The downloaded OpenStreetMap xml file can be parsed using
the :func:`mtldp.mtlmap.build_network_from_xml`:
.. code-block:: python
:linenos:
import mtldp.mtlmap as mtlmap
network = mtlmap.build_network_from_xml("*.osm")
This will return you a well-structured class
:class:`mtldp.mtlmap.Network`.
.. _query_code:
Appendix A: Query code
************************************************
Here is an example of the query code using the OverpassAPI.
.. literalinclude:: ../_static/overpass.xml
:linenos:
.. _OpenStreetMapOfficial :