示例#1
0
def test_polyline_popups():
    m = Map([43,-100], zoom_start=4)
    features.PolyLine([[40,-80],[45,-80]], popup="PolyLine").add_to(m)
    features.PolyLine([[40,-90],[45,-90]], popup=Popup("PolyLine")).add_to(m)
    features.MultiPolyLine([[[40,-110],[45,-110]]], popup="MultiPolyLine").add_to(m)
    features.MultiPolyLine([[[40,-120],[45,-120]]], popup=Popup("MultiPolyLine")).add_to(m)
    m._repr_html_()

    bounds = m.get_bounds()
    assert bounds == [[40, -120], [45, -80]], bounds
示例#2
0
def test_marker_popups():
    m = Map()
    features.Marker([45,-180],popup='-180').add_to(m)
    features.Marker([45,-120],popup=Popup('-120')).add_to(m)
    features.RegularPolygonMarker([45,-60],popup='-60').add_to(m)
    features.RegularPolygonMarker([45,0],popup=Popup('0')).add_to(m)
    features.CircleMarker([45,60],popup='60').add_to(m)
    features.CircleMarker([45,120],popup=Popup('120')).add_to(m)
    m._repr_html_()

    bounds = m.get_bounds()
    assert bounds == [[45, -180], [45, 120]], bounds
示例#3
0
def test_marker_popups():
    m = Map()
    features.Marker([45, -180], popup='-180').add_to(m)
    features.Marker([45, -120], popup=Popup('-120')).add_to(m)
    features.RegularPolygonMarker([45, -60], popup='-60').add_to(m)
    features.RegularPolygonMarker([45, 0], popup=Popup('0')).add_to(m)
    features.CircleMarker([45, 60], popup='60').add_to(m)
    features.CircleMarker([45, 120], popup=Popup('120')).add_to(m)
    m._repr_html_()

    bounds = m.get_bounds()
    assert bounds == [[45, -180], [45, 120]], bounds
示例#4
0
def test_polyline_popups():
    m = Map([43, -100], zoom_start=4)
    features.PolyLine([[40, -80], [45, -80]], popup="PolyLine").add_to(m)
    features.PolyLine([[40, -90], [45, -90]],
                      popup=Popup("PolyLine")).add_to(m)
    features.PolyLine([[[40, -110], [45, -110]]],
                      popup="MultiPolyLine").add_to(m)
    features.PolyLine([[[40, -120], [45, -120]]],
                      popup=Popup("MultiPolyLine")).add_to(m)
    m._repr_html_()

    bounds = m.get_bounds()
    assert bounds == [[40, -120], [45, -80]], bounds
示例#5
0
def test_wms_service():
    m = Map([40, -100], zoom_start=4)
    url = 'http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi'
    w = features.WmsTileLayer(url,
                              name='test',
                              format='image/png',
                              layers='nexrad-n0r-900913',
                              attr=u"Weather data © 2012 IEM Nexrad",
                              transparent=True)
    w.add_to(m)
    m._repr_html_()

    bounds = m.get_bounds()
    assert bounds == [[None, None], [None, None]], bounds
示例#6
0
def test_wms_service():
    m = Map([40, -100], zoom_start=4)
    url = 'http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi'
    w = features.WmsTileLayer(url,
                              name='test',
                              format='image/png',
                              layers='nexrad-n0r-900913',
                              attr=u"Weather data © 2012 IEM Nexrad",
                              transparent=True)
    w.add_to(m)
    m._repr_html_()

    bounds = m.get_bounds()
    assert bounds == [[None, None], [None, None]], bounds
示例#7
0
def main(args):
    if not args.output[-5:] == '.html':
        exit('ERROR Output file must be .html')

    heatmap_data = []

    for gpx_file in get_gpx_files(args):
        if not args.quiet:
            print('Reading {}'.format(gpx_file))

        with open(gpx_file, 'r') as file:
            last_point = None
            for line in file:
                if '<trkpt' in line:
                    r = re.findall('[-]?[0-9]*[.]?[0-9]+', line)

                    point = [float(r[0]), float(r[1])]
                    if last_point is not None and distance(point, last_point) < args.skip_distance:
                        continue
                    heatmap_data.append(point)
                    last_point = point

    if not args.quiet:
        print('Loaded {} trackpoints'.format(len(heatmap_data)))

    fmap = Map(tiles = 'CartoDB positron' if args.light_map else 'CartoDB dark_matter',
               location=args.center,
               zoom_start=11,
               prefer_canvas = True,
               max_zoom = HEATMAP_MAXZOOM)

    HeatMap(heatmap_data,
            radius = args.radius,
            blur = args.blur,
            gradient = HEATMAP_GRAD['light' if args.light_map else 'dark'],
            min_opacity = args.min_opacity,
            max_val = args.max_val).add_to(fmap)

    if args.center is None:
        fmap.fit_bounds(fmap.get_bounds())

    fmap.save(args.output)

    if not args.quiet:
        print('Saved {}'.format(args.output))

    if not args.quiet:
        webbrowser.open(args.output, new = 2, autoraise = True)
示例#8
0
def main(args):
    if not args.output[-5:] == '.html':
        exit('ERROR Output file must be .html')

    heatmap_data = []

    for gpx_file in get_gpx_files(args):
        if not args.quiet:
            print('Reading {}'.format(gpx_file))

        with open(gpx_file, 'r') as file:
            for line in file:
                if '<trkpt' in line:
                    r = re.findall('[-]?[0-9]*[.]?[0-9]+', line)

                    heatmap_data.append([float(r[0]), float(r[1])])

    if not args.quiet:
        print('Loaded {} trackpoints'.format(len(heatmap_data)))

    if args.skip_ratio > 1:
        heatmap_data = heatmap_data[::args.skip_ratio]

        print('Reduced to {} trackpoints'.format(len(heatmap_data)))

    fmap = Map(tiles = 'CartoDB positron' if args.light_map else 'CartoDB dark_matter',
               prefer_canvas = True,
               max_zoom = HEATMAP_MAXZOOM)

    HeatMap(heatmap_data,
            radius = args.radius,
            blur = args.blur,
            gradient = HEATMAP_GRAD['light' if args.light_map else 'dark'],
            min_opacity = args.min_opacity,
            max_val = args.max_val).add_to(fmap)

    fmap.fit_bounds(fmap.get_bounds())

    fmap.save(args.output)

    if not args.quiet:
        print('Saved {}'.format(args.output))

    webbrowser.open(args.output, new = 2, autoraise = True)
示例#9
0
def build_map(trackpoint, trips):
    ''' Build and display Folium map '''
    html_file = args.output
    # color map for heatmap plugin
    heatmap_grad = \
        {0.0: '#000004',
         0.1: '#160b39',
         0.2: '#420a68',
         0.3: '#6a176e',
         0.4: '#932667',
         0.5: '#bc3754',
         0.6: '#dd513a',
         0.7: '#f37819',
         0.8: '#fca50a',
         0.9: '#f6d746',
         1.0: '#fcffa4'}

    fmap = Map(tiles='CartoDB dark_matter', prefer_canvas=True, max_zoom=16)

    # Individual coordonate as heatmap
    HeatMap(
        trackpoint,
        radius=5,
        blur=5,
        gradient=heatmap_grad,
        max_zoom=19).add_to(fmap)

    # Trace the trip as polyline
    for trip in trips:
        PolyLine(
            locations=trip,
            weight=5,
            color='#FFC300',
            opacity=0.6).add_to(fmap)

    # Set map bounds
    fmap.fit_bounds(fmap.get_bounds())

    # save map to HTML file and open with browser
    print('writing ' + html_file + '...')
    fmap.save(html_file)
    webbrowser.open(html_file, new=2, autoraise=True)
    print('done')
示例#10
0
def map_points_circles(df, feature, date):

    print(feature.title(), 'at time:', date)

    # Create a map
    this_map = Map(prefer_canvas=True)

    # Check for the inputs to be on the dataframe
    # Getting data
    data = df[df['datetime'] == date]

    # Create a color map
    color_var = str(feature)  #what variable will determine the color
    cmap = LinearColormap(['blue', 'red'],
                          vmin=data[color_var].quantile(0.05),
                          vmax=data[color_var].quantile(0.95),
                          caption=color_var)

    # Add the color map legend to your map
    this_map.add_child(cmap)

    def plotDot(point):
        '''Takes a series that contains a list of floats named latitude and longitude and
         this function creates a CircleMarker and adds it to your this_map'''

        CircleMarker(location=[point.latitude, point.longitude],
                     fill_color=cmap(point[color_var]),
                     fill=True,
                     fill_opacity=0.4,
                     radius=40,
                     weight=0).add_to(this_map)

        # Iterate over rows

    data.apply(plotDot, axis=1)

    # Set the boundaries
    this_map.fit_bounds(this_map.get_bounds())

    # Show plot
    return this_map
