Skip to content

Instantly share code, notes, and snippets.

@busybus
busybus / osmdownload.py
Last active April 22, 2019 20:31
Download OpenStreetMap by bounding box
# RA, 2019-01-15
# Download an OpenStreetMap file based on a lat-lon bounding box
# License: CC0 -- "No rights reserved"
# IMPORTS:
import os
import json
import inspect
@busybus
busybus / mapbox.py
Created January 16, 2019 04:29
Download a rendered map from Mapbox based on a bounding box
# RA, 2019-01-16
# Download a rendered map from Mapbox based on a bounding box
# License: CC0 -- no rights reserved
import io
import urllib.request
from PIL import Image
from math import pi, log, tan, exp, atan, log2, floor
# Convert geographical coordinates to pixels
@busybus
busybus / KHH122-1.json
Created January 20, 2019 12:39
GPS measurements of Kaohsiung bus route 88 from 2018-11-05 to 2018-11-11
This file has been truncated, but you can view the full file.
[
{
"PlateNumb": "698-FP",
"SubRouteUID": "KHH122",
"Direction": 1,
"Speed": [
0.0,
0.0,
16.0,
0.0,
@busybus
busybus / KHH82-1.json
Created January 20, 2019 13:06
GPS measurements of Kaohsiung bus route 紅21 from 2018-11-05 to 2018-11-11
This file has been truncated, but you can view the full file.
[
{
"PlateNumb": "551-FP",
"SubRouteUID": "KHH82",
"Direction": 1,
"Speed": [
27.0,
0.0,
35.0,
0.0,
@busybus
busybus / zipjson_part1.py
Created January 22, 2019 12:25
Compress/decompress JSON (1)
import zlib, json, base64
ZIPJSON_KEY = 'base64(zip(o))'
def json_zip(j):
j = {
ZIPJSON_KEY: base64.b64encode(
zlib.compress(
json.dumps(j).encode('utf-8')
@busybus
busybus / zipjson_part2.py
Created January 22, 2019 12:27
Compress/decompress JSON (2)
import zlib, json, base64
ZIPJSON_KEY = 'base64(zip(o))'
def json_unzip(j, insist=True):
try:
assert (j[ZIPJSON_KEY])
assert (set(j.keys()) == {ZIPJSON_KEY})
except:
if insist:
@busybus
busybus / zipjson.py
Created January 22, 2019 12:30
Compress/decompress JSON with zip
# RA, 2019-01-22
# Compress and decompress a JSON object
# License: CC0 -- "No rights reserved"
# For zlib license, see https://docs.python.org/3/license.html
import zlib
import json, base64
@busybus
busybus / real-time-gps-example.json
Created January 22, 2019 12:33
Real-time bus GPS measurement example from Taipei
{
"PlateNumb": "001-FQ",
"OperatorID": "100",
"RouteUID": "TPE10181",
"RouteID": "10181",
"RouteName": {
"Zh_tw": "205",
"En": "205"
},
"SubRouteUID": "TPE101810",
# RA, 2019-01-15
# Download an OpenStreetMap file based on a lat-lon bounding box
# License: CC0 -- "No rights reserved"
# IMPORTS:
import os
import json
import inspect
import logging
import datetime as dt
import urllib.request, urllib.error