#!/usr/bin/env python # coding: utf-8 # In[1]: import geopandas as gpd rivers = gpd.read_file(r"C:\dev\05_geodata\landuse\ETAK_EESTI_GPKG\ETAK_EESTI_GPKG.gpkg", layer='E_203_vooluveekogu_j') # In[2]: rivers.describe() # In[3]: rivers.dtypes # In[4]: rivers.crs # In[5]: import numpy as np import seaborn as sns import matplotlib.pyplot as plt get_ipython().run_line_magic('matplotlib', 'inline') import datashader as ds import datashader.transfer_functions as tf from functools import partial from datashader.utils import export_image from datashader.colors import colormap_select, Hot, viridis # In[6]: rivers['cent_x'] = rivers['geometry'].apply(lambda x: x.centroid.x) # In[7]: rivers['cent_y'] = rivers['geometry'].apply(lambda x: x.centroid.y) # In[8]: background = 'black' # a "partially applied" convenience function for saving the image export = partial(export_image, background = background, export_path=".") # this "partially applied" convenience function handles colorizing of the image, incl reversing your colormap if you like cm = partial(colormap_select, reverse=False) # In[9]: rivers.total_bounds # In[12]: x = 739420.95 - 373559.669 y = 6615024.21 - 6377128.388 print(f"{x} / {y}") # In[13]: x_factor = x / y print(x_factor) # In[47]: w = 800 *2 h = int(w / x_factor) # In[48]: cvs = ds.Canvas(plot_width=w, plot_height=h) # "tyyp" denotes the "magnitude" of the river, 50-river, 40-stream ... channel, 10-ditch agg = cvs.points(rivers, 'cent_x', 'cent_y', ds.mean('tyyp')) # to change color map you culd could use the parameter cmap=cm(viridis) or cmap=cm(Hot) shaded = tf.shade(agg, cmap=cm(['cyan','black'], False), how='linear', alpha=210, min_alpha=150) img_dyn = tf.spread(shaded, px=1, how='add') img = tf.set_background(img_dyn, background) img # In[49]: export(img,'../source/_static/day-02-river-lines') # In[117]: # to change color map you culd could use the parameter cmap=cm(viridis) or cmap=cm(Hot) shaded = tf.shade(agg, cmap=cm(Hot, False), how='linear', alpha=210, min_alpha=150) img_dyn = tf.spread(shaded, px=1, how='over') img = tf.set_background(img_dyn, background) img # In[ ]: