Skip to main content
Version: Next

Get Data

Turbulence

SDK fetches data from the server and caches it locally automatically.

Use TurbulenceQuery to get filtered data as a GeoJSON string or as an array of objects. It will query locally cached data received previously. It blocks the current thread, so using a separate background thread is recommended.

do {
let result = try SkyPath.shared.turbulence(with: TurbulenceQuery()).get()
let geoJSON = result.geoJSON
// Show GeoJSON on the map
} catch {
print(error)
}

SkyPath.shared.dataHistoryTime determines the data history be fetched from the server. By default, it is .twoHours. So if it was not changed and query for .fourHours for example, there will be data only up to 2 hours because no more data was fetched from the server.

H3 resolution 5 is used by SkyPath for the turbulence reports area. Each turbulence report covers ~252.9 square km hexagon area (as per the H3 resolutions table) and 1000 feet of altitude. Each hexagon is connected to the other so this allows for covering the area better. So one turbulence report covers for example FL370..<FL380 or FL380..<FL390.

In order to get reports for specific tiles use TurbulenceQuery.tiles property. It accepts h3 or h3-alt format. Such tile id can be taken from TurbulenceItem.tile property which is a Tile object with the corresponding properties Tile.key and Tile.keyByCoord or Tile.h3Hex.

GeoJSON vs Items

TurbulenceQuery.resultOptions determines in which format returns the queried data.

  • items will provide an array of TurbulenceItem objects. It can be used for postprocessing and converting for rendering in a custom way.

  • geoJSON will generate a GeoJSON string to visualize on the map. It has a geometry polygon to draw the hexagons and extra properties for each one like severity and others. Please note that the properties fields could not match the TurbulenceItem fields as it's not equivalent objects.

  • geoJSONData is the same as geoJSON just as Data not as String.

note

The GeoJSON string is not intended to provide all the details about each report. It is intended to have minimal details to visualize on the map. TurbulenceItem can be used to get all details per each report.

Report Details

TurbulenceItem has all the details about the report.

For example, when need to show report details by tapping on the report on the map, the GeoJSON feature properties could not have all the needed values. Also, it could be hard to find all reports in the tapped area using GeoJSON only.

Here is the flow:

  1. When tapping the GeoJSON feature on the map, take the h3Hex string from the properties. It's the H3 index of the tapped hexagon.

  2. Query data from the SDK in the tapped hexagon.

do {
let query = TurbulenceQuery(resultOptions: .items, aggregate: false, tiles: [h3Hex])
let result = try SkyPath.shared.turbulence(with: query).get()
// Process `result.items`
} catch {
print(error)
}

Turbulence Polygons

Use TurbulencePolygonsQuery to get filtered data as a GeoJSON string. It will query locally cached data received previously. It blocks the current thread, so using a separate background thread is recommended.

let query = TurbulencePolygonsQuery(altRange: 0...52_000)
do {
let result = try SkyPath.shared.turbulencePolygons(with: query).get()
let geoJSON = result.geoJSON
// Show GeoJSON on the map
} catch {
print(error)
}

SkyPath.shared.dataHistoryTime determines the data history be fetched from the server. By default it is .twoHours. So if it was not changed there are no polygons data for .fourHours for example. This is because polygons data is generated per each history time separately, so SDK needs to have it cached to return.

When Offline

When offline there could be situations where the global turbulence polygons have been fetched but the turbulence reports are not for the specific viewport when moving the map. It is possible to use turbulence polygons data instead. Set TurbulenceQuery.usePolygonsEnabled to use polygons data to return data in a query instead of having empty data.