def add_webm_xys(df):
  """computer Mercator x and y values from Longitude and Latitude"""

  x, y = [c for c in list(webm(df.loc[:, 'Longitude'], df.loc[:, 'Latitude']))]
  df = df.assign(webm_x=x).copy()
  df = df.assign(webm_y=y).copy()
  return df
Пример #2
0
def create_image(longitude_range, latitude_range, w=plot_width, h=plot_height):
    x_range, y_range = webm(longitude_range, latitude_range)
    cvs = ds.Canvas(plot_width=w,
                    plot_height=h,
                    x_range=x_range,
                    y_range=y_range)
    agg = cvs.points(df, 'easting', 'northing', ds.count_cat('race'))
    img = tf.shade(agg, color_key=color_key, how='eq_hist')
    return img
Пример #3
0
def serve_image():  #dataset
    # parse params
    print('-------------- server receives request-----------')
    width = int(request.args.get('width'))
    height = int(request.args.get('height'))
    spread = int(request.args.get('spread'))
    xmin = float(request.args.get('xmin'))
    xmax = float(request.args.get('xmax'))
    ymax = float(request.args.get('ymax'))
    ymin = float(request.args.get('ymin'))

    colorw = str(request.args.get('colorw'))
    colorb = str(request.args.get('colorb'))
    colora = str(request.args.get('colora'))
    colorh = str(request.args.get('colorh'))
    coloro = str(request.args.get('coloro'))

    x_range = webm(latitude=ymin, longitude=xmin)
    y_range = webm(latitude=ymax, longitude=xmax)

    cvs = ds.Canvas(plot_width=width,
                    plot_height=height,
                    x_range=(x_range[0], y_range[0]),
                    y_range=(x_range[1], y_range[1]))

    agg = cvs.points(df, 'easting', 'northing', ds.count_cat('race'))

    color_key = {
        'w': colorw,
        'b': colorb,
        'a': colora,
        'h': colorh,
        'o': coloro
    }

    img = tf.shade(agg, color_key=color_key, how='eq_hist')
    img = tf.spread(img, px=spread)
    img_io = img.to_bytesio()
    return send_file(img_io, mimetype='image/png')
def get_plot_params(bbox, plot_width=PLOT_WIDTH):
  """returns the Web Mercator x_range and y_range in meters, and plot_width and plot_height in pixels.

  Args:
    bbox: bounding box Web Mercator tuple (longitude_range, latitude_range) in degrees.
          i.e. ((min_longitude, max_latitude), (min_latitude, max_latitude))
    plot_width (int): the desirable plot width in pixel

  Returns:
    x_range, y_range, plot_width, plot_height

  """
  x_range, y_range = webm(*bbox)
  plot_width, plot_height = get_plot_size(x_range, y_range, plot_width=plot_width)
  return x_range, y_range, plot_width, plot_height
Пример #5
0
# In[6]:

USA = ((-124.72, -66.95), (23.55, 50.06))
LakeMichigan = ((-91.68, -83.97), (40.75, 44.08))
Chicago = ((-88.29, -87.30), (41.57, 42.00))
Chinatown = ((-87.67, -87.63), (41.84, 41.86))
NewYorkCity = ((-74.39, -73.44), (40.51, 40.91))
LosAngeles = ((-118.53, -117.81), (33.63, 33.96))
Houston = ((-96.05, -94.68), (29.45, 30.11))
Austin = ((-97.91, -97.52), (30.17, 30.37))
NewOrleans = ((-90.37, -89.89), (29.82, 30.05))
Atlanta = ((-84.88, -84.04), (33.45, 33.84))

from datashader.utils import lnglat_to_meters as webm
x_range, y_range = [list(r) for r in webm(*USA)]

plot_width = int(900)
plot_height = int(plot_width * 7.0 / 12)

background = "black"

# In[7]:

from functools import partial
from datashader.utils import export_image
from datashader.colors import colormap_select, Greys9
from IPython.core.display import HTML, display

export = partial(export_image, background=background, export_path="export")
cm = partial(colormap_select, reverse=(background != "black"))
import pandas as pd
from datashader.utils import lnglat_to_meters as webm

with open('data/inaturalist.csv', 'w') as f:
    f.write('x,y\n')
    for chunk in pd.read_csv("data/observations.csv", chunksize=10000):
        txt = ''
        for lng, lat in zip(chunk['decimalLongitude'],
                            chunk['decimalLatitude']):
            txt += "%s,%s\n" % webm(lng, lat)
        f.write(txt)
Пример #7
0
# In[ ]:

# Removing some outliers
#Brazils most Northern spot is at 5 deg 16′ 27.8″ N latitude.;
geo = geo[geo.geolocation_lat <= 5.27438888]
#it’s most Western spot is at 73 deg, 58′ 58.19″W Long.
geo = geo[geo.geolocation_lng >= -73.98283055]
#It’s most southern spot is at 33 deg, 45′ 04.21″ S Latitude.
geo = geo[geo.geolocation_lat >= -33.75116944]
#It’s most Eastern spot is 34 deg, 47′ 35.33″ W Long.
geo = geo[geo.geolocation_lng <= -34.79314722]

# In[ ]:

from datashader.utils import lnglat_to_meters as webm
x, y = webm(geo.geolocation_lng, geo.geolocation_lat)
geo['x'] = pd.Series(x)
geo['y'] = pd.Series(y)

# Then we treat the latitute and longitude coordinates and transform then to Mercator x/y Coordinates.

# In[ ]:

geo.head(3)

# ## Zip Codes in Brazil
# Finally plotting the coordinates on a map. We see there is a relationship between the zip code prefix and the location of that zip code. They start in Sao Paulo, with prefix 01001, and then increase counterclockwise finishing in Rio Grande do Sul (south of Brazil), with prefix 99990.

# In[ ]:

# transforming the prefixes to int for plotting purposes
    'groß_2'
]
df['diskret_kronendurchmesser'] = pd.cut(df.Kronendurchmesser,
                                         bins=bins,
                                         labels=labels)
df.drop(columns=['Gattung/Art/Deutscher Name'])

# In[7]:

# Alle Bäume, die nach 2000 gepflanzt wurden
df['Pflanzjahr'] = (df['Pflanzjahr'].astype(int))
new_df = df[df['Pflanzjahr'] >= 2000].copy()

# In[8]:

sw = webm(x_range_min, y_range_min)
ne = webm(x_range_max, y_range_max)
FFM = zip(sw, ne)

# In[9]:

# Initialize plot for datashader

plot_width = int(2000)
plot_height = int(2000)
background = "black"
export = partial(export_image, background=background, export_path="export")
#cm = partial(colormap_select, reverse=(background!="black"))
cm = partial(colormap_select, reverse=(background != "black"))

display(HTML("<style>.container {width:100%} !important; }</style>"))