Skip to content

Instantly share code, notes, and snippets.

@GeoWill
GeoWill / get_unsplit_postcodes.sql
Last active January 8, 2021 20:04
Overly complicated way of "pick a postcode that is a) inside the (multi-)polygon and b) far away from edges"
with
-- n as (select 'Highland' as name),
-- n as (select 'Na h-Eileanan an Iar' as name),
n as (select 'City of London' as name),
-- n as (select 'Bristol City Council' as name),
buffered as (
select
n.name, oo.common_name, f.factor, st_buffer(st_simplify(largest_poly.geom, 0.01), -f.factor) as geom, largest_poly.geom as orig_geom
from
n, organisations_organisation oo

Keybase proof

I hereby claim:

  • I am geowill on github.
  • I am willroper (https://keybase.io/willroper) on keybase.
  • I have a public key ASCXa4HJfVcw30ifHtn7jgvURYLi9OPLUZZ8oN1KdyRQDgo

To claim this, I am signing this object:

@GeoWill
GeoWill / combine-json.sh
Last active November 21, 2018 18:39
Append some new json to some existing json
jq -s '.[0] + .[1]' original.json new.json > updated.json
@GeoWill
GeoWill / to_ascii.py
Created September 3, 2018 10:08
QGIS Function to make strings ascii only
"""
Make place names be lowercase ascii only with '-' instead of ' '.
"""
from qgis.core import *
from qgis.gui import *
ascii_dict = {ord(u'ß'): u'ss', ord(u'à'): u'a', ord(u'á'): u'a', ord(u'â'): u'a', ord(u'ã'): u'a', ord(u'ä'): u'a', ord(u'å'): u'a', ord(u'æ'): u'ae', ord(u'ç'): u'c', ord(u'è'): u'e', ord(u'é'): u'e', ord(u'ê'): u'e', ord(u'ë'): u'e', ord(u'ì'): u'i', ord(u'í'): u'i', ord(u'î'): u'i', ord(u'ï'): u'i', ord(u'ð'): u'd', ord(u'ñ'): u'n', ord(u'ò'): u'o', ord(u'ó'): u'o', ord(u'ô'): u'o', ord(u'õ'): u'o', ord(u'ö'): u'o', ord(u'÷'): u'/', ord(u'ø'): u'o', ord(u'ù'): u'u', ord(u'ú'): u'u', ord(u'û'): u'u', ord(u'ü'): u'u', ord(u'ý'): u'y', ord(u'þ'): u'p', ord(u'ÿ'): u'y', ord(u'’'):u"'"}
@qgsfunction(args='auto', group='Custom')
@GeoWill
GeoWill / merge-distrito-local-wgs84.sh
Created April 19, 2018 15:11
Scripts to merge local electoral districts in Mexico
#!/bin/bash
# To call the script open the terminal in the same folder as the script
# Ensure it is executable: $ chmod u+x merge-reproject.sh
# Call it with $ ./merge-distrito-local-reproject.sh
# SET TO PATH WHERE YOU WANT THE SHP TO BE CREATED
FILE='/enter/path/here/DISTRITO_LOCAL-wgs1984.shp' # name of file to be merged to
@GeoWill
GeoWill / merge-reproject.sh
Last active May 8, 2018 16:52
Simple shell script to merge shapefiles from INE
#!/bin/bash
# To call the script open the terminal in the same folder as the script
# Ensure it is executable: $ chmod u+x merge-reproject.sh
# Call it with the layer you wish to combine: eg. $ merge-reproject.sh ENTIDAD
# LAYERS are 'SECCION' 'ENTIDAD' and 'DISTRITO'
LYR=$1
#SET TO PATH WHERE YOU WANT THE SHP TO BE CREATED
county,town
雲林縣,麥寮鄉
彰化縣,員林市
連江縣,南竿鄉
連江縣,北竿鄉
連江縣,莒光鄉
連江縣,東引鄉
金門縣,金城鎮
金門縣,金沙鎮
金門縣,金湖鎮
@GeoWill
GeoWill / villages.csv
Created March 2, 2018 07:52
villages
We can't make this file beautiful and searchable because it's too large.
VILLCODE,COUNTYNAME,TOWNNAME,VILLNAME,VILLENG,COUNTYID,COUNTYCODE,TOWNID,TOWNCODE,NOTE
10013030S01,屏東縣,東港鎮,,,T,10013,T03,10013030,未編定村里
64000130006,高雄市,林園區,中門里,Zhongmen Vil.,E,64000,E13,64000130,
10018010054,新竹市,東區,關新里,Guanxin Vil.,O,10018,O01,10018010,
64000130008,高雄市,林園區,港埔里,Gangpu Vil.,E,64000,E13,64000130,
64000100010,高雄市,旗津區,上竹里,Shangzhu Vil.,E,64000,E10,64000100,
64000100013,高雄市,旗津區,中興里,Zhongxing Vil.,E,64000,E10,64000100,
09007010006,連江縣,南竿鄉,津沙村,Jinsha Vil.,Z,09007,Z01,09007010,
09007010007,連江縣,南竿鄉,馬祖村,Mazu Vil.,Z,09007,Z01,09007010,
09007010009,連江縣,南竿鄉,四維村,Siwei Vil.,Z,09007,Z01,09007010,
@GeoWill
GeoWill / villages.csv
Created March 2, 2018 07:52
villages
We can't make this file beautiful and searchable because it's too large.
VILLCODE,COUNTYNAME,TOWNNAME,VILLNAME,VILLENG,COUNTYID,COUNTYCODE,TOWNID,TOWNCODE,NOTE
10013030S01,屏東縣,東港鎮,,,T,10013,T03,10013030,未編定村里
64000130006,高雄市,林園區,中門里,Zhongmen Vil.,E,64000,E13,64000130,
10018010054,新竹市,東區,關新里,Guanxin Vil.,O,10018,O01,10018010,
64000130008,高雄市,林園區,港埔里,Gangpu Vil.,E,64000,E13,64000130,
64000100010,高雄市,旗津區,上竹里,Shangzhu Vil.,E,64000,E10,64000100,
64000100013,高雄市,旗津區,中興里,Zhongxing Vil.,E,64000,E10,64000100,
09007010006,連江縣,南竿鄉,津沙村,Jinsha Vil.,Z,09007,Z01,09007010,
09007010007,連江縣,南竿鄉,馬祖村,Mazu Vil.,Z,09007,Z01,09007010,
09007010009,連江縣,南竿鄉,四維村,Siwei Vil.,Z,09007,Z01,09007010,
TOWNID TOWNCODE COUNTYNAME TOWNNAME TOWNENG COUNTYID COUNTYCODE
V02 10014020 臺東縣 成功鎮 Chenggong Township V 10014
T21 10013210 屏東縣 佳冬鄉 Jiadong Township T 10013
P13 10009130 雲林縣 麥寮鄉 Mailiao Township P 10009
V11 10014110 臺東縣 綠島鄉 Lvdao Township V 10014
V16 10014160 臺東縣 蘭嶼鄉 Lanyu Township V 10014
N07 10007120 彰化縣 田中鎮 Tianzhong Township N 10007
N19 10007170 彰化縣 社頭鄉 Shetou Township N 10007
T14 10013140 屏東縣 竹田鄉 Zhutian Township T 10013
T05 10013050 屏東縣 萬丹鄉 Wandan Township T 10013