AWFGeoPolygon

Objective-C

@interface AWFGeoPolygon : NSObject <NSCoding>

Swift

class AWFGeoPolygon : NSObject, NSCoding

An AWFGeoPolygon object manages a series of coordinates that define a region or polygon that is used when requesting data from the API or rendering API data on a map.

  • Returns the array of coordinates as instances of NSValue that comprises the polygon bounds.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) NSArray<NSValue *> *_Nonnull coordinates;

    Swift

    var coordinates: [NSValue] { get }
  • Returns an array of coordinate values that defines the polygon bounds. The value of this property is typically passed to overlay rendering methods when drawing the polygon on a map, such as MKPolyline or MKPolygon.

    Declaration

    Objective-C

    @property (nonatomic, readonly) CLLocationCoordinate2D *_Nonnull coords;

    Swift

    var coords: UnsafeMutablePointer<CLLocationCoordinate2D> { get }
  • Returns the bounding box that encloses the polygon.

    See

    AWFCoordinateRect

    Declaration

    Objective-C

    @property (nonatomic, readonly) int boundingBox;

    Swift

    var boundingBox: Int32 { get }
  • Returns the coordinate at the midpoint of the overall polygon bounds.

    Declaration

    Objective-C

    @property (nonatomic, readonly) CLLocationCoordinate2D centerCoordinate;

    Swift

    var centerCoordinate: CLLocationCoordinate2D { get }
  • Calculates the centroid of the polygon, which is the average of the coordinate sums from all coordinates.

    Declaration

    Objective-C

    @property (nonatomic, readonly) CLLocationCoordinate2D centroid;

    Swift

    var centroid: CLLocationCoordinate2D { get }
  • Calculates the approximate area of the polygon when the polygon is closed in square meters.

    This method is only an approximation and can be inaccurate for large regions because the Earth’s curvature is not accounted for in the area calculation.

    Declaration

    Objective-C

    @property (nonatomic, readonly) CGFloat area;

    Swift

    var area: CGFloat { get }
  • An array of AWFGeoPolygon instances that are cut out from the polygon when rendering on a map.

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) NSArray<AWFGeoPolygon *> *interiorPolygons;

    Swift

    var interiorPolygons: [AWFGeoPolygon]? { get set }
  • Weather model object associated with the geo polygon.

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) AWFWeatherObject *modelObject;

    Swift

    var modelObject: AWFWeatherObject? { get set }
  • Initializes and returns a polygon object defined by the array of coordinates and their order.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithArrayOfCoordinates:
        (nonnull NSArray<NSValue *> *)coordinates;

    Swift

    init(arrayOfCoordinates coordinates: [NSValue])

    Parameters

    coordinates

    The array of CLLocationCoordinate2D values.

    Return Value

    The initialized polygon instance.

  • Initializes and returns a polygon object defined by an array of coordinate values.

    Each item in the array should be an array that provides the latitude and longitude values, e.g. @[@(47.61), @(-122.33)].

    Declaration

    Objective-C

    - (nonnull instancetype)initWithArrayOfPoints:
        (nonnull NSArray<AWFGeoPolygonCoordValue> *)points;

    Swift

    init(arrayOfPoints points: [[NSNumber]])

    Parameters

    points

    The array of latitude, longitude arrays.

    Return Value

    The initialized polygon instance.

  • Initializes and returns a polygon object defined by an array of coordinate values.

    Each item in the array should be an array that provides the latitude and longitude values, e.g. @[@(47.61), @(-122.33)].

    Declaration

    Objective-C

    - (nonnull instancetype)initWithArrayOfPoints:
                                (nonnull NSArray<AWFGeoPolygonCoordValue> *)points
                            startingWithLongitude:(BOOL)startsWithLongitude;

    Swift

    init(arrayOfPoints points: [[NSNumber]], startingWithLongitude startsWithLongitude: Bool)

    Parameters

    points

    The array of coordinate values containing the latitude and longitude values

    startsWithLongitude

    Whether or not the first value in each coordinate array represents the longitude value. Default is NO.

    Return Value

    The initialized polygon instance

  • Initializes and returns a polygon object defined by the polygon string.

    The provided string should be a series of latitude and longitude coordinate points, e.g. ‘@“30.844648845745,-95.62972672269,30.473950476293,-95.489974064209,…”’.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithPolygonString:(nonnull NSString *)polygonString;

    Swift

    init(polygonString: String)

    Parameters

    polygonString

    The polygon string that provides the list of latitude and longitude coordinates.

    Return Value

    The initialized polygon instance.

Managing Coordinates

  • Appends a new coordinate value to the end of the existing polygon. If no coordinates already exist, the specified coordinate will be the starting coordinate point.

    Declaration

    Objective-C

    - (void)addCoordinate:(CLLocationCoordinate2D)coordinate;

    Swift

    func addCoordinate(_ coordinate: CLLocationCoordinate2D)

    Parameters

    coordinate

    The coordinate to add.

  • Inserts a new coordinate value at a specific index within the array of coordinates that defines the polygon. If the specified index is greater than the total number of coordinates, it will be appended to the end of the coordinates array.

    Declaration

    Objective-C

    - (void)insertCoordinate:(CLLocationCoordinate2D)coordinate
                     atIndex:(NSUInteger)index;

    Swift

    func insertCoordinate(_ coordinate: CLLocationCoordinate2D, at index: UInt)

    Parameters

    coordinate

    The coordinate to insert.

    index

    The index in which to insert the coordinate.

  • Removes all coordinate values from the polygon.

    Declaration

    Objective-C

    - (void)removeAllCoordinates;

    Swift

    func removeAllCoordinates()
  • Returns a string representation of the polygon as a series of latitude and longitude values, e.g. ‘@“30.844648845745,-95.62972672269,30.473950476293,-95.489974064209,…”’.

    Declaration

    Objective-C

    - (nonnull NSString *)polygonAsString;

    Swift

    func polygonAsString() -> String
  • Determines whether or not the specified coordinate falls within the polygon’s bounds.

    Declaration

    Objective-C

    - (BOOL)containsCoordinate:(CLLocationCoordinate2D)coord;

    Swift

    func containsCoordinate(_ coord: CLLocationCoordinate2D) -> Bool

    Parameters

    coord

    The coordinate to determine if it’s within the polygon.

    Return Value

    YES if the polygon contains the coordinate, otherwise NO.

  • Returns an AWFGeoPolygon instance generated from the specified GeoJSON dictionary data.

    Note that the provided GeoJSON data must follow the GeoJSON spec: http://geojson.org/geojson-spec.html#polygon

    Declaration

    Objective-C

    + (nullable AWFGeoPolygon *)polygonFromGeoJSON:(nonnull NSDictionary *)geoJSON;

    Swift

    /*not inherited*/ init?(fromGeoJSON geoJSON: [AnyHashable : Any])

    Parameters

    geoJSON

    The GeoJSON data to generate polygon instances from

    Return Value

    An array of polygon instances based on the GeoJSON data

  • Returns an array of AWFGeoPolygon instances generated from the specified GeoJSON dictionary data.

    Note that the provided GeoJSON data must follow the GeoJSON spec: http://geojson.org/geojson-spec.html#polygon

    Declaration

    Objective-C

    + (nullable NSArray<AWFGeoPolygon *> *)polygonsFromGeoJSON:
        (nonnull NSDictionary *)geoJSON;

    Swift

    class func polygons(fromGeoJSON geoJSON: [AnyHashable : Any]) -> [AWFGeoPolygon]?

    Parameters

    geoJSON

    The GeoJSON data to generate polygon instances from

    Return Value

    An array of polygon instances based on the GeoJSON data