DataQuery

public struct DataQuery

At first request, the whole data according to SkyPath.dataQuery is fetched.

Then only the new data that appeared (delta) is fetched to save network traffic. When cached data expires or a delta can’t be received, the whole fresh data will be received again.

There are thousands of turbulence reports around the globe. To reduce network traffic usage and keep only data that is currently needed the data fetch is separated into the different types controlled by the SkyPath.dataQuery object that is set initially to default values and can be updated at any time.

All of the below are optional to set but recommended due to your specific flow.

After updating SkyPath.dataQuery in any way, the check, if need to fetch new data, will be made. And if the change requires a new server fetch, the server request will be made immediately. No need to call SkyPath.fetchData(refresh:).

You can update data query at any time and in both ways by setting a property only or a whole object.

SkyPath.shared.dataQuery.polygon = polygon
SkyPath.shared.dataQuery = DataQuery(polygon: polygon)
  • Set it if you need more than just turbulence data.

    By default, it’s turbulence only, and only turbulence data is fetched from the server.

    Declaration

    Swift

    public var types: DataTypeOptions
  • It controls what data will be fetched inside the viewport if set.

    Used to disable fetching some data type on low map zoom to not load too much data for huge area.

    Optional. By default it fetches types.

    Declaration

    Swift

    public var viewportTypes: DataTypeOptions
  • By default, all severities of turbulence will be fetched.

    But you can provide a list of severities to fetch from the server if don’t need other at all.

    Declaration

    Swift

    public var sevs: [TurbulenceSeverity]
  • Polygon is a geo-fence area to fetch data inside only.

    The route corridor is a good example. Route line coordinates can be used to create a polygon that includes the route with a width distance. It is not recommended to set a worldwide polygon, use global turbulence polygons for it instead.

    It is fetched separately from other data types and as fast as possible. The data fetched for the polygon will be stored on disk and accessible offline.

    Should be a closed ring and have at least 4 and max 250 coordinates with the last equal to the first, otherwise SkyPath.didFailToFetchNewData will be called with an error. Simplify the polygon with enough tolerance.

    To make a route corridor and simplification of the polygon you can use provided Array<CLLocationCoordinate2D>.buffer(widthNM:simplify:tolerance:) and Array<CLLocationCoordinate2D>.simplify(tolerance:) methods from the SDK like the following:

    dataQuery.polygon = polygon.buffer(widthNM: 100)
    

    Optional.

    Declaration

    Swift

    public var polygon: [CLLocationCoordinate2D]?
  • A viewport is a polygon of a visible map area in the app to fetch the right data when it’s needed.

    Please keep in mind, that the SDK will try to fetch the data for the viewport as soon as possible after updating SkyPath.shared.dataQuery.viewport. So to save network traffic consider updating viewport when it’s needed.

    A good place could be when the pilot moved the map manually, released the finger and the map stopped moving after animation. Or when the focused map area is moved by code far from the previously focused area.

    The data fetched for the viewport will be stored in memory only and accessible offline until app relaunch.

    The previous viewport data is replaced with new viewport data.

    The simplest viewport polygon would be a currently visible rectangle on the map like [NorthWest, NorthEast, SouthEast, SouthWest, NorthWest]. For a more complex polygon, the following rules are applied.

    Should be a closed ring and have at least 4 and max 250 coordinates with the last equal to the first, otherwise SkyPath.didFailToFetchNewData will be called with an error. Simplify the polygon with enough tolerance.

    You can use provided Array<CLLocationCoordinate2D>.simplify(tolerance:) method from the SDK to siimplify the complex viewport polygon.

    Optional.

    Declaration

    Swift

    public var viewport: [CLLocationCoordinate2D]?
  • If true turbulence polygons will be fetched worldwide, otherwise, if polygon is set - only inside the polygon.

    Declaration

    Swift

    public var globalEnabled: Bool
  • A planet-wide aggregated turbulence area polygons as a GeoJSON string.

    Used to show turbulence areas worldwide without fetching too much data. DataQuery.types should have .turbulencePolygons to fetch it.

    The data fetched for the global polygons will be stored on disk and accessible offline.

    Turbulence polygons are generated per time history separately and by default only selected time history is fetched for polygons. To enable fetching polygons for all time histories up to selected set a corresponding flag. For example, if set to fetch 4h, then to have polygons available offline for 0.5h, 1h, 2h, and 4h you need to set this flag to true.

    Default is false.

    Declaration

    Swift

    public var globalTurbulencePolygonsUpToEnabled: Bool
  • An altitude range to query. Supported only in specific data types.

    Should be round to a thousand feet. The default is 0…52000. Measured in feet.

    Declaration

    Swift

    public var altRange: ClosedRange<Double>?
  • A route line coordinates.

    Should be used in conjunction with widthAround. Route corridor will be built based on route and routeWidth. Should be a great circle route coordinates already, not just waypoints.

    Optional.

    Declaration

    Swift

    public var route: [CLLocationCoordinate2D]?
  • Width of the route corridor.

    A distance from the left to the right edge of the corridor around the route.

    Measured in nautical miles (NM). Optional.

    Declaration

    Swift

    public var routeWidth: Double?
  • Default initializer.

    Declaration

    Swift

    public init(types: DataTypeOptions = .turbulence,
                sevs: [TurbulenceSeverity] = TurbulenceSeverity.allCases,
                polygon: [CLLocationCoordinate2D]? = nil)

    Parameters

    types

    The types of data to fetch from the server. The default is light.

    sevs

    The severities to fetch from the server. Default is all.

    polygon

    See polygon for more details. The default is nil.