Beispiel #1
0
    def drawmap(self):
        """
        Multiple examples of kernel density estimation visualization
        """
        data = self.get_dao_object()
        # geoplotlib.kde(data, bw=5, cut_below=1e-4)

        # lowering clip_above changes the max value in the color scale
        # geoplotlib.kde(data, bw=5, cut_below=1e-4, clip_above=.1)

        # different bandwidths
        geoplotlib.kde(data, bw=20, cmap=self.cmap, cut_below=1e-4)
        # geoplotlib.kde(data, bw=2, cmap='PuBuGn', cut_below=1e-4)

        # linear colorscale
        # geoplotlib.kde(data, bw=5, cmap='jet', cut_below=1e-4, scaling='lin')

        geoplotlib.set_bbox(BoundingBox.from_nominatim('CHINA'))

        geoplotlib.savefig(self.ouput_filename)
Beispiel #2
0
"""
Example of rendering shapefiles
"""
from geoplotlib.utils import BoundingBox
import geoplotlib


geoplotlib.shapefiles('data/dk_kommune/dk_kommune',
                  f_tooltip=lambda attr: attr['STEDNAVN'],
                  color=[0,0,255])

geoplotlib.set_smoothing(True)
geoplotlib.set_bbox(BoundingBox.DK)
geoplotlib.show()
Beispiel #3
0
#!/usr/bin/env python2
import geoplotlib
from geoplotlib.utils import read_csv, BoundingBox, DataAccessObject

data = read_csv('filtered_lonlat.csv')

# http://andreacuttone.com/geoplotlib/api.html#module-geoplotlib
geoplotlib.dot(data, color=[0,0,0], point_size=1.5)
geoplotlib.kde(data, bw=10, cmap='PuBuGn', cut_below=1e-4, clip_above=1e-2, alpha=180)
geoplotlib.graph(read_csv('group0.csvgraph.csv'), src_lat='flat', src_lon='flon',
        dest_lat='tlat', dest_lon='tlon', color=[0,0,0], linewidth=2)
geoplotlib.graph(read_csv('group1.csvgraph.csv'), src_lat='flat', src_lon='flon',
        dest_lat='tlat', dest_lon='tlon', color=[0,255,0], linewidth=2)
geoplotlib.graph(read_csv('group2.csvgraph.csv'), src_lat='flat', src_lon='flon',
        dest_lat='tlat', dest_lon='tlon', color=[128,0,128], linewidth=2)
geoplotlib.kde(read_csv('chokepoints.csv'), bw=10, cmap='hot',
        cut_below=1e-4, clip_above=1e-2, alpha=180)

bbox = BoundingBox(north=25.7188,west=-80.280,south=25.711,east=-80.280)
geoplotlib.set_bbox(bbox)
geoplotlib.set_window_size(1400, 1600)
#geoplotlib.set_window_size(700, 800)
geoplotlib.tiles_provider('toner')
geoplotlib.set_smoothing(True)
geoplotlib.savefig('output')
#geoplotlib.show()
Beispiel #4
0
"""
Multiple examples of kernel density estimation visualization
"""
import geoplotlib
from geoplotlib.utils import read_csv, BoundingBox, DataAccessObject

data = read_csv('data/opencellid_dk.csv')

geoplotlib.kde(data, bw=5, cut_below=1e-4)

# lowering clip_above changes the max value in the color scale
#geoplotlib.kde(data, bw=5, cut_below=1e-4, clip_above=.1)

# different bandwidths
#geoplotlib.kde(data, bw=20, cmap='PuBuGn', cut_below=1e-4)
#geoplotlib.kde(data, bw=2, cmap='PuBuGn', cut_below=1e-4)

# linear colorscale
#geoplotlib.kde(data, bw=5, cmap='jet', cut_below=1e-4, scaling='lin')

geoplotlib.set_bbox(BoundingBox.KBH)
geoplotlib.show()
Beispiel #5
0
        while len(queue) > 0:
            qt = queue.pop()
            if qt.can_split(x, y):
                queue.extend(qt.split())
            else:
                done.append(qt)

        print(len(queue), len(done))

        if self.cmap is not None:
            for qt in done:
                area = (qt.right - qt.left) * (qt.top - qt.bottom)
                self.painter.set_color(
                    self.cmap.to_color(1 + area, 1 + maxarea, 'log'))
                self.painter.rect(qt.left, qt.top, qt.right, qt.bottom)
        else:
            for qt in done:
                self.painter.linestrip([qt.left, qt.right, qt.right, qt.left],
                                       [qt.top, qt.top, qt.bottom, qt.bottom],
                                       closed=True)

    def draw(self, proj, mouse_x, mouse_y, ui_manager):
        self.painter.batch_draw()


data = geoplotlib.utils.read_csv('data/test_map2.csv')
geoplotlib.add_layer(QuadsLayer(data, cmap=None))
geoplotlib.set_smoothing(False)
geoplotlib.set_bbox(geoplotlib.utils.BoundingBox.DK)
geoplotlib.show()
"""
Example of delaunay triangulation
"""
from geoplotlib.layers import DelaunayLayer
import geoplotlib
from geoplotlib.utils import read_csv, BoundingBox


