mirror of
https://github.com/projecthorus/sondehub-infra.git
synced 2025-03-22 03:45:18 +00:00
add kml output
This commit is contained in:
parent
6a62101fad
commit
1c1173ccf4
@ -274,7 +274,7 @@ def get_telem_full(event, context):
|
||||
lt = requested_time + timedelta(0, 1)
|
||||
gte = requested_time - timedelta(0, last)
|
||||
|
||||
path = f"ham-telm-{lt.year:2}-{lt.month:02},telm-{gte.year:2}-{gte.month:02}/_search"
|
||||
path = f"ham-telm-*/_search"
|
||||
payload = {
|
||||
"timeout": "30s",
|
||||
"size": 10000,
|
||||
@ -370,6 +370,70 @@ def get_telem_full(event, context):
|
||||
fc.writeheader()
|
||||
fc.writerows(data)
|
||||
data = csv_output.getvalue()
|
||||
elif (
|
||||
"queryStringParameters" in event
|
||||
and "format" in event["queryStringParameters"]
|
||||
and event["queryStringParameters"]['format'] == "kml"
|
||||
):
|
||||
content_type = "application/vnd.google-earth.kml+xml"
|
||||
|
||||
# Extract some basic flight info for use in KML Metadata
|
||||
callsign = str(event["pathParameters"]["payload_callsign"])
|
||||
start_datetime = gte.isoformat()
|
||||
|
||||
# Only get unique date/time data.
|
||||
# This results in a much shorter dictionary.
|
||||
_temp_data = {}
|
||||
for _telem in data:
|
||||
_temp_data[_telem['datetime']] = f"{float(_telem['lon']):.6f},{float(_telem['lat']):.6f},{float(_telem['alt']):.1f}\n"
|
||||
|
||||
# For a KML output, the data *must* be sorted, else the KML LineString becomes a complete mess.
|
||||
# Get the keys from the dictionary generated above, and sort them.
|
||||
data_keys = list(_temp_data.keys())
|
||||
data_keys.sort()
|
||||
|
||||
# Now generate the LineString data (lon,lat,alt)
|
||||
# This could possibly done with a .join, but I suspect that wont be much more efficient.
|
||||
kml_coords = ""
|
||||
for _key in data_keys:
|
||||
kml_coords += _temp_data[_key]
|
||||
|
||||
# Generate the output KML.
|
||||
# This is probably the simplest way of handling this without bringing in
|
||||
# any other libraries.
|
||||
kml_out = f"""
|
||||
<kml:Document xmlns:kml="http://www.opengis.net/kml/2.2">
|
||||
<kml:visibility>1</kml:visibility>
|
||||
<kml:Folder id="{callsign}">
|
||||
<kml:name>{start_datetime} {callsign}</kml:name>
|
||||
<kml:description>Flight Path</kml:description>
|
||||
<kml:visibility>1</kml:visibility>
|
||||
<kml:Placemark id="Flight Path ID">
|
||||
<kml:name>{start_datetime} {callsign}</kml:name>
|
||||
<kml:visibility>1</kml:visibility>
|
||||
<kml:Style><kml:LineStyle>
|
||||
<kml:color>aaffffff</kml:color>
|
||||
<kml:width>2.0</kml:width>
|
||||
</kml:LineStyle>
|
||||
<kml:PolyStyle>
|
||||
<kml:color>20000000</kml:color>
|
||||
<kml:fill>1</kml:fill>
|
||||
<kml:outline>1</kml:outline>
|
||||
</kml:PolyStyle></kml:Style>
|
||||
<kml:LineString>
|
||||
<kml:extrude>1</kml:extrude>
|
||||
<kml:altitudeMode>absolute</kml:altitudeMode>
|
||||
<kml:coordinates>
|
||||
{kml_coords}
|
||||
</kml:coordinates>
|
||||
</kml:LineString>
|
||||
</kml:Placemark>
|
||||
</kml:Folder>
|
||||
</kml:Document>
|
||||
"""
|
||||
|
||||
# Finally replace the data with the kml data
|
||||
data = kml_out
|
||||
else:
|
||||
data = json.dumps(data)
|
||||
|
||||
|
@ -6,12 +6,12 @@ import zlib
|
||||
response = get_telem_full(
|
||||
{
|
||||
"pathParameters": {
|
||||
"payload_callsign" : "HORUS-V2"
|
||||
"payload_callsign" : "HORUSBINARY"
|
||||
},
|
||||
"queryStringParameters":{
|
||||
"last": "3600",
|
||||
"datetime": "2022-05-07T04:18:10.000000Z",
|
||||
"format": "csv"
|
||||
"last": "10800",
|
||||
"datetime": "2022-06-26T08:30:00.000001Z",
|
||||
"format": "kml"
|
||||
}
|
||||
}, {})
|
||||
print(len(response['body']))
|
||||
@ -19,4 +19,5 @@ compressed = base64.b64decode(response['body'])
|
||||
|
||||
decompressed = (zlib.decompress(compressed, 16 + zlib.MAX_WBITS))
|
||||
#print(json.loads(decompressed))
|
||||
print(decompressed.decode().splitlines()[:5])
|
||||
#print(decompressed.decode().splitlines()[:5])
|
||||
print(decompressed.decode())
|
@ -102,7 +102,7 @@ paths:
|
||||
type: string
|
||||
- in: query
|
||||
name: format
|
||||
description: "If set to csv will provide a CSV of the results rather than JSON"
|
||||
description: "Valid options are csv, kml or json"
|
||||
required: false
|
||||
type: string
|
||||
format: string
|
||||
|
Loading…
x
Reference in New Issue
Block a user