Skip to content

Instantly share code, notes, and snippets.

View mvexel's full-sized avatar

Martijn van Exel mvexel

View GitHub Profile
@mvexel
mvexel / pip-install-osmium.txt
Created August 20, 2018 21:47
pip-install-osmium
pip
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mvexel
mvexel / get_users_in_area.py
Created April 6, 2018 19:00
Get unique OSM contributors for a named area
#!/usr/bin/env python3
import overpass
area_name = "Kanab"
query = """area[name="{}"]->.slc;(node(area.slc);<;);""".format(area_name)
users = {"ids": [], "usernames": []}
api = overpass.API(debug=False)
@mvexel
mvexel / StringSearch.java
Last active November 18, 2017 23:46
StringSearch
public class StringSearch {
public static void main(String[] args) {
// Initialize a new String
String myString = "Thanksgiving Day";
System.out.println("Our string is: " + myString);
// Now, get the 3rd letter in this string.
// Remember that indexes are zero based,
// so the third character has index 2, not 3.
@mvexel
mvexel / query-states-geojson.sql
Created October 18, 2017 16:11
query on a TIGER states table (Imported from Census SHAPE using shp2pgsql) to generate GeoJSON for each that osmium will understand.
COPY (
SELECT name, jsonb_build_object(
'type', 'Feature',
'id', gid,
'geometry', ST_AsGeoJSON(geom)::jsonb,
'properties', to_jsonb(row) - 'gid' - 'geom')
FROM (SELECT * FROM cb_2016_us_state_500k) row)
TO '/Users/martijnv/osm/planet/states.tsv';
@mvexel
mvexel / gist:5273c69d6b58587b5004e0a53ae34e75
Created October 18, 2017 16:10
osmium command to process N-America history into states using config file (see other gist)
osmium extract -H --overwrite -c osmium-config.json north-america.osh.pbf
@mvexel
mvexel / osmium-config.json
Created October 18, 2017 16:09
osmium config file to extract state history PBFs
{
"extracts": [
{
"description": "Full history PBF of Alabama",
"output": "Alabama.osh.pbf",
"output_format": "pbf",
"polygon": {
"file_name": "Alabama.geojson",
"file_type": "geojson"
}
@mvexel
mvexel / states.tsv
Created October 18, 2017 16:08
GeoJSON of all states (wrapped as Features this time with all TIGER attributes as properties)
We can't make this file beautiful and searchable because it's too large.
Alabama {"id": 1, "type": "Feature", "geometry": {"type": "MultiPolygon", "coordinates": [[[[-88.053375, 30.506987], [-88.051088, 30.508857], [-88.045647, 30.513306], [-88.041966, 30.517376], [-88.03867, 30.520405], [-88.035099, 30.521967], [-88.032407, 30.521447], [-88.029165, 30.519648], [-88.026222, 30.516609], [-88.023506, 30.492573], [-88.02433, 30.490774], [-88.026748, 30.491105], [-88.045043, 30.501189], [-88.052349, 30.505591], [-88.053375, 30.506987]]], [[[-88.211209, 30.322249], [-88.209999, 30.323199], [-88.209559, 30.322202], [-88.208954, 30.320445], [-88.208073, 30.319543], [-88.208733, 30.318878], [-88.209559, 30.31902], [-88.210824, 30.320777], [-88.211209, 30.322249]]], [[[-88.22512, 30.321802], [-88.221281, 30.322233], [-88.218694, 30.321903], [-88.221031, 30.32039], [-88.224653, 30.319886], [-88.226522, 30.320793], [-88.22512, 30.321802]]], [[[-88.264659, 30.335541], [-88.263674, 30.336335], [-88.261506, 30.335485], [-88.260061, 30.336449], [-88.259141, 30.337129], [-88.259141, 30.339], [-88
@mvexel
mvexel / states.txt
Created October 18, 2017 15:08
US state boundaries in geojson format
This file has been truncated, but you can view the full file.
Alabama {"type":"MultiPolygon","coordinates":[[[[-88.053375,30.506987],[-88.051088,30.508857],[-88.045647,30.513306],[-88.041966,30.517376],[-88.03867,30.520405],[-88.035099,30.521967],[-88.032407,30.521447],[-88.029165,30.519648],[-88.026222,30.516609],[-88.023506,30.492573],[-88.02433,30.490774],[-88.026748,30.491105],[-88.045043,30.501189],[-88.052349,30.505591],[-88.053375,30.506987]]],[[[-88.211209,30.322249],[-88.209999,30.323199],[-88.209559,30.322202],[-88.208954,30.320445],[-88.208073,30.319543],[-88.208733,30.318878],[-88.209559,30.31902],[-88.210824,30.320777],[-88.211209,30.322249]]],[[[-88.22512,30.321802],[-88.221281,30.322233],[-88.218694,30.321903],[-88.221031,30.32039],[-88.224653,30.319886],[-88.226522,30.320793],[-88.22512,30.321802]]],[[[-88.264659,30.335541],[-88.263674,30.336335],[-88.261506,30.335485],[-88.260061,30.336449],[-88.259141,30.337129],[-88.259141,30.339],[-88.258418,30.340417],[-88.257827,30.342742],[-88.257762,30.344329],[-88.259732,30.345633],[-88.262097,30.346541],[-88.26
@mvexel
mvexel / how_to_count.md
Last active October 17, 2017 22:06
how to generate a time series of object counts from an OSM history planet.

First, get your history extract at Geofabrik. Every region they define has an osh.pbf file.

Then, fork this gist and replace utah with the region name. Run it.

You end up with a bunch of files:

...
-rw-r--r--    1 martijnv    25M Oct 17 15:48 utah-20100101.osm.pbf
-rw-r--r--    1 martijnv    25M Oct 17 15:48 utah-20100201.osm.pbf