Skip to content

Instantly share code, notes, and snippets.

@andrashann
Created March 13, 2022 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrashann/7ee46cd169632a9fabe7b6197c0c830b to your computer and use it in GitHub Desktop.
Save andrashann/7ee46cd169632a9fabe7b6197c0c830b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 63,
"id": "55be6e11-59bf-4045-ae0c-65e74e9ace52",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import xmltodict\n",
"import json\n",
"import os\n",
"from time import sleep\n",
"import urllib.parse\n",
"import osm2geojson\n",
"import geopandas as gpd"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "791d803f-de28-48d1-9035-fd27dc40d700",
"metadata": {},
"outputs": [],
"source": [
"OKT_RELATION = '3020505'\n",
"DATA_DIR = 'data'\n",
"\n",
"if not os.path.exists(DATA_DIR):\n",
" os.makedirs(DATA_DIR)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "fa52e4d7-4c33-4586-93ca-a0acef8278cb",
"metadata": {},
"outputs": [],
"source": [
"# get current version"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "62c32408-0fbf-4756-a0b6-e8a2c0f00621",
"metadata": {},
"outputs": [],
"source": [
"r = requests.get(f'https://www.openstreetmap.org/api/0.6/relation/{OKT_RELATION}')"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "5e514ed9-cdec-4751-abd2-aa03cdae30b2",
"metadata": {},
"outputs": [],
"source": [
"latest_version = int(xmltodict.parse(r.text)['osm']['relation']['@version'])"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "68ec5433-a967-4691-a214-dde42a6d27b9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1108"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"latest_version"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "3c71357d-b8ee-421a-a902-d04ad470ae88",
"metadata": {},
"outputs": [],
"source": [
"modified_dates = []"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "e9b1fb39-54f3-445b-8b32-96662c9340c2",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................."
]
}
],
"source": [
"for version in range(1, latest_version + 1):\n",
" r = requests.get(f'https://www.openstreetmap.org/api/0.6/relation/{OKT_RELATION}/{version}')\n",
" modified_dates.append(xmltodict.parse(r.text)['osm']['relation']['@timestamp'][:10])\n",
" print('.', end = '')"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "177cab3e-1c33-4983-b43c-74eb09999af8",
"metadata": {},
"outputs": [],
"source": [
"unique_modified_dates = sorted(list(set(modified_dates)))"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "a4886a1a-0852-4d72-b855-14e467e1eb54",
"metadata": {},
"outputs": [],
"source": [
"with open(f'{DATA_DIR}/unique_modified_dates.json', 'w') as file: # Use file to refer to the file object\n",
" json.dump(unique_modified_dates, file)"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "dc980621-0496-4931-a1b1-9e989d6ba0f1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" % Total % Received % Xferd Average Speed Time Time Time Current\n",
" Dload Upload Total Spent Left Speed\n",
"100 1309k 0 1309k 0 0 62476 0 --:--:-- 0:00:21 --:--:-- 317k:06 --:--:-- 0\n",
" % Total % Received % Xferd Average Speed Time Time Time Current\n",
" Dload Upload Total Spent Left Speed\n",
"100 1313k 0 1313k 0 0 36283 0 --:--:-- 0:00:37 --:--:-- 277k\n",
" % Total % Received % Xferd Average Speed Time Time Time Current\n",
" Dload Upload Total Spent Left Speed\n",
"100 1314k 0 1314k 0 0 53816 0 --:--:-- 0:00:25 --:--:-- 352k\n"
]
}
],
"source": [
"overwrite_downloaded_files = True\n",
"\n",
"for date in unique_modified_dates[:3]:\n",
" if not os.path.exists(f'{DATA_DIR}/okt-{date}.xml') or overwrite_downloaded_files:\n",
" query = f'[date:\"{date}T23:59:59Z\"];relation(3020505);out meta geom;'\n",
" encoded_query = urllib.parse.quote_plus(query)\n",
" !curl 'http://overpass-api.de/api/interpreter?data={encoded_query}' > {DATA_DIR}/okt-{date}.xml\n",
" sleep(1)"
]
},
{
"cell_type": "code",
"execution_count": 196,
"id": "a53c068c-c6e1-44ca-8f65-f7a8e6b29bc6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2013-06-25- 2013-06-28- 2013-07-07- 2013-07-08✗ 2013-07-15- 2013-07-18- 2013-07-19✗ 2013-07-21- 2013-07-30- 2013-08-27- 2013-08-29- 2013-08-31- 2013-09-01✗ 2013-09-04- 2013-09-20- 2013-09-21- 2013-09-23- 2013-09-30- 2013-10-03- 2013-10-04✗ 2013-10-08- 2013-10-10- 2013-10-12- 2013-10-13- 2013-10-16- 2013-10-18- 2013-10-30- 2013-11-04- 2013-11-15- 2013-11-17- 2013-11-27- 2013-12-05- 2013-12-06- 2013-12-07- 2013-12-18- 2013-12-21- 2013-12-25- 2013-12-26- 2013-12-31- 2014-01-02- 2014-01-06- 2014-01-07- 2014-01-09- 2014-01-25- 2014-01-27- 2014-02-02- 2014-02-11- 2014-02-13- 2014-02-15- 2014-02-18- 2014-02-19- 2014-02-20- 2014-02-22- 2014-02-23- 2014-02-24- 2014-03-01- 2014-03-09- 2014-03-10- 2014-03-14- 2014-03-21- 2014-03-22- 2014-03-23- 2014-03-24- 2014-03-30- 2014-03-31✗ 2014-04-02- 2014-04-08- 2014-04-09- 2014-04-10- 2014-04-11- 2014-04-15- 2014-04-19- 2014-04-20- 2014-04-21- 2014-04-22- 2014-04-23- 2014-04-25- 2014-04-26- 2014-04-28- 2014-05-01- 2014-05-02- 2014-05-06- 2014-05-10- 2014-05-11- 2014-05-12✗ 2014-05-14- 2014-05-30- 2014-06-03- 2014-06-12- 2014-06-16- 2014-06-17- 2014-06-22- 2014-06-23- 2014-06-24- 2014-06-26- 2014-06-27- 2014-06-28- 2014-06-29- 2014-06-30- 2014-07-05- 2014-07-09- 2014-07-11- 2014-07-13- 2014-07-17- 2014-07-19- 2014-07-22- 2014-07-24- 2014-07-26- 2014-07-27- 2014-07-28- 2014-07-29- 2014-07-30- 2014-08-02- 2014-08-03- 2014-08-05- 2014-08-06- 2014-08-08- 2014-08-10- 2014-08-11- 2014-08-12- 2014-08-13- 2014-08-16- 2014-08-17- 2014-08-19- 2014-08-21- 2014-08-22- 2014-08-24- 2014-08-26- 2014-09-02- 2014-09-05- 2014-09-13- 2014-09-14- 2014-09-17- 2014-09-19- 2014-09-21- 2014-09-22- 2014-09-23- 2014-09-27- 2014-10-04- 2014-10-05- 2014-10-08- 2014-10-09✗ 2014-10-13- 2014-10-15- 2014-10-18- 2014-10-19- 2014-10-20- 2014-10-25- 2014-10-26- 2014-10-28- 2014-10-29✗ 2014-11-01- 2014-11-02- 2014-11-03- 2014-11-08- 2014-11-16- 2014-11-19- 2014-11-23- 2014-11-25- 2014-11-26- 2014-11-27- 2014-11-29- 2014-11-30- 2014-12-01- 2014-12-02- 2014-12-03- 2014-12-13- 2014-12-14- 2014-12-16- 2014-12-18- 2014-12-19- 2014-12-23- 2014-12-27- 2015-01-05- 2015-01-06- 2015-01-18- 2015-01-21- 2015-01-22- 2015-01-23- 2015-01-24- 2015-01-25- 2015-01-26- 2015-01-28- 2015-01-30- 2015-02-01- 2015-02-04- 2015-02-06- 2015-02-09- 2015-02-10- 2015-02-11- 2015-02-19- 2015-02-21- 2015-02-22- 2015-02-25- 2015-03-02- 2015-03-04- 2015-03-05- 2015-03-07- 2015-03-08- 2015-03-12- 2015-03-13- 2015-03-15- 2015-03-18- 2015-03-19- 2015-03-20- 2015-03-22- 2015-03-23- 2015-03-25- 2015-03-27- 2015-03-28- 2015-03-30- 2015-04-03- 2015-04-06- 2015-04-15- 2015-04-19- 2015-04-20- 2015-04-21- 2015-04-26- 2015-04-27- 2015-04-28- 2015-05-01- 2015-05-03- 2015-05-04- 2015-05-05- 2015-05-06- 2015-05-07- 2015-05-09- 2015-05-11- 2015-05-12- 2015-05-17- 2015-05-20- 2015-05-26- 2015-05-30- 2015-05-31- 2015-06-02- 2015-06-03✗ 2015-06-06- 2015-06-07- 2015-06-08- 2015-06-09- 2015-06-10✗ 2015-06-12- 2015-06-17- 2015-06-20- 2015-06-22- 2015-06-24- 2015-06-25"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Failed to convert relation to shape {'changeset': 32226155,\n",
" 'id': 3020505,\n",
" 'tags': {'jel': 'k',\n",
" 'name': 'Országos Kéktúra - egyben (Írott-kő - Budapest - Hollóháza)',\n",
" 'network': 'nwn',\n",
" 'osmc:symbol': 'blue:white:blue_bar',\n",
" 'ref': 'OKT',\n",
" 'route': 'hiking',\n",
" 'symbol': 'blue_bar',\n",
" 'symbol:hu': 'kék sáv',\n",
" 'type': 'route'},\n",
" 'timestamp': '2015-06-26T13:43:43Z',\n",
" 'type': 'relation',\n",
" 'uid': 2122406,\n",
" 'user': 'raf_1010',\n",
" 'version': 472}\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"- 2015-06-26e 2015-07-10"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/andras/env/lib/python3.8/site-packages/geopandas/geodataframe.py:610: FutureWarning: Assigning CRS to a GeoDataFrame without a geometry column is now deprecated and will not be supported in the future.\n",
" return GeoDataFrame(rows, columns=columns, crs=crs)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✓ 2015-07-11✓ 2015-07-12✓ 2015-07-14✗ 2015-07-18✓ 2015-07-19✓ 2015-07-26✓ 2015-08-03✓ 2015-08-04✓ 2015-08-05✓ 2015-08-10✓ 2015-08-16✓ 2015-08-21✓ 2015-08-24✓ 2015-08-25✓ 2015-09-07✓ 2015-09-08✓ 2015-09-10✓ 2015-09-12✓ 2015-09-13✓ 2015-09-22✓ 2015-09-23✓ 2015-09-25✓ 2015-09-26✓ 2015-10-03✓ 2015-10-04✓ 2015-10-05✓ 2015-10-06✗ 2015-10-07✓ 2015-10-08✓ 2015-10-10✓ 2015-10-13✓ 2015-10-18✓ 2015-10-23✓ 2015-10-27✓ 2015-11-03✓ 2015-11-08✓ 2015-11-10✓ 2015-11-12✓ 2015-11-13✓ 2015-11-15✓ 2015-11-16✓ 2015-11-18✓ 2015-11-21✓ 2015-11-22✓ 2015-11-24✓ 2015-11-27✓ 2015-11-28✓ 2015-11-29✓ 2015-12-06✓ 2015-12-07✓ 2015-12-08✓ 2015-12-22✓ 2015-12-26✓ 2015-12-27✓ 2015-12-28✓ 2015-12-29✓ 2015-12-30✓ 2016-01-03✓ 2016-01-07✓ 2016-01-08✓ 2016-01-09✓ 2016-01-12✓ 2016-01-13✓ 2016-01-23✓ 2016-01-31✓ 2016-02-05✓ 2016-02-09✓ 2016-02-13✓ 2016-02-19✓ 2016-02-21✓ 2016-02-25✓ 2016-02-26✓ 2016-03-05✓ 2016-03-14✓ 2016-03-16✓ 2016-03-19✓ 2016-03-20✓ 2016-03-22✗ 2016-03-24✓ 2016-03-28✓ 2016-03-29✓ 2016-04-18✓ 2016-04-19✓ 2016-04-20✓ 2016-04-22✓ 2016-04-23✓ 2016-04-24✓ 2016-04-27✓ 2016-04-30✓ 2016-05-02✓ 2016-05-04✓ 2016-05-08✓ 2016-05-12✓ 2016-05-14✓ 2016-05-15✓ 2016-05-18✓ 2016-05-19✓ 2016-05-20✓ 2016-05-21✓ 2016-05-22✓ 2016-05-23✓ 2016-05-25✓ 2016-05-31✓ 2016-06-01✓ 2016-06-04✓ 2016-06-06✓ 2016-06-15✓ 2016-06-18✓ 2016-06-25✓ 2016-07-03✓ 2016-07-04✓ 2016-07-10✓ 2016-07-17✓ 2016-07-26✓ 2016-08-03✓ 2016-08-21✓ 2016-08-24✓ 2016-08-27✓ 2016-08-31✓ 2016-09-01✓ 2016-09-07✓ 2016-09-10✓ 2016-09-13✓ 2016-09-14✓ 2016-09-17✓ 2016-09-19✓ 2016-09-21✓ 2016-09-28✓ 2016-09-30✓ 2016-10-01✓ 2016-10-10✓ 2016-10-13✓ 2016-10-14✓ 2016-10-15✓ 2016-10-16✓ 2016-10-18✓ 2016-10-23✓ 2016-10-31✓ 2016-11-01✓ 2016-11-04✓ 2016-11-13✓ 2016-11-30✓ 2016-12-03✓ 2016-12-10✓ 2016-12-17✓ 2016-12-20✓ 2017-02-12✓ 2017-02-19✓ 2017-02-23✓ 2017-02-24✓ 2017-02-26✓ 2017-03-04✓ 2017-03-12✓ 2017-03-17✓ 2017-03-19✓ 2017-03-20✓ 2017-03-22✓ 2017-03-23✓ 2017-03-24✓ 2017-03-25✓ 2017-03-26✓ 2017-03-27✓ 2017-03-30✓ 2017-04-06✓ 2017-04-07✓ 2017-04-09✓ 2017-04-15✓ 2017-04-17✓ 2017-04-19✓ 2017-04-23✓ 2017-04-26✓ 2017-04-30✓ 2017-05-01✓ 2017-05-02✓ 2017-05-04✓ 2017-05-05✓ 2017-05-07✓ 2017-05-11✓ 2017-05-12✓ 2017-05-15✓ 2017-05-18✓ 2017-05-19✓ 2017-05-22✓ 2017-05-25✓ 2017-06-01✓ 2017-06-05✓ 2017-06-06✓ 2017-06-09✓ 2017-06-10✓ 2017-06-11✓ 2017-06-13✓ 2017-06-14✓ 2017-06-18✓ 2017-06-19✓ 2017-06-22✓ 2017-06-25✓ 2017-06-29✓ 2017-07-01✓ 2017-07-05✓ 2017-07-07✓ 2017-07-08✓ 2017-07-10✓ 2017-07-17✓ 2017-07-25✓ 2017-07-26✓ 2017-08-02✓ 2017-08-09✓ 2017-08-13✓ 2017-08-17✓ 2017-08-20✓ 2017-08-28✓ 2017-08-29✗ 2017-08-30✓ 2017-08-31✓ 2017-09-06✓ 2017-09-10✓ 2017-09-17✓ 2017-09-21✓ 2017-10-06✓ 2017-10-15✓ 2017-10-18✓ 2017-10-20✓ 2017-10-21✓ 2017-10-28✓ 2017-11-01✓ 2017-11-02✓ 2017-11-04✓ 2017-11-15✓ 2017-11-18✓ 2017-11-19✓ 2017-11-26✓ 2017-12-09✓ 2017-12-13✓ 2017-12-18✓ 2017-12-19✓ 2017-12-23✓ 2017-12-24✓ 2018-01-09✓ 2018-01-10✓ 2018-01-28✓ 2018-02-01✓ 2018-02-21✓ 2018-03-10✓ 2018-04-02✓ 2018-04-13✓ 2018-04-16✓ 2018-04-29✓ 2018-04-30✓ 2018-05-13✓ 2018-05-14✓ 2018-05-15✓ 2018-05-22✓ 2018-05-31✓ 2018-06-07✓ 2018-06-10✓ 2018-06-15✓ 2018-06-18✓ 2018-06-20✓ 2018-06-21✗ 2018-06-26✓ 2018-06-30✓ 2018-07-05✓ 2018-07-10✓ 2018-07-14✓ 2018-07-26✓ 2018-07-27✓ 2018-07-30✓ 2018-07-31✓ 2018-08-01✓ 2018-08-02✓ 2018-08-03✓ 2018-08-06✓ 2018-08-10✓ 2018-08-12✓ 2018-08-20✓ 2018-08-21✓ 2018-08-31✓ 2018-09-02✓ 2018-09-03✓ 2018-09-06✗ 2018-09-07✓ 2018-09-08✓ 2018-09-15✓ 2018-09-17✓ 2018-09-26✓ 2018-10-12✓ 2018-10-14✓ 2018-10-17✓ 2018-10-21✓ 2018-11-04✓ 2018-11-14✓ 2018-12-03✓ 2018-12-06✓ 2018-12-15✓ 2018-12-28✓ 2018-12-29✓ 2019-01-04✓ 2019-01-05✓ 2019-01-14✓ 2019-01-27✓ 2019-02-08✓ 2019-02-11✓ 2019-02-18✓ 2019-02-23✓ 2019-02-25✓ 2019-03-03✓ 2019-03-21✓ 2019-03-23✓ 2019-03-24✓ 2019-03-30✓ 2019-03-31✓ 2019-04-21✓ 2019-05-04✓ 2019-05-05✓ 2019-05-24✓ 2019-05-27✗ 2019-05-28✓ 2019-05-30✓ 2019-06-02✓ 2019-06-18✓ 2019-06-19✓ 2019-07-14✓ 2019-07-15✓ 2019-07-16✗ 2019-07-19✓ 2019-07-23✓ 2019-08-05✓ 2019-08-08✓ 2019-08-15✓ 2019-08-16✓ 2019-08-17✓ 2019-08-20✓ 2019-08-21✗ 2019-09-06✓ 2019-09-11✓ 2019-09-21✓ 2019-09-22✓ 2019-09-26✓ 2019-09-30✓ 2019-10-08✓ 2019-10-25✓ 2019-10-26✗ 2019-11-02✓ 2019-11-19✓ 2019-11-21✓ 2019-11-25✓ 2019-11-30✓ 2019-12-30✓ 2020-01-01✓ 2020-01-05✓ 2020-01-24✓ 2020-02-01✓ 2020-02-04✓ 2020-02-10✓ 2020-02-16✓ 2020-02-20✓ 2020-02-23✓ 2020-03-04✓ 2020-03-14✓ 2020-03-15✓ 2020-03-19✓ 2020-03-20✓ 2020-03-23✓ 2020-03-25✓ 2020-03-29✓ 2020-04-02✓ 2020-04-08✓ 2020-04-13✓ 2020-05-09✓ 2020-05-10✓ 2020-05-16✓ 2020-06-09✓ 2020-06-13✓ 2020-06-14✓ 2020-06-21✓ 2020-07-02✓ 2020-07-06✓ 2020-07-07✓ 2020-07-09✓ 2020-07-13✓ 2020-07-17✓ 2020-07-18✓ 2020-07-25✓ 2020-08-04✓ 2020-08-10✓ 2020-08-13✓ 2020-08-15✓ 2020-08-17✓ 2020-08-21✓ 2020-08-23✓ 2020-08-30✓ 2020-09-01✓ 2020-09-04✓ 2020-09-14✓ 2020-09-17✓ 2020-09-21✓ 2020-09-23✓ 2020-09-25✓ 2020-10-02✓ 2020-10-06✓ 2020-10-07✓ 2020-10-09✓ 2020-10-24✓ 2020-10-26✓ 2020-10-27✗ 2020-10-29✓ 2020-11-01✓ 2020-11-03✓ 2020-11-04✓ 2020-11-08✓ 2020-11-20✓ 2020-11-23✓ 2020-11-29✓ 2020-12-01✓ 2020-12-06✓ 2020-12-13✓ 2020-12-31✓ 2021-01-03✓ 2021-01-07✓ 2021-01-08✓ 2021-01-10✓ 2021-01-11✓ 2021-01-22✓ 2021-01-24✓ 2021-02-07✓ 2021-02-08✓ 2021-02-09✓ 2021-02-15✓ 2021-02-26✓ 2021-03-03✗ 2021-03-10✓ 2021-03-16✓ 2021-03-23✓ 2021-04-02✓ 2021-04-03✓ 2021-04-04✓ 2021-04-16✓ 2021-04-19✓ 2021-04-22✓ 2021-04-25✓ 2021-05-01✓ 2021-05-05✓ 2021-05-07✓ 2021-05-11✓ 2021-05-24✓ 2021-06-07✓ 2021-06-10✓ 2021-06-13✓ 2021-06-17✓ 2021-06-24✓ 2021-07-02✓ 2021-07-13✓ 2021-07-14✓ 2021-07-15✓ 2021-07-25✓ 2021-07-28✓ 2021-08-01✓ 2021-08-09✓ 2021-08-10✓ 2021-08-12✓ 2021-08-18✓ 2021-08-22✓ 2021-09-02✓ 2021-09-24✓ 2021-09-25✗ 2021-09-27✓ 2021-10-04✓ 2021-10-13✓ 2021-10-18✓ 2021-10-19✓ 2021-10-23✓ 2021-10-25✓ 2021-10-29✓ 2021-10-30✓ 2021-11-14✓ 2021-11-15✓ 2021-11-17✓ 2021-11-19✓ 2021-11-21✓ 2021-11-28✓ 2021-11-30✓ 2021-12-09✓ 2021-12-13✓ 2021-12-20✓ 2021-12-30✓ 2022-01-30✓ 2022-02-17✓ 2022-02-19✓ 2022-02-24✗ 2022-03-05✓ "
]
}
],
"source": [
"overwrite_downloaded_files = False\n",
"overwrite_geojson_files = False\n",
"\n",
"previous_df = gpd.GeoDataFrame({'geometry':[Point(0,1)]}, geometry='geometry')\n",
"\n",
"for date in unique_modified_dates:\n",
" print(date, end='')\n",
" if not os.path.exists(f'{DATA_DIR}/okt-{date}.xml') or overwrite_downloaded_files:\n",
" query = f'[date:\"{date}T23:59:59Z\"];relation(3020505);out meta geom;'\n",
" xml_data = osm2geojson.overpass_call(query)\n",
" with open(f'{DATA_DIR}/okt-{date}.xml', 'w') as file:\n",
" file.write(xml_data)\n",
" else:\n",
" with open(f'{DATA_DIR}/okt-{date}.xml', 'r') as file:\n",
" xml_data = file.read()\n",
" \n",
" geojson_data = osm2geojson.xml2geojson(xml_data)\n",
" gdf = gpd.GeoDataFrame.from_features(geojson_data,crs=4326)\n",
"\n",
" geojson_file_name = f'{DATA_DIR}/okt-{date}.geojson'\n",
" try:\n",
" if gdf.geometry[0] == previous_df.geometry[0]: # only metadata change\n",
" print('✗', end=' ')\n",
" else:\n",
" previous_df = gdf.copy()\n",
"\n",
" if not os.path.exists(geojson_file_name) or overwrite_downloaded_files:\n",
" if os.path.exists(geojson_file_name):\n",
" os.remove(geojson_file_name)\n",
" gdf.to_file(geojson_file_name, driver='GeoJSON')\n",
" print('✓', end=' ')\n",
" else:\n",
" print('-', end=' ')\n",
" except AttributeError: \n",
" # could not convert data for some reason, this happens \n",
" # at https://www.openstreetmap.org/api/0.6/relation/3020505/472\n",
" # (2015-06-25)\n",
" print('e', end=' ')\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.8.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment