Mapping Pirenaica with Folium

So back in September I cycled through the Pyrenees and decided to map it with Folium. Latitude and longitude info was retrieved from Strava gpx files and cleaned up using sed, grep and awk. Result is a file as below.

user@computer:$ head Pirenaica_stage_1.csv
lat,lon
43.3057130,-1.9778780
43.3057130,-1.9778770
43.3057140,-1.9778770
43.3057230,-1.9778880
43.3060960,-1.9783310
43.3064990,-1.9788360
43.3065760,-1.9789890
43.3067630,-1.9791790
43.3069250,-1.9791730

Below code will create the html with the complete Pirenaica course.

import random
import folium
from pyspark.sql import SparkSession
from pyspark.sql.functions import col
spark = SparkSession.builder.master("local").getOrCreate()

# Change Spark loglevel
spark.sparkContext.setLogLevel('FATAL')

# Load the rides and ride_routes data from local instead of HDFS
position1 = spark.read.load("/tmp/Pirenaica_stage_1.csv", format="csv", sep=",", inferSchema="true", header="true")
position2 = spark.read.load("/tmp/Pirenaica_stage_2.csv", format="csv", sep=",", inferSchema="true", header="true")
position3 = spark.read.load("/tmp/Pirenaica_stage_3.csv", format="csv", sep=",", inferSchema="true", header="true")
position4 = spark.read.load("/tmp/Pirenaica_stage_4.csv", format="csv", sep=",", inferSchema="true", header="true")
position5 = spark.read.load("/tmp/Pirenaica_stage_5.csv", format="csv", sep=",", inferSchema="true", header="true")
position6 = spark.read.load("/tmp/Pirenaica_stage_6.csv", format="csv", sep=",", inferSchema="true", header="true")
position7 = spark.read.load("/tmp/Pirenaica_stage_7.csv", format="csv", sep=",", inferSchema="true", header="true")
position8 = spark.read.load("/tmp/Pirenaica_stage_8.csv", format="csv", sep=",", inferSchema="true", header="true")
position9 = spark.read.load("/tmp/Pirenaica_stage_9.csv", format="csv", sep=",", inferSchema="true", header="true")

position = [position1, position2, position3, position4, position5, position6, position7, position8, position9]

#m = folium.Map()
INIT_COORDINATES = (46.00, -0.50)
m = folium.Map(location=INIT_COORDINATES, tiles='openstreetmap', zoom_start=1)

col=0
colArray=['red','blue','green','yellow', 'brown', 'purple', 'salmon', 'olive', 'orange']

# Check file was correctly loaded
for x in position:
#   x.printSchema()
#   x.show(2)

# Map position
   coordinates = [[float(i.lat), float(i.lon)] for i in x.collect()]

# Make a Folium map
#m = folium.Map()
   m.fit_bounds(coordinates, padding=(25, 25))
   folium.PolyLine(locations=coordinates, weight=5, color=colArray[random.randrange(8)]).add_to(m)
   folium.Marker(coordinates[1], icon=folium.Icon(color='blue'), popup="Origin").add_to(m)
   folium.Marker(coordinates[-1], popup="Destination", icon=folium.Icon(color='red')).add_to(m)
   col = col + 1

# Adding cols we crossed
folium.Marker([43.366944, -1.820556], icon=folium.Icon(color='green'), popup='Col du Jaizkibel, alt: 455m').add_to(m)
folium.Marker([43.175556, -1.402222], icon=folium.Icon(color='green'), popup='Col du Izpegi, alt: 672m').add_to(m)
folium.Marker([43.0381288, -1.0287726], icon=folium.Icon(color='green'), popup='Col de Bagargi, alt: 1327m').add_to(m)
folium.Marker([42.9966, -0.9871], icon=folium.Icon(color='green'), popup='Col d\'Erroymendi, alt: 1362m').add_to(m)
folium.Marker([42.973889, -0.993889], icon=folium.Icon(color='green'), popup='Col de Larrau, alt: 1578m').add_to(m)
folium.Marker([42.9212905, -0.989741], icon=folium.Icon(color='green'), popup='Alto de Laza, alt: 1106m').add_to(m)
folium.Marker([42.970278, -0.765833], icon=folium.Icon(color='green'), popup='Col de La Pierre de St Martin, alt: 1766m').add_to(m)
folium.Marker([42.976667, -0.339722], icon=folium.Icon(color='green'), popup='Col d\'Aubisque, alt: 1709m').add_to(m)
folium.Marker([42.908194, 0.145111], icon=folium.Icon(color='green'), popup='Col du Tourmalet, alt: 2115m').add_to(m)
folium.Marker([42.942306, 0.327389], icon=folium.Icon(color='green'), popup='Col d\'Aspin, alt: 1489m').add_to(m)
folium.Marker([42.802222, 0.462778], icon=folium.Icon(color='green'), popup='Col de Peyresourde, alt: 1596m').add_to(m)
folium.Marker([42.79, 0.445], icon=folium.Icon(color='green'), popup='Station de Peyragudes, alt: 1592m').add_to(m)
folium.Marker([42.769167, 0.66], icon=folium.Icon(color='green'), popup='Col du Portillon, alt: 1293m').add_to(m)
folium.Marker([42.663889, 0.981944], icon=folium.Icon(color='green'), popup='Port de la Bonaigua, alt: 2072m').add_to(m)
folium.Marker([42.371444, 1.238953], icon=folium.Icon(color='green'), popup='Port del Canto, alt: 1730m').add_to(m)
folium.Marker([42.3324755, 1.9450939], icon=folium.Icon(color='green'), popup='La Molina, alt: 1780m').add_to(m)
folium.Marker([42.2111825,2.3321633], icon=folium.Icon(color='green'), popup='Coll de Santigosa, alt: 1064m').add_to(m)

# Save to an html file
m.save('pirenaica.html')

# Cleanup
spark.stop()

And output is an html file we will call pirenaica.html which we can see below.

Leave a Reply

Your email address will not be published. Required fields are marked *

AlphaOmega Captcha Mathematica  –  Do the Math
     
 

*