Skip to content

Instantly share code, notes, and snippets.

View geobabbler's full-sized avatar
💭
Working

William Dollins geobabbler

💭
Working
View GitHub Profile
{ type: 'Feature',
geometry: { type: 'Point', coordinates: [ -76.6955, 38.3754 ] },
properties:
{ message: 'insert',
schema: 'public',
table: 'simple_table',
id: '12' } }
---------------------------------
{"type":"Feature","geometry":{"type":"Point","coordinates":[-76.6955,38.3754]},"properties":{"message":"insert","schema":"public","table":"simple_table","id":"12"}}
var PGPubsub = require('pg-pubsub');
var pubsubInstance = new PGPubsub('postgres://postgres:user@localhost:5432/database');
pubsubInstance.addChannel('actions', function (channelPayload) {
console.log(channelPayload);
console.log('---------------------------------');
console.log(JSON.stringify(channelPayload));
});
INSERT INTO simple_table(message, shape)
VALUES('test message', ST_GeomFromText('POINT(-76.6955 38.3754)', 4326));
CREATE TRIGGER sample_table_trigger
AFTER INSERT
ON public.simple_table
FOR EACH ROW
EXECUTE PROCEDURE public.sample_notify();
CREATE TABLE public.simple_table
(
id integer NOT NULL DEFAULT nextval('simple_table_id_seq'::regclass),
message text,
shape geometry(Point,4326),
CONSTRAINT pk_notify PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
CREATE OR REPLACE FUNCTION public.sample_notify()
RETURNS trigger AS
$BODY$
DECLARE
BEGIN
PERFORM pg_notify('actions', '{"type": "Feature", "geometry": ' ||
st_asgeojson(NEW.shape) ||
',"properties": {"message": "' ||
'insert' || '",' ||
'"schema": "' || TG_TABLE_SCHEMA || '",' ||
@geobabbler
geobabbler / mbmerge.bat
Last active June 24, 2016 13:27
Windows batch file to merge MBTiles database. Based on 'patch' (https://github.com/mapbox/mbutil/blob/master/patch)
REM based on 'patch' here: https://github.com/mapbox/mbutil/blob/master/patch
@ECHO OFF
REM goto CATCH
REM %1 = source database
REM %2 = destination database
echo PRAGMA journal_mode=PERSIST;PRAGMA page_size=80000;PRAGMA synchronous=OFF;ATTACH DATABASE '%1' AS source;REPLACE INTO map SELECT * FROM source.map;REPLACE INTO images SELECT * FROM source.images;REPLACE INTO grid_data SELECT * FROM source.grid_data; | "C:\spatialite3\bin\sqlite3.exe" %2%
GOTO FINALLY
:CATCH
echo there was an error
@geobabbler
geobabbler / d3_squares_example.js
Last active May 25, 2016 14:55
D3 squares example for blog post
d3.json(
"data/statistics.geojson",
function (json) {
//dimensions
var w = 980;
var h = 480;
//get the center of the data
var center = d3.geo.centroid(json);
var svg = d3.select("body").append("svg")
.attr("width", w)
SELECT name FROM sqlite_master
WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%'
UNION ALL
SELECT name FROM sqlite_temp_master
WHERE type IN ('table','view')
ORDER BY 1
BEGIN;
-- Generate ADMINISTRATIVE_BOUNDARY_C for PostGIS.
CREATE TABLE "ADMINISTRATIVE_BOUNDARY_C" (OID INTEGER PRIMARY KEY, "BEN" varchar(15) DEFAULT 'noInformation', "BST" integer DEFAULT -999999, "CAA" integer DEFAULT -999999, "DSP" integer DEFAULT -999999, "F_CODE" varchar(5) DEFAULT 'FA000' CHECK ("F_CODE" = 'FA000'), "FA003_BAL" integer DEFAULT -999999, "FUFI" varchar(254) DEFAULT 'noInformation', "FURL" text DEFAULT 'noInformation', "LSP" integer DEFAULT -999999, "LZN" double precision DEFAULT -999999.0, "MGL" integer DEFAULT -999999, "MGL2" integer DEFAULT -999999, "MGL3" integer DEFAULT -999999, "OTH" text DEFAULT 'noInformation', "RPC" integer DEFAULT -999999, "UFI" varchar(254) DEFAULT 'noInformation', "ZI002_UFI" varchar(254) DEFAULT 'A9593791-4AE9-4180-8E1E-9CB3D239DEE5', "ZI004_RCG" varchar(30) DEFAULT 'noInformation', "ZI005_FNAA" varchar(200) DEFAULT 'No Information', "ZI005_FNAB" varchar(200) DEFAULT 'No Information', "ZI005_GNTA" integer DEFAULT -999999, "ZI005_GNTB" integer DEFAULT -99999