-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* parse settings from variables.txt * avoid parsing same dict multiple times * use data instead of saving to thousands of files * add mapbox service with basic needed functions * update requirements and add main script file * update readme * adding better variables * fixing var names * Update README.md * restructure and simplify code * improve how settings are set * Update variables.txt * removing old files * Update .gitignore * fix some problems * updating mapbox permissions * adding some more mapbox permissions * Update README.md * fix image zoom level * Update README.md * adding some test cases * adding tests * more tests * fix get data by key in nested dict * allow maki in marker and ensure hex color format * change marker label default in description * always str colours * uncomment geojson generation line * ensure marker label doesn't have svg extension * make label optional * add line width to multiline style * Update variables.txt Co-authored-by: David G <[email protected]>
- Loading branch information
1 parent
65740b9
commit 05a9f77
Showing
23 changed files
with
484 additions
and
133 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import argparse | ||
from time import sleep | ||
|
||
from services.geojson_service import generate_images, get_data | ||
from services.mapbox_service import create_base_style | ||
from settings import MAPBOX_USER_STYLE | ||
|
||
parser = argparse.ArgumentParser() | ||
files_dir = "geojson-files" | ||
|
||
parser.add_argument("-f", "--file", help="Telemetry Filename Including .json") | ||
args = parser.parse_args() | ||
|
||
if not args.file: | ||
print( | ||
"Please provide the telemetry filename (in base directory) using the -f flag, e.g. python3 main.py -f telemetry.json" | ||
) | ||
exit() | ||
|
||
|
||
images_data = get_data(args.file) | ||
# override style recreation (to reuse one created previously, for example) | ||
if not MAPBOX_USER_STYLE: | ||
MAPBOX_USER_STYLE = create_base_style() | ||
# we wait some seconds just to allow the style to be available (sometimes fails for first few images otherwise) | ||
sleep(5) | ||
# call the image generator method | ||
generate_images(MAPBOX_USER_STYLE, images_data) |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
geojson==2.5.0 | ||
requests==2.27.1 | ||
urllib3==1.26.9 | ||
urllib3==1.26.9 | ||
mapbox==0.18.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import json | ||
import os | ||
import urllib.parse | ||
from multiprocessing.sharedctypes import Value | ||
|
||
import requests | ||
from settings import MAPBOX_KEY, MAPBOX_USERNAME | ||
|
||
from services.mapbox_service import generate_image | ||
|
||
files_dir = "geojson-files" | ||
images_dir = "mapbox-images" | ||
|
||
|
||
def generate_images(style, images_data): | ||
try: | ||
os.mkdir(f"./{images_dir}") | ||
except OSError as error: | ||
print(error) | ||
|
||
for index, data in enumerate(images_data): | ||
image = generate_image(data, style) | ||
|
||
if image: | ||
with open(f"./{images_dir}/{index:06}.png", "wb") as f: | ||
f.write(image) | ||
f.close() | ||
print(f"Fetched image: {index}") | ||
|
||
|
||
# Find the samples value in dict | ||
def find_by_key(data, target): | ||
if target in data.keys(): | ||
return data[target] | ||
for key, value in data.items(): | ||
if isinstance(value, dict): | ||
return find_by_key(value, target) | ||
|
||
|
||
def generate_multiline_geojson(data): | ||
multiline = [] | ||
filedata = "" | ||
|
||
for index, x in enumerate(data[1::2]): | ||
multiline.append( | ||
[[data[index][0], data[index][1]], [data[index + 1][0], data[index + 1][1]]] | ||
) | ||
|
||
filedata = f'{{"type": "FeatureCollection","features": [{{"type": "Feature","geometry": {{"type": "MultiLineString","coordinates": {multiline}}},"properties": {{"prop0": "value0"}}}}]}}' | ||
|
||
f = open(f"./multiline.geojson", "w") | ||
f.write(filedata) | ||
f.close() | ||
|
||
|
||
def get_data(file: str): | ||
with open(f"./{file}") as json_file: | ||
data = json.load(json_file) | ||
linestring = [] | ||
|
||
data = find_by_key(data, "GPS5").get("samples", []) | ||
|
||
for x in data: | ||
if "GPS (Lat.) [deg]" in x: | ||
linestring.append([x["GPS (Lat.) [deg]"], x["GPS (Long.) [deg]"]]) | ||
else: | ||
linestring.append([x["value"][1], x["value"][0]]) | ||
|
||
generate_multiline_geojson(linestring) | ||
return linestring |
Oops, something went wrong.