Skip to content

Instantly share code, notes, and snippets.

View hoods processing.sql
alter table dublin_hoods.all_dub_new add column geom_2157 geometry(polygon, 2157);
update dublin_hoods.all_dub_new set geom_2157 = st_transform(geom, 2157);
create index
idx_all_dub_new_geom_2157 on
dublin_hoods.all_dub_new using gist (geom_2157);
-- Hex grid needs to be created in QGIS
@HeikkiVesanto
HeikkiVesanto / gist:a5a0e1f24d2680e9306ba465553de431
Created Dec 7, 2021
Download and parse to PostgreSQL Dublin Hoods
View gist:a5a0e1f24d2680e9306ba465553de431
import zipfile, os, subprocess, psycopg2, codecs, json
from urllib.request import Request, urlopen
import shutil
dir_path = os.path.dirname(os.path.realpath(__file__))
DB = "PG:dbname=postgis host=localhost port=5432 user=postgres password=postgres"
conn = psycopg2.connect(host='localhost', dbname='postgis', user='postgres', password='postgres')
print(DB)
@HeikkiVesanto
HeikkiVesanto / glob.py
Last active Nov 26, 2021
Spinning globe
View glob.py
# QGIS spinning globe export.
# Run https://gist.github.com/Joonalai/7b8693ef904df75cb15cb9af0e82c032 first
# Uses the GISPO globe plugin: https://github.com/GispoCoding/GlobeBuilder/
import time
from PyQt5.QtGui import *
mapCanvas = iface.mapCanvas()
vLayer = iface.activeLayer()
def spin(seconds):
View hood_hex.sql
create index idx_liberties_geom_2157 on dublin_hoods.liberties using gist (st_transform(geom, 2157));
create table dublin_hoods.liberties_extent as
select g.id, g.geom, count(nh.*) as count, ((count(nh.*)/(select count(*)::float from dublin_hoods.liberties)) * 100)::int as pct
from dublin_hoods.hex_grid g
left join dublin_hoods.liberties nh on st_intersects(g.geom, st_transform(nh.geom, 2157)) --My grid is in EPSG:2157 but the geoms are 4326 so need to reproject.
group by g.id, g.geom
having count(nh.*) > 0;
@HeikkiVesanto
HeikkiVesanto / parse_hoods.py
Last active Jan 15, 2022
Parse Dublin Hoods Simple
View parse_hoods.py
import os, psycopg2, json
from urllib.request import Request, urlopen
dir_path = os.path.dirname(os.path.realpath(__file__))
# Database details:
DB = "PG:dbname=postgis host=localhost port=5432 user=postgres password=postgres"
conn = psycopg2.connect(host='localhost', dbname='postgis', user='postgres', password='postgres')
@HeikkiVesanto
HeikkiVesanto / load_osm_history.py
Last active Aug 8, 2021
pipe osmium-tools extracts into PostgreSQL
View load_osm_history.py
import os
import psycopg2
import subprocess
def runogr2ogr(infile):
# import the data
try:
command = ["ogr2ogr", "-f", "PostgreSQL",
OGR_CONN_STRING,
@HeikkiVesanto
HeikkiVesanto / py3_osgeo.bat
Created Mar 9, 2018
Launch Python3 in OSGeo4W
View py3_osgeo.bat
@ECHO OFF
set OSGEO4W_ROOT=C:\OSGeo4W64
set PATH=%OSGEO4W_ROOT%\bin;%PATH%
set PATH=%PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
@echo off
call "%OSGEO4W_ROOT%\bin\o4w_env.bat"
call "%OSGEO4W_ROOT%\bin\qt5_env.bat"
View walk.json
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View world_country.topojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View TransSiberianSimplified.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.