{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Ipyrest, OSM Examples\n", "\n", "These are some examples of using Ipyrest with the OpenStreetMap API." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import geojson\n", "\n", "from ipyrest import Api" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Empty Interface" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Api()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Simple Examples\n", "\n", "https://wiki.openstreetmap.org/wiki/API_v0.6" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Api('https://api.openstreetmap.org/api/capabilities')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Api('https://api.openstreetmap.org/api/0.6/permissions')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Api('https://api.openstreetmap.org/api/0.6/changesets')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Map Notes\n", "\n", "https://wiki.openstreetmap.org/wiki/API_v0.6#Map_Notes_API\n", "\n", "Ideally, the markers would have the respective notes' text showing in a pop-up, too..." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def post(resp):\n", " \"Modify response content-type in order to get a GeoJSON view.\"\n", " resp.headers['Content-Type'] = 'application/vnd.geo+json'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = 'https://api.openstreetmap.org/api/0.6/notes.json?bbox=-0.65094,51.312159,0.374908,51.669148'\n", "api = Api(url, post_process_resp=post, click_send=True)\n", "api" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# list comments\n", "gj = geojson.loads(api.resp.content)\n", "for feat in gj.features:\n", " if feat.geometry.type != 'Point':\n", " continue\n", " lon, lat = feat.geometry.coordinates\n", " print(lat, lon)\n", " # fields inside 'properties' is not standard GeoJSON...\n", " for comment in feat.properties['comments']:\n", " print(comment['text'].strip())\n", " print()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.3" }, "toc": { "nav_menu": {}, "number_sections": false, "sideBar": true, "skip_h1_title": true, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": true } }, "nbformat": 4, "nbformat_minor": 2 }