Skip to content

Commit

Permalink
Feedback alterations
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitchelbourne committed Apr 5, 2022
1 parent 0871ab3 commit acc2de1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

The multiline.geojson file contains the multiline for the entire path in the dataset, and can be uploaded as a layer for a custom style on mapbox. This was done to shorten the URL requests as there is an 8000 character limit. You can create your own mapbox style, the alter the geojsonrequest script and replace the "mitchelbourne/cl1......" with your own style.

Packages used: geojson, json, os, requests, urllib,
Packages used: geojson, json, os, requests, urllib, argparse

1. Paste telemetry data into the data.json file
2. Run the generategeojson python file to create the geojson files from the data set.
Expand Down
Empty file removed data.json
Empty file.
17 changes: 14 additions & 3 deletions generategeojson.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import json
from geojson import Point
import os
import argparse

parser = argparse.ArgumentParser()
files_dir = 'geojson-files'

parser.add_argument("-f", "--file", help="Telemetry Filename Including .json")
args = parser.parse_args()

# Find the samples value in dict
def find_by_key(data, target):
Expand All @@ -11,7 +18,11 @@ def find_by_key(data, target):
yield value

def main():
with open('./data.json') as json_file:
if not args.file:
print("Please provide the telemetry filename (in base directory) using the -f flag, e.g. python3 generategeojson.py -f mytelemetry.json")
exit()

with open(f'./{args.file}') as json_file:
data = json.load(json_file)
linestring = []

Expand All @@ -24,12 +35,12 @@ def main():
)

try:
os.mkdir("./files")
os.mkdir(f"./{files_dir}")
except OSError as error:
print(error)

for index, x in enumerate(data):
f = open(f"./files/{index}.geojson", "x")
f = open(f"./{files_dir}/{index:06}.geojson", "x")

filedata = f'{{"type": "Point","coordinates": {[x["GPS (Lat.) [deg]"], x["GPS (Long.) [deg]"]]}}}'
f.write(filedata)
Expand Down
12 changes: 7 additions & 5 deletions geojsonrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
import urllib.parse
import os

directory = "./files"
files_dir = 'geojson-files'
images_dir = 'mapbox-images'
# Paste in an access token here
access_token = ""

def main():
index = 0
try:
os.mkdir("./images")
os.mkdir(f"./{images_dir}")
except OSError as error:
print(error)

for filename in os.listdir(directory):
with open(f'{directory}/{index}.geojson') as json_file:
for filename in os.listdir(files_dir):
with open(f'./{files_dir}/{index:06}.geojson') as json_file:
data = json.load(json_file)
xcoord = data["coordinates"][0]
ycoord = data["coordinates"][1]
Expand All @@ -25,9 +26,10 @@ def main():
r = requests.get(f"https://api.mapbox.com/styles/v1/mitchelbourne/cl1jw3qpv005014q4s04zfzea/static/geojson({encodeddata})/{xcoord}, {ycoord},17/500x300?access_token={access_token}")

if r.status_code == 200:
with open(f"./images/{index}.png", 'wb') as f:
with open(f"./{images_dir}/{index:06}.png", 'wb') as f:
f.write(r.content)
f.close()
print(f"Fetched image: {index}")
else:
print("Failed to fetch image with status code: ", r.status_code)
index += 1
Expand Down
1 change: 1 addition & 0 deletions mytelemetry.json

Large diffs are not rendered by default.

0 comments on commit acc2de1

Please sign in to comment.