Skip to content

Instantly share code, notes, and snippets.

@perrygeo
perrygeo / example.py
Last active October 9, 2024 23:30
Flyte example
from flytekit import ContainerTask, kwtypes, task, workflow
@task
def say_hello(name: str, area: float) -> str:
return f"Hey {name}! You have an ellipse of area {area}"
calculate_ellipse_area_python = ContainerTask(
command=[
@perrygeo
perrygeo / osm-tiledb.txt
Created June 23, 2023 12:05
Convert Open Street Map data into TileDB arrays
# Using osm.pbf extracts from https://download.geofabrik.de/index.html
# Requires GDAL 3.7+ with the TileDB driver
ogr2ogr -f TileDB ./dc-lines district-of-columbia-latest.osm.pbf lines
ogr2ogr -f TileDB ./dc-points district-of-columbia-latest.osm.pbf points
ogr2ogr -f TileDB ./dc-polygons district-of-columbia-latest.osm.pbf multipolygons
DROP TABLE if EXISTS boundaries;
CREATE TABLE boundaries (
id BIGSERIAL primary key,
geometry geometry(multipolygon, 4326) NOT null
);
CREATE INDEX idx_boundaries_geometry
ON boundaries
USING gist (geometry);
@perrygeo
perrygeo / us_counties_geocoding.md
Created December 13, 2022 15:27
Geocoding US Counties with PostGIS

County/State level geocoding in postgis

If your geocoding task requires only US county and state level information, you can avoid a third party web service dependency using open data and postgis.

Data source

Natural Earth counties, US only.

@perrygeo
perrygeo / failed_clojerl_compile.txt
Last active January 29, 2021 16:18
Clojerl, attempt 1 using the example-web-app failed (compiling clojure.core)
💲 git clone https://github.com/clojerl/example-web-app
Cloning into 'example-web-app'...
remote: Enumerating objects: 78, done.
remote: Total 78 (delta 0), reused 0 (delta 0), pack-reused 78
Unpacking objects: 100% (78/78), 7.94 KiB | 507.00 KiB/s, done.
mperry@t14-dev:/tmp
💲 cd example-web-app/
@perrygeo
perrygeo / asyncio-intro.md
Created November 9, 2020 14:55
Basic intro to asyncio

Baking a cake: Why we need asyncronous code in Python

This is a basic analogy that explains why we need asyncio. Consider the process of baking a cake:

Before you bake a cake, you need to preheat the oven

def preheat_oven(target_temp):
    temp = 100
    while temp < target_temp:
extern crate byteorder;
extern crate itertools;
extern crate rustfft;
use byteorder::{LittleEndian, ReadBytesExt};
use num_complex::Complex;
use rustfft::num_traits::Zero;
use rustfft::FFTplanner;
use std::fs::File;
use std::io::Seek;
from h3 import h3
import json
from rasterstats import gen_zonal_stats
def hexbin_features(bounding_polygon, zoom=8):
"""Takes a GeoJSON-like geometry dictionary with type Polygon
and yields GeoJSON-like Features representing the hexbins
that cover the polygon at a given zoom level
#!/usr/bin/env python
from fiona.transform import transform_geom
from rasterstats import point_query
import mercantile
def make_dem_url(lon: float, lat: float, z: int = 14) -> str:
"""Returns a URL referencing the GeoTiff Digitial Elevation Model (DEM)
for the given point at a zoom level (default, max is 14).

Installing pgextwlist

# Dockerfile
ENV PGEXTWLIST_VERSION 1.7
RUN wget -q -O pgextwlist-${PGEXTWLIST_VERSION}.tar.gz https://github.com/dimitri/pgextwlist/archive/v${PGEXTWLIST_VERSION}.tar.gz
RUN tar -xzf pgextwlist-${PGEXTWLIST_VERSION}.tar.gz && \
    cd pgextwlist-${PGEXTWLIST_VERSION} && \
    make -j${CPUS} && make install && \
 export pkg=$(pg_config --pkglibdir) &amp;&amp; mkdir $pkg/plugins &amp;&amp; cp $pkg/pgextwlist.so $pkg/plugins