Skip to content

Instantly share code, notes, and snippets.

View pramsey's full-sized avatar

Paul Ramsey pramsey

View GitHub Profile
@pramsey
pramsey / vrt2pgsql.py
Created July 9, 2021 22:56
OpenTopography SRTM VRT Parser
import sys
import xml.etree.ElementTree as ET
import argparse
######################################################################
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--file',
required=True,
dest='file',
<html>
<head>
<style>
html {
font-family: sans-serif;
}
.geomA {
marker-end: url(#vertexA); marker-mid: url(#vertexA); fill:#bbbbff; fill-opacity:0.5; stroke:#0000ff; stroke-width:1; stroke-opacity:1; stroke-miterlimit:4; stroke-linejoin:miter; stroke-linecap:square;
}
/*
cc projtimer.c -I/usr/local/include -L/usr/local/lib -lproj -o projtimer
./projtimer epsg:4326 epsg:4326
./projtimer epsg:4326 epsg:26910
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>

Parallel PostGIS Testing

Create a database, enable PostGIS and load the polling divisions.

createdb parallel
psql -c 'create extension postgis' -d parallel
wget http://ftp.geogratis.gc.ca/pub/nrcan_rncan/vector/electoral/2015/pd338.2015.zip
unzip pd338.2015.zip
shp2pgsql -s 3347 -I -D -W latin1 PD_A.shp pd | psql parallel
@pramsey
pramsey / pgconf-eu-keynote.md
Last active June 16, 2020 06:03
PGConf.eu Keynote Notes
@pramsey
pramsey / postgis-gis.md
Last active October 23, 2018 21:32
Carto Cosmos PostGIS && GIS Talk Notes

PostGIS && GIS

cdb-manager

A simple browser-based terminal for running SQL against Carto using the SQL API

  • http://github.com/cartodb/cdb-manager
  • git clone git@github.com:CartoDB/cdb-manager.git
  • When you're done cloning, enter the directory and run ./httpserv.py
  • Point your browser at http://locahost:8000
@pramsey
pramsey / both_geoms.vrt
Created June 18, 2018 17:55
VRT file to write both 'the_geom' and 'the_geom_webmercator' columns
<?xml version="1.0"?>
<OGRVRTDataSource>
<OGRVRTWarpedLayer>
<OGRVRTLayer name="cartogeom">
<SrcDataSource>cartogeom.csv</SrcDataSource>
<GeometryField name="the_geom" encoding="PointFromColumns" x="longitude" y="latitude">
<GeometryType>wkbPoint</GeometryType>
<SRS>EPSG:4326</SRS>
</GeometryField>
<GeometryField name="the_geom_webmercator" encoding="PointFromColumns" x="longitude" y="latitude">
import sys
import os
import gzip
import random
import md5
from carto.auth import APIKeyAuthClient
from carto.sql import SQLClient
import requests
import hashlib
@pramsey
pramsey / index.md
Last active April 13, 2018 12:50
SQL API COPY

So, it looks like COPY support will have to be divided into two parts, /copyfrom and /copyto, which is fine. They are both interesting, in that since the idea is to support scaling, the implementations absolutely must stream, rather than taking files or holding data in memory.

The parts needed are

The parts do in fact all fit together and work, as can been seen in this small proof-of-concept:

@pramsey
pramsey / rect_node_distance.sql
Created February 22, 2018 19:40
Performance Tests on Distance
-- Large primary geometry
select st_distance(e.geom, v.geom)
from ed_2017 e, va_ply_17 v
where e.ed_abbrev = 'KLA' and v.ed_abbrev != 'KLA';
-- 25s
select _ST_DistanceRectTree(e.geom, v.geom)
from ed_2017 e, va_ply_17 v
where e.ed_abbrev = 'KLA' and v.ed_abbrev != 'KLA';