Skip to content

Instantly share code, notes, and snippets.

View jarnaldich's full-sized avatar

Joan Arnaldich jarnaldich

View GitHub Profile
@jarnaldich
jarnaldich / RGBIZE DSM with rio calc for use with nextzen DTM tiles
Created January 29, 2020 11:15
RGBIZE DSM with rio calc for use with nextzen DTM tiles #rasterio #rio #dsm #bash
#!/bin/bash
SRC=$1
DST=$2
rio calc --co COMPRESS=LZW --co BIGTIFF=YES -t uint8 "(asarray (/ (+ 3278 (read 1 1)) 256) (mod (+ 3278 (read 1 1)) 256) (* 256 (- (+ 3278 (read 1 1)) (floor (+ 3278 (read 1 1))))))" $SRC $DST
@jarnaldich
jarnaldich / copy_extent_to_clipboard.py
Created January 30, 2020 09:31
Copying map extent to clipboard in QGIS with python #qgis #python
def copy_extent_to_clipboard(separator=';'):
ext = iface.mapCanvas().extent()
coords = [ ext.xMinimum(), ext.yMinimum(), ext.xMaximum(), ext.yMaximum() ]
txt = separator.join([ "{:10.4f}".format(x) for x in coords ])
QgsApplication.clipboard().setText(txt)
# Run: exec(open('C:/Users/j.arnaldich/copy_extent_to_clipboard.py'.encode('utf-8')).read())
@jarnaldich
jarnaldich / setup.sh
Created May 18, 2020 07:29
Install new Ubuntu machine for work
# Check version
lsb_release -a
# Install zsh oh my zsh...
sudo apt install zsh
sudo apt-get install powerline fonts-powerline
git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$HOME/.zsh-syntax-highlighting" --depth 1
echo "source $HOME/.zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> "$HOME/.zshrc"
@jarnaldich
jarnaldich / Main.purs
Last active April 8, 2021 11:32
[Nested Update Purescript]
-- Proposed Purescript Solution for: https://github.com/josevalim/nested-data-structure-traversal
-- Pure solution (no mutability), Strongly Typed (try to mess around, eg, misspelling an attribute)
-- Nothing fancy (no optics), just the usual pure functional artillery (foldl, zipWith...)
-- plus the convenience of extendable row types in Purescript. A seasoned Purescript dev may improve
-- on this, though...
module Main where
import Prelude
import Data.Array (zipWith, length, (..), snoc)
@jarnaldich
jarnaldich / table_columns.sql
Last active February 12, 2024 08:57
[Introspect Table Column DataTypes in PostgreSQL] View listing all tables joined with columns and data types for PostgreSQL
CREATE OR REPLACE VIEW table_columns AS
WITH table_oids AS (
SELECT c.relname, c.oid
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE
pg_catalog.pg_table_is_visible(c.oid)),
column_types AS (
SELECT
toids.relname AS "tablename",
@jarnaldich
jarnaldich / json2csv.sh
Created November 4, 2021 06:54
[Json 2 CSV with jq] #json #jq
jq.exe --% -r ".result | map([(.doy|tostring), .timestamp, (.val|tostring), (.interpol|tostring)] | join(\",\")) | join(\"\n\")" rasdaman.json
@jarnaldich
jarnaldich / autoargs.py
Created February 20, 2022 07:28
[Automatically set attributes from __init__ args in Pyhon] #python #args #init #constructor
# Also check data classes and collections for this
import inspect
import functools
def autoargs(*include,**kwargs):
def _autoargs(func):
attrs,varargs,varkw,defaults=inspect.getargspec(func)
def sieve(attr):
if kwargs and attr in kwargs['exclude']: return False
@jarnaldich
jarnaldich / xml2json.hs
Created March 18, 2022 18:07
XML to JSON in Haskell sample #haskell #json #xml
#!/usr/bin/env stack
{-
stack
--install-ghc runghc
--package aeson
--package aeson-pretty
--package lens-aeson
--package xml-lens
-}
{-# LANGUAGE OverloadedStrings #-}
@jarnaldich
jarnaldich / etl.hs
Last active March 26, 2022 21:26
[ETL in Haskell] Enrich a geojson file with attributes coming from an .xml #haskell #xml #geojson
#!/usr/bin/env stack
{-
stack
--install-ghc runghc
--package aeson
--package lens-aeson
--package xml-lens
-}
{-# Language OverloadedStrings #-}
import Control.Monad.Reader
@jarnaldich
jarnaldich / out.py
Created March 28, 2022 09:54
[TFW from GCPs with RasterIO] #gdal #rasterio
from affine import dumpsw
ts = rio.transform.from_gcps(ds.gcps[0])
open(r"e:\public\aerot\1988040011117.tfw", 'w').write(dumpsw(ts))