data = read_csv('data/test_map2.csv')
geoplotlib.delaunay(data, cmap='hot_r')
geoplotlib.set_bbox(BoundingBox.DK)
geoplotlib.set_smoothing(True)
geoplotlib.show()
Beispiel #7
0
        k_means.fit(np.vstack([x,y]).T)
        labels = k_means.labels_

        self.cmap = create_set_cmap(set(labels), 'hsv')
        for l in set(labels):
            self.painter.set_color(self.cmap[l])
            self.painter.convexhull(x[labels == l], y[labels == l])
            self.painter.points(x[labels == l], y[labels == l], 2)
    
            
    def draw(self, proj, mouse_x, mouse_y, ui_manager):
        ui_manager.info('Use left and right to increase/decrease the number of clusters. k = %d' % self.k)
        self.painter.batch_draw()


    def on_key_release(self, key, modifiers):
        if key == pyglet.window.key.LEFT:
            self.k = max(2,self.k - 1)
            return True
        elif key == pyglet.window.key.RIGHT:
            self.k = self.k + 1
            return True
        return False
  

data = geoplotlib.utils.read_csv('data/bus.csv')
geoplotlib.add_layer(KMeansLayer(data))
geoplotlib.set_smoothing(True)
geoplotlib.set_bbox(geoplotlib.utils.BoundingBox.DK)
geoplotlib.show()
Beispiel #8
0
"""
Multiple examples of kernel density estimation visualization
"""
import geoplotlib
from geoplotlib.utils import read_csv, BoundingBox, DataAccessObject

data = read_csv('data/opencellid_dk.csv')

#geoplotlib.kde(data, bw=5, cut_below=1e-4)

# lowering clip_above changes the max value in the color scale
#geoplotlib.kde(data, bw=5, cut_below=1e-4, clip_above=.1)

# different bandwidths
geoplotlib.kde(data, bw=20, cmap='OrRd', cut_below=1e-4)
#geoplotlib.kde(data, bw=2, cmap='PuBuGn', cut_below=1e-4)

# linear colorscale
#geoplotlib.kde(data, bw=5, cmap='jet', cut_below=1e-4, scaling='lin')

geoplotlib.set_bbox(BoundingBox.from_nominatim('CHINA'))

geoplotlib.savefig('full.png')
geoplotlib.show()
f = open("VLOCs.csv", "w+")
f.close()

#write csv to be read by geoplotlib
with open('VLOCs.csv', mode='w', newline='') as VLOCs:
    VLOCs = csv.writer(VLOCs, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
    VLOCs.writerow(['name', 'S_lat', 'S_lon', 'D_lat', 'D_lon'])
    for station in Locations:
        VLOCs.writerow([station[0], station[1], station[2], station[3], station[4]])

#empty SLOCs.csv
f = open("SLOCs.csv", "w+")
f.close()

#write csv to be read by geoplotlib
with open('SLOCs.csv', mode='w', newline='') as SLOCs:
    SLOCs = csv.writer(SLOCs, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
    SLOCs.writerow(['name', 'lat', 'lon'])
    for station in Locations:
        SLOCs.writerow([station[0], station[1], station[2]])

#plot stations
Plotdata1 = read_csv('VLOCs.csv')
Plotdata2 = read_csv('SLOCs.csv')
gp.set_bbox(BoundingBox(north=9, west=110, south=1, east=95))
gp.graph(Plotdata1, 'S_lat', 'S_lon', 'D_lat', 'D_lon', linewidth=2, color='Blues')
gp.dot(Plotdata2, color='blue', point_size=3)
gp.labels(Plotdata2, 'name', color='black', font_size=8, anchor_x='center')
gp.tiles_provider('positron')

gp.show()
"""
Example of choropleth using geojson files.
Based on by Mike Bostock's unemployment choropleth http://bl.ocks.org/mbostock/4060606
"""

import geoplotlib
from geoplotlib.utils import BoundingBox
from geoplotlib.colors import ColorMap
import json


# find the unemployment rate for the selected county, and convert it to color
def get_color(properties):
    key = str(int(properties['STATE'])) + properties['COUNTY']
    if key in unemployment:
        return cmap.to_color(unemployment.get(key), .15, 'lin')
    else:
        return [0, 0, 0, 0]


with open('data/unemployment.json') as fin:
    unemployment = json.load(fin)

cmap = ColorMap('Blues', alpha=255, levels=10)
geoplotlib.geojson('data/gz_2010_us_050_00_20m.json', fill=True, color=get_color, f_tooltip=lambda properties: properties['NAME'])
geoplotlib.geojson('data/gz_2010_us_050_00_20m.json', fill=False, color=[255, 255, 255, 64])
geoplotlib.set_bbox(BoundingBox.USA)
geoplotlib.show()
Beispiel #11
0
def show_geoplot(results, mbc):
	data=DataAccessObject.from_dataframe(results[["lat","lon"]])
	gpl.hist(data, colorscale='sqrt', binsize=4)
	gpl.kde(data, bw=5, cut_below=1e-3)
	gpl.set_bbox(BoundingBox(mbc[0],mbc[1],mbc[2],mbc[3]))
	gpl.show()