Created
January 19, 2021 05:24
-
-
Save andrewbt/95339d186a3a5a04d997daa8ce603040 to your computer and use it in GitHub Desktop.
Converts regular JSON to GeoJSON for Arlington County bike counters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! 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