Skip to content

Instantly share code, notes, and snippets.

@andrewbt
Created January 19, 2021 05:24
Show Gist options
  • Save andrewbt/95339d186a3a5a04d997daa8ce603040 to your computer and use it in GitHub Desktop.
Save andrewbt/95339d186a3a5a04d997daa8ce603040 to your computer and use it in GitHub Desktop.
Converts regular JSON to GeoJSON for Arlington County bike counters
#! usr/bin/env python
from sys import argv
from os.path import exists
import simplejson as json
#script, in_file, out_file = argv
# Step 1: get XML from http://webservices.commuterpage.com/counters.cfc?wsdl&method=GetAllCounters
# Step 2: Convert XML to JSON with https://www.freeformatter.com/xml-to-json-converter.html
# Step 3: Run this script on the JSON file to convert to GeoJSON!
data = json.load(open("jsonfile.json")) #open(in_file))
geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry" : {
"type": "Point",
"coordinates": [float(d["longitude"]), float(d["latitude"])],
},
"properties" : d,
} for d in data]
}
output = open("mygeojson.geojson", 'w')
json.dump(geojson, output)
print(geojson)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment