Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin de Youngster kevin-deyoungster

View GitHub Profile
@kevin-deyoungster
kevin-deyoungster / geojson_to_h3.py
Created Jul 26, 2020
Function to convert GeoJSON feature to H3 cells and vice versa
View geojson_to_h3.py
from h3 import h3
def feature_to_h3set(feature, resolution):
return h3.polyfill(feature["geometry"], resolution, True)
def h3_to_feature(hex_address, properties={}):
coordinates = [h3.h3_to_geo_boundary(hex_address, True)]
return {
@kevin-deyoungster
kevin-deyoungster / sqlitedict_to_postgresql.py
Last active Jul 26, 2020
(SqliteDict -> Postgres) Script to migrate an SqliteDict-initialized sqlite database to Postgres.
View sqlitedict_to_postgresql.py
"""
This script migrates data from an sqlitedict-initialized database
to postgres database with similar schema
The resulting postgres database will have schema:
* key (str)
* value (jsonb/json binary)
"""
from psycopg2 import connect, Error
from sqlitedict import SqliteDict
@kevin-deyoungster
kevin-deyoungster / export_selected_features.py
Created Jul 14, 2020
QGIS script to export selected features to GeoJSON (separately)
View export_selected_features.py
import json
layer = qgis.utils.iface.activeLayer()
for i, elem in enumerate(layer.selectedFeatures()):
attrs = elem.__geo_interface__
filename = attrs["properties"]["DISTRICT"] # change this to whatever you want to be filename
View Latex two-column with wide table
\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage{adjustbox}
\begin{document}
\lipsum[1-5] % To create a random first page
\begin{table}[ht]
@kevin-deyoungster
kevin-deyoungster / walk.py
Created Jun 29, 2019
Walk through folder and apply function on files with specific extension
View walk.py
"""
This module handles crawling through folders and subfolders and applies function
on certain files
"""
from pathlib import Path
def walk_and_apply_function(target_extension, function, folder=None):
"""
Goes through [folder] recursively and runs function on every [target_extension] file