Skip to content

Instantly share code, notes, and snippets.

View zerebubuth's full-sized avatar

Matt Amos zerebubuth

View GitHub Profile
@zerebubuth
zerebubuth / update.sh
Last active April 22, 2016 14:50
Simple script to load elements one-off into your local database. Export your database name as `$MZ_DATABASE` and run like `./update.sh <URL to OSM element>` from within the vector-datasource root.
#!/bin/bash
set -e
function die {
echo -e "ERROR: $@" 1>&2
exit 1
}
for prog in awk curl xsltproc osm2pgsql; do
@zerebubuth
zerebubuth / demo.cpp
Last active April 18, 2016 19:46
Playing around with the prime_server example.
#include "prime_server/prime_server.hpp"
#include "prime_server/http_protocol.hpp"
#include "prime_server/logging.hpp"
#include <boost/variant.hpp>
#include <thread>
struct http_server {
using work_function_t = prime_server::worker_t::work_function_t;
@zerebubuth
zerebubuth / test.py
Created March 10, 2016 14:53
Test program to transcode a GeoJSON tile into MVT using the mapbox_vector_tile library.
import json
from shapely.geometry import mapping, shape
import sys
from mapbox_vector_tile import encode
geojson = json.load(open(sys.argv[1]))
layers = []
for name, featurecollection in geojson.iteritems():
features = []
@zerebubuth
zerebubuth / foo.py
Created February 16, 2016 19:57
Simple GDAL/numpy that doesn't seem to work
from osgeo import gdal
import numpy as np
import sys
xsize = 266
ysize = 276
drv = gdal.GetDriverByName("MEM")
ds = drv.Create('', xsize, ysize, 1, gdal.GDT_Float32)
band = ds.GetRasterBand(1)
@zerebubuth
zerebubuth / migrate.sql
Last active December 15, 2015 20:28
v0.6.0 migration
BEGIN;
CREATE OR REPLACE FUNCTION mz_calculate_is_landuse(
landuse_val text, leisure_val text, natural_val text, highway_val text,
amenity_val text, aeroway_val text, tourism_val text, man_made_val text,
power_val text, boundary_val text)
RETURNS BOOLEAN AS $$
BEGIN
RETURN
landuse_val IN ('park', 'forest', 'residential', 'retail', 'commercial',
BEGIN;
CREATE OR REPLACE FUNCTION mz_calculate_poi_level(
aerialway_val text,
aeroway_val text,
amenity_val text,
barrier_val text,
craft_val text,
highway_val text,
historic_val text,
@zerebubuth
zerebubuth / migrate.sql
Created December 11, 2015 17:10
Migration for #382, adding piers to the roads layer.
BEGIN;
DROP FUNCTION IF EXISTS mz_calculate_road_level(text, text, text, text, text, text, text, text, geometry);
CREATE OR REPLACE FUNCTION mz_calculate_man_made_level(man_made_val text)
RETURNS SMALLINT AS $$
BEGIN
RETURN CASE
WHEN man_made_val IN ('pier') THEN 13
ELSE NULL
BEGIN;
-- IF YOU UPDATE THIS, PLEASE UPDATE mz_calculate_landuse_kind
-- BELOW!
CREATE OR REPLACE FUNCTION mz_calculate_is_landuse(
landuse_val text, leisure_val text, natural_val text, highway_val text,
amenity_val text, aeroway_val text, tourism_val text, man_made_val text,
power_val text, boundary_val text)
RETURNS BOOLEAN AS $$
BEGIN
{
"node_id": {
"id": 1118,
"level": 2,
"tile_id": 752471
},
"input_lon": 17.959406,
"node": {
"type": "street_intersection",
"traffic_signal": false,
@zerebubuth
zerebubuth / migrate.sql
Created December 10, 2015 13:34
Migration for #404 for toy shops. Note: this is supposed to be applied on top of the migration for #436, or needs to be de-duped.
BEGIN;
DROP FUNCTION IF EXISTS mz_calculate_poi_level(text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, way_area real);
CREATE OR REPLACE FUNCTION mz_calculate_poi_level(
aerialway_val text,
aeroway_val text,
amenity_val text,
barrier_val text,