Skip to content

Instantly share code, notes, and snippets.

@timlinux
timlinux / find_multipart.py
Last active August 13, 2023 13:19
A QGIS Python snippet to select multipart features in the active layer
# Find all multipart features in the active layer
l = iface.activeLayer()
iter = l.getFeatures()
geoms = []
for feature in iter:
geom = feature.geometry()
if geom.isMultipart():
l.select(feature.id())
geoms.append(geom)
@agounaris
agounaris / word_count_notebook.py
Created April 28, 2017 23:21
Word count of markdown jupyter notebook cells
import io
from IPython.nbformat import current
with io.open(filepath, 'r', encoding='utf-8') as f:
nb = current.read(f, 'json')
word_count = 0
for cell in nb.worksheets[0].cells:
if cell.cell_type == "markdown":
word_count += len(cell['source'].replace('#', '').lstrip().split(' '))
@tylermorganwall
tylermorganwall / humanity_globe.R
Created August 17, 2021 14:37
3D Humanity Globe
library(rayshader)
library(rayrender)
popdata = raster::raster("gpw_v4_population_density_rev11_2020_15_min.tif")
population_mat = rayshader:::flipud(raster_to_matrix(popdata))
above1 = population_mat > 1
above5 = population_mat > 5
above10 = population_mat > 10