Skip to content

Commit

Permalink
Merge pull request #691 from sackh/kml_gpx
Browse files Browse the repository at this point in the history
Added example notebooks for KML and GPX file formats
  • Loading branch information
martinRenou authored Sep 11, 2020
2 parents f426414 + 0316327 commit 4a1e321
Show file tree
Hide file tree
Showing 4 changed files with 753 additions and 0 deletions.
77 changes: 77 additions & 0 deletions examples/GPX.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You will need to install the below packages:\n",
"- `ipyleaflet`\n",
"- `geopandas`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from ipyleaflet import Map, GeoData\n",
"import geopandas as gpd\n",
"import fiona"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Visualize GPX data\n",
"\n",
"m = Map(center=[46.57608333, 8.89241667], zoom=17)\n",
"\n",
"path = \"data/example.gpx\"\n",
"layers = fiona.listlayers(path)\n",
"for layer in layers:\n",
" gdf = gpd.read_file(path, driver=\"GPX\", layer=layer)\n",
" if gdf.empty:\n",
" continue\n",
" geo_data = GeoData(\n",
" geo_dataframe=gdf,\n",
" style={\n",
" \"color\": \"black\",\n",
" \"fillColor\": \"#3366cc\",\n",
" \"opacity\": 0.05,\n",
" \"weight\": 1.9,\n",
" \"fillOpacity\": 0.6,\n",
" },\n",
" hover_style={\"fillColor\": \"red\", \"fillOpacity\": 0.2},\n",
" )\n",
" m.add_layer(geo_data)\n",
"\n",
"m"
]
}
],
"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.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
73 changes: 73 additions & 0 deletions examples/KML.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You will need to install the below packages:\n",
"- `ipyleaflet`\n",
"- `geopandas`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from ipyleaflet import Map, GeoData\n",
"import geopandas as gpd"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Visualize KML data \n",
"\n",
"m = Map(center=[41.8781, -87.6298], zoom=4)\n",
"\n",
"gpd.io.file.fiona.drvsupport.supported_drivers[\"KML\"] = \"rw\"\n",
"us_states = gpd.read_file(\"data/us-states.kml\", driver=\"KML\")\n",
"\n",
"geo_data = GeoData(\n",
" geo_dataframe=us_states,\n",
" style={\n",
" \"color\": \"black\",\n",
" \"fillColor\": \"#3366cc\",\n",
" \"opacity\": 0.05,\n",
" \"weight\": 1.9,\n",
" \"fillOpacity\": 0.6,\n",
" },\n",
" hover_style={\"fillColor\": \"red\", \"fillOpacity\": 0.2},\n",
" name=\"us-states\",\n",
")\n",
"m.add_layer(geo_data)\n",
"m"
]
}
],
"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.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
17 changes: 17 additions & 0 deletions examples/data/example.gpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.0">
<name>Example gpx</name>
<wpt lat="46.57638889" lon="8.89263889">
<ele>2372</ele>
<name>LAGORETICO</name>
</wpt>
<trk><name>Example gpx</name><number>1</number><trkseg>
<trkpt lat="46.57608333" lon="8.89241667"><ele>2376</ele><time>2007-10-14T10:09:57Z</time></trkpt>
<trkpt lat="46.57619444" lon="8.89252778"><ele>2375</ele><time>2007-10-14T10:10:52Z</time></trkpt>
<trkpt lat="46.57641667" lon="8.89266667"><ele>2372</ele><time>2007-10-14T10:12:39Z</time></trkpt>
<trkpt lat="46.57650000" lon="8.89280556"><ele>2373</ele><time>2007-10-14T10:13:12Z</time></trkpt>
<trkpt lat="46.57638889" lon="8.89302778"><ele>2374</ele><time>2007-10-14T10:13:20Z</time></trkpt>
<trkpt lat="46.57652778" lon="8.89322222"><ele>2375</ele><time>2007-10-14T10:13:48Z</time></trkpt>
<trkpt lat="46.57661111" lon="8.89344444"><ele>2376</ele><time>2007-10-14T10:14:08Z</time></trkpt>
</trkseg></trk>
</gpx>
Loading

0 comments on commit 4a1e321

Please sign in to comment.