Пример #1
0
to the map. The chart is placed inside a popup.
"""
import json
import folium
from gpxplotter import create_folium_map, read_gpx_file, add_segment_to_map
import numpy as np
import vincent

line_options = {'weight': 8}

the_map = create_folium_map(tiles='kartverket_topo4')
for track in read_gpx_file('example3.gpx'):
    for i, segment in enumerate(track['segments']):
        add_segment_to_map(the_map,
                           segment,
                           color_by='hr-zone-float',
                           cmap='viridis',
                           line_options=line_options)

# Create a chart using vincent
idx = np.argmax(segment['elevation'])

data = {
    'x': segment['Distance / km'],
    'y': segment['elevation'],
}

WIDTH = 400
HEIGHT = 200

line = vincent.Line(data, iter_idx="x", width=WIDTH, height=HEIGHT)
line_options1 = {'weight': 13, 'color': '#006d2c'}
line_options2 = {
    'weight': 8,
}

the_map = create_folium_map(tiles='kartverket_topo4')

for track in read_gpx_file('example3.gpx'):
    for i, segment in enumerate(track['segments']):
        segment['velocity-level'] = cluster_velocities(
            segment['velocity'],
            n_clusters=9,
        )
        add_segment_to_map(the_map,
                           segment,
                           line_options=line_options1,
                           add_start_end=False)
        add_segment_to_map(the_map,
                           segment,
                           color_by='velocity-level',
                           cmap='RdYlGn_09',
                           line_options=line_options2,
                           add_start_end=False)
        # Find 1 km locations:
        maxd = max(segment['Distance / km'])
        locations = np.arange(1, maxd, 1)
        location_idx = []
        for j in locations:
            diff = abs(j - segment['Distance / km'])
            idx = np.argmin(diff)
            location_idx.append(idx)
Пример #3
0
Annotate a map with folium
==========================

This example will create a map and color the track according
to the elevation. It will then add two folium markers to show
the location of the highest elevation and the highest heart rate.
"""
from gpxplotter import read_gpx_file, create_folium_map, add_segment_to_map
import folium
import numpy as np

the_map = create_folium_map(tiles='kartverket_topo4')
for track in read_gpx_file('example1.gpx'):
    for i, segment in enumerate(track['segments']):
        # Add track to the map:
        add_segment_to_map(the_map, segment, color_by='elevation')

        # This is sufficient to add the segment to the map.
        # Here we will add some extra markers using folium:
        # 1) Add marker at highest elevation:
        idx = np.argmax(segment['elevation'])
        value = segment['elevation'][idx]
        time = segment['time'][idx].strftime('%A %B %d, %Y, %H:%M:%S')
        hrate = segment['heart rate'][idx]
        distance = segment['distance'][idx] / 1000.
        txt = (f'The highest elevation was <b>{value:g} m</b>:'
               '<ul>'
               f'<li> Time: {time}'
               f'<li> Distance: {distance:.2f} km'
               f'<li> Heart rate: {hrate:g} bpm'
               '</ul>')
Пример #4
0
"""
from branca.element import MacroElement
from jinja2 import Template
import folium
from gpxplotter import (
    create_folium_map,
    read_gpx_file,
    add_segment_to_map,
)
line_options = {'weight': 8}

the_map = create_folium_map(tiles='kartverket_topo4')

for track in read_gpx_file('example3.gpx'):
    for i, segment in enumerate(track['segments']):
        add_segment_to_map(the_map, segment, line_options=line_options)

steepness = folium.WmsTileLayer(
    url='https://gis3.nve.no/map/services/Bratthet/MapServer/WmsServer',
    layers='Bratthet_snoskred',
    fmt='image/png',
    opacity=0.7,
    transparent=True,
    name='Steepness',
)
steepness.add_to(the_map)


# Add some custom code to show a legend:
class Legend(MacroElement):
    """Just add a hard-coded legend template."""
Пример #5
0
Track colored by heart rate
===========================

This example will create a map and color the track according
to the measured heart rate.
"""
import folium
from gpxplotter import (
    read_gpx_file,
    create_folium_map,
    add_segment_to_map,
    add_all_tiles,
)

the_map = create_folium_map(tiles='kartverket_topo4')
# Add pre-defined tiles:
add_all_tiles(the_map)

for track in read_gpx_file('example1.gpx'):
    for i, segment in enumerate(track['segments']):
        add_segment_to_map(the_map, segment, color_by='hr')

# Add layer control to change tiles:
folium.LayerControl(sortLayers=True).add_to(the_map)

# To store the map as a HTML page:
# the_map.save('map_001.html')

# To display the map in a Jupyter notebook:
the_map
Пример #6
0
# Copyright (c) 2021, Anders Lervik.
# Distributed under the LGPLv2.1+ License. See LICENSE for more info.
"""
Track colored by velocity
==========================

This example will create a map and color the track according
to the velocity.

.. note:: The velocities are calculated from the distance
   so it is a bit noisy.
"""
from gpxplotter import read_gpx_file, create_folium_map, add_segment_to_map
line_options = {'weight': 8}

the_map = create_folium_map(tiles='openstreetmap')
for track in read_gpx_file('example2.gpx'):
    for i, segment in enumerate(track['segments']):
        add_segment_to_map(the_map, segment, color_by='velocity-level',
                           cmap='RdPu_09', line_options=line_options)

# To store the map as a HTML page:
# the_map.save('map_003.html')

# To display the map in a Jupyter notebook:
the_map
Пример #7
0
from the image.
"""
import datetime
from gpxplotter import create_folium_map, read_gpx_file, add_segment_to_map
import folium
import numpy as np
import PIL
from PIL.ExifTags import TAGS, GPSTAGS


line_options = {'weight': 8}

the_map = create_folium_map()
for track in read_gpx_file('example3.gpx'):
    for i, segment in enumerate(track['segments']):
        add_segment_to_map(the_map, segment, color_by='hr-zone-float',
                           cmap='viridis', line_options=line_options)

# Display initial map:
the_map


# Create a method to get coordinates from an image:
def get_lat_lon(imagefile):
    image = PIL.Image.open(imagefile)
    exif_info = {}
    for key, val in image._getexif().items():
        exif_info[TAGS.get(key, key)] = val
    gps_info = {}
    for key, val in exif_info['GPSInfo'].items():
        gps_info[GPSTAGS.get(key, key)] = val
    # Convert to decimal latitude/longitude: