Skip to content

Instantly share code, notes, and snippets.

Avatar

Francesco LoConti fralc

View GitHub Profile
View xarray_coords_to_geohash.py
import numpy as np
import geohash
import xarray as xr
array = xr.DataArray(np.array([[1, 2, 3], [4, 5, 6]]), coords=[("lat", [36, 37]), ("lon", [12, 13, 14])])
lat_arr, lon_arr = xr.broadcast(array.lat, array.lon)
f = lambda y, x: geohash.encode(y, x, 7)
array_geohash = xr.apply_ufunc(f, lat_arr, lon_arr, vectorize=True)
@fralc
fralc / raster_postgis.py
Last active Jun 5, 2020 — forked from gzagatti/raster_postgis.py
Loads raster data from POSTGIS directly to numpy.array using rasterio
View raster_postgis.py
import psycopg2
from rasterio.io import MemoryFile
conn = pscopg2.connect("<connection string>")
cur = conn.cursor()
# ensure that the GTiff driver is available,
# see https://postgis.net/docs/postgis_gdal_enabled_drivers.html
cur.execute('''
SET postgis.gdal_enabled_drivers TO 'GTiff';
WITH temp as (