def main(args):
    if not args.output[-5:] == '.html':
        exit('ERROR Output file must be .html')

    gpx_files = glob.glob('{}/{}'.format(args.dir, args.filter))

    if not gpx_files:
        exit('ERROR No GPX files in {}'.format(args.dir))

    heatmap_data = []

    for gpx_file in gpx_files:
        print('Reading {}'.format(gpx_file))

        with open(gpx_file, 'r') as file:
            for line in file:
                if '<trkpt' in line:
                    r = re.findall('[-]?[0-9]*[.]?[0-9]+', line)

                    heatmap_data.append([float(r[0]), float(r[1])])

    print('Loaded {} trackpoints'.format(len(heatmap_data)))

    fmap = Map(tiles='CartoDB dark_matter',
               prefer_canvas=True,
               max_zoom=HEATMAP_MAXZOOM)

    HeatMap(heatmap_data,
            radius=args.radius,
            blur=args.blur,
            gradient=HEATMAP_GRAD,
            min_opacity=args.min_opacity).add_to(fmap)

    fmap.fit_bounds(fmap.get_bounds())

    fmap.save(args.output)

    print('Saved {}'.format(args.output))

    webbrowser.open(args.output, new=2, autoraise=True)
def main(args):
    # arguments
    gpx_dir = args.dir
    gpx_filter = args.filter
    html_file = args.output
    heatmap_radius = args.radius
    heatmap_blur = args.blur

    if not html_file[-5:] == '.html':
        print('ERROR output file must be .html')
        quit()

    # parse GPX files
    gpx_files = glob.glob(gpx_dir + '/' + gpx_filter)

    if not gpx_files:
        print('ERROR no GPX files in ' + gpx_dir)
        quit()

    heatmap_data = []

    for gpx_file in gpx_files:
        print('reading ' + gpx_file + '...')

        with open(gpx_file, 'r') as file:
            for line in file:
                if '<trkpt' in line:
                    tmp = re.findall('[-]?[0-9]*[.]?[0-9]+', line)

                    heatmap_data.append([float(tmp[0]), float(tmp[1])])

    print('read ' + str(len(heatmap_data)) + ' trackpoints')

    # color map
    heatmap_grad = \
    {0.0: '#000004',
     0.1: '#160b39',
     0.2: '#420a68',
     0.3: '#6a176e',
     0.4: '#932667',
     0.5: '#bc3754',
     0.6: '#dd513a',
     0.7: '#f37819',
     0.8: '#fca50a',
     0.9: '#f6d746',
     1.0: '#fcffa4'}

    # create Folium map
    fmap = Map(tiles='CartoDB positron',
               prefer_canvas=True,
               max_zoom=HEATMAP_MAXZOOM)

    HeatMap(heatmap_data,
            radius=heatmap_radius,
            blur=heatmap_blur,
            gradient=heatmap_grad,
            max_zoom=19).add_to(fmap)

    fmap.fit_bounds(fmap.get_bounds())

    # save map to HTML file and open with browser
    print('writing ' + html_file + '...')

    fmap.save(html_file)

    webbrowser.open(html_file, new=2, autoraise=True)

    print('done')
示例#13
0
            location=[row[5], row[6]],
            popup=row[1]
        ))
    mapElement.add_child(markuster)


# for i in range
# plotDot(getLoc('', 'CHENNAI', 'TAMIL NADU', '600029'))

#create a map
main_map = Map(prefer_canvas=True)

#Connect with database
db_connection = sqlite3.connect(database='../db.sqlite3')
# db_connection = sql.connect(host='hostname', database='db_name', user='******', password='******')
df = pd.read_sql('SELECT lat, long FROM main_userprofile', con=db_connection)

#Load dataframe and cluster
mupLoader(main_map, df)

#Add LayerControl
LayerControl().add_to(main_map)

#Set the zoom to the maximum possible
main_map.fit_bounds(main_map.get_bounds())

#Save the map to an HTML file
main_map.save('MarkerMap.html')

print('Time Taken: {} secs'.format(time()-start))