SFGeometryUtils

@interface SFGeometryUtils : NSObject

Utilities for Geometry objects

@author osbornb

  • Get the dimension of the Geometry, 0 for points, 1 for curves, 2 for surfaces. If a collection, the largest dimension is returned.

    Declaration

    Objective-C

    + (int)dimensionOfGeometry:(SFGeometry *)geometry;

    Swift

    class func dimension(of geometry: SFGeometry!) -> Int32

    Parameters

    geometry

    geometry object

    Return Value

    dimension (0, 1, or 2)

  • Get the Pythagorean theorem distance between two points

    Declaration

    Objective-C

    + (double)distanceBetweenPoint1:(SFPoint *)point1 andPoint2:(SFPoint *)point2;

    Swift

    class func distanceBetweenPoint1(_ point1: SFPoint!, andPoint2 point2: SFPoint!) -> Double

    Parameters

    point1

    point 1

    point2

    point 2

    Return Value

    distance

  • Get the centroid point of a 2 dimensional representation of the Geometry (balancing point of a 2d cutout of the geometry). Only the x and y coordinate of the resulting point are calculated and populated. The resulting SFPoint.z and SFPoint.m values will always be nil.

    Declaration

    Objective-C

    + (SFPoint *)centroidOfGeometry:(SFGeometry *)geometry;

    Swift

    class func centroid(of geometry: SFGeometry!) -> SFPoint!

    Parameters

    geometry

    geometry object

    Return Value

    centroid point

  • Minimize the geometry using the shortest x distance between each connected set of points. The resulting geometry point x values will be in the range: (3 * min value <= x <= 3 * max value

    Example: For WGS84 provide a max x of 180.0. Resulting x values will be in the range: -540.0 <= x <= 540.0

    Example: For web mercator provide a world width of 20037508.342789244. Resulting x values will be in the range: -60112525.028367732 <= x <= 60112525.028367732

    Declaration

    Objective-C

    + (void)minimizeGeometry:(SFGeometry *)geometry withMaxX:(double)maxX;

    Swift

    class func minimizeGeometry(_ geometry: SFGeometry!, withMaxX maxX: Double)

    Parameters

    geometry

    geometry

    maxX

    max positive x value in the geometry projection

  • Normalize the geometry so all points outside of the min and max value range are adjusted to fall within the range.

    Example: For WGS84 provide a max x of 180.0. Resulting x values will be in the range: -180.0 <= x <= 180.0.

    Example: For web mercator provide a world width of 20037508.342789244. Resulting x values will be in the range: -20037508.342789244 <= x <= 20037508.342789244.

    Declaration

    Objective-C

    + (void)normalizeGeometry:(SFGeometry *)geometry withMaxX:(double)maxX;

    Swift

    class func normalize(_ geometry: SFGeometry!, withMaxX maxX: Double)

    Parameters

    geometry

    geometry

    maxX

    max positive x value in the geometry projection

  • Simplify the ordered points (representing a line, polygon, etc) using the Douglas Peucker algorithm to create a similar curve with fewer points. Points should be in a meters unit type projection. The tolerance is the minimum tolerated distance between consecutive points.

    Declaration

    Objective-C

    + (NSArray<SFPoint *> *)simplifyPoints:(NSArray<SFPoint *> *)points
                             withTolerance:(double)tolerance;

    Swift

    class func simplifyPoints(_ points: [SFPoint]!, withTolerance tolerance: Double) -> [SFPoint]!

    Parameters

    points

    geometry points

    tolerance

    minimum tolerance in meters for consecutive points

    Return Value

    simplified points

  • Calculate the perpendicular distance between the point and the line represented by the start and end points. Points should be in a meters unit type projection.

    Declaration

    Objective-C

    + (double)perpendicularDistanceBetweenPoint:(SFPoint *)point
                                      lineStart:(SFPoint *)lineStart
                                        lineEnd:(SFPoint *)lineEnd;

    Swift

    class func perpendicularDistanceBetweenPoint(_ point: SFPoint!, lineStart: SFPoint!, lineEnd: SFPoint!) -> Double

    Parameters

    point

    point

    lineStart

    point representing the line start

    lineEnd

    point representing the line end

    Return Value

    distance in meters

  • Check if the point is in the polygon

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point inPolygon:(SFPolygon *)polygon;

    Swift

    class func point(_ point: SFPoint!, in polygon: SFPolygon!) -> Bool

    Parameters

    point

    point

    polygon

    polygon

    Return Value

    true if in the polygon

  • Check if the point is in the polygon

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point
          inPolygon:(SFPolygon *)polygon
        withEpsilon:(double)epsilon;

    Swift

    class func point(_ point: SFPoint!, in polygon: SFPolygon!, withEpsilon epsilon: Double) -> Bool

    Parameters

    point

    point

    polygon

    polygon

    epsilon

    epsilon line tolerance

    Return Value

    true if in the polygon

  • Check if the point is in the polygon ring

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point inPolygonRing:(SFLineString *)ring;

    Swift

    class func point(_ point: SFPoint!, inPolygonRing ring: SFLineString!) -> Bool

    Parameters

    point

    point

    ring

    polygon ring

    Return Value

    true if in the polygon

  • Check if the point is in the polygon ring

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point
        inPolygonRing:(SFLineString *)ring
          withEpsilon:(double)epsilon;

    Swift

    class func point(_ point: SFPoint!, inPolygonRing ring: SFLineString!, withEpsilon epsilon: Double) -> Bool

    Parameters

    point

    point

    ring

    polygon ring

    epsilon

    epsilon line tolerance

    Return Value

    true if in the polygon

  • Check if the point is in the polygon points

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point inPolygonPoints:(NSArray<SFPoint *> *)points;

    Swift

    class func point(_ point: SFPoint!, inPolygonPoints points: [SFPoint]!) -> Bool

    Parameters

    point

    point

    points

    polygon points

    Return Value

    true if in the polygon

  • Check if the point is in the polygon points

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point
        inPolygonPoints:(NSArray<SFPoint *> *)points
            withEpsilon:(double)epsilon;

    Swift

    class func point(_ point: SFPoint!, inPolygonPoints points: [SFPoint]!, withEpsilon epsilon: Double) -> Bool

    Parameters

    point

    point

    points

    polygon points

    epsilon

    epsilon line tolerance

    Return Value

    true if in the polygon

  • Check if the point is on the polygon edge

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point onPolygonEdge:(SFPolygon *)polygon;

    Swift

    class func point(_ point: SFPoint!, onPolygonEdge polygon: SFPolygon!) -> Bool

    Parameters

    point

    point

    polygon

    polygon

    Return Value

    true if on the polygon edge

  • Check if the point is on the polygon edge

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point
        onPolygonEdge:(SFPolygon *)polygon
          withEpsilon:(double)epsilon;

    Swift

    class func point(_ point: SFPoint!, onPolygonEdge polygon: SFPolygon!, withEpsilon epsilon: Double) -> Bool

    Parameters

    point

    point

    polygon

    polygon

    epsilon

    epsilon line tolerance

    Return Value

    true if on the polygon edge

  • Check if the point is on the polygon ring edge

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point onPolygonRingEdge:(SFLineString *)ring;

    Swift

    class func point(_ point: SFPoint!, onPolygonRingEdge ring: SFLineString!) -> Bool

    Parameters

    point

    point

    ring

    polygon ring

    Return Value

    true if on the polygon edge

  • Check if the point is on the polygon ring edge

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point
        onPolygonRingEdge:(SFLineString *)ring
              withEpsilon:(double)epsilon;

    Swift

    class func point(_ point: SFPoint!, onPolygonRingEdge ring: SFLineString!, withEpsilon epsilon: Double) -> Bool

    Parameters

    point

    point

    ring

    polygon ring

    epsilon

    epsilon line tolerance

    Return Value

    true if on the polygon edge

  • Check if the point is on the polygon ring edge points

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point onPolygonPointsEdge:(NSArray<SFPoint *> *)points;

    Swift

    class func point(_ point: SFPoint!, onPolygonPointsEdge points: [SFPoint]!) -> Bool

    Parameters

    point

    point

    points

    polygon points

    Return Value

    true if on the polygon edge

  • Check if the point is on the polygon ring edge points

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point
        onPolygonPointsEdge:(NSArray<SFPoint *> *)points
                withEpsilon:(double)epsilon;

    Swift

    class func point(_ point: SFPoint!, onPolygonPointsEdge points: [SFPoint]!, withEpsilon epsilon: Double) -> Bool

    Parameters

    point

    point

    points

    polygon points

    epsilon

    epsilon line tolerance

    Return Value

    true if on the polygon edge

  • Check if the polygon outer ring is explicitly closed, where the first and last point are the same

    Declaration

    Objective-C

    + (BOOL)closedPolygon:(SFPolygon *)polygon;

    Swift

    class func closedPolygon(_ polygon: SFPolygon!) -> Bool

    Parameters

    polygon

    polygon

    Return Value

    true if the first and last points are the same

  • Check if the polygon ring is explicitly closed, where the first and last point are the same

    Declaration

    Objective-C

    + (BOOL)closedPolygonRing:(SFLineString *)ring;

    Swift

    class func closedPolygonRing(_ ring: SFLineString!) -> Bool

    Parameters

    ring

    polygon ring

    Return Value

    true if the first and last points are the same

  • Check if the polygon ring points are explicitly closed, where the first and last point are the same

    Declaration

    Objective-C

    + (BOOL)closedPolygonPoints:(NSArray<SFPoint *> *)points;

    Swift

    class func closedPolygonPoints(_ points: [SFPoint]!) -> Bool

    Parameters

    points

    polygon ring points

    Return Value

    true if the first and last points are the same

  • Check if the point is on the line

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point onLine:(SFLineString *)line;

    Swift

    class func point(_ point: SFPoint!, onLine line: SFLineString!) -> Bool

    Parameters

    point

    point

    line

    line

    Return Value

    true if on the line

  • Check if the point is on the line

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point
             onLine:(SFLineString *)line
        withEpsilon:(double)epsilon;

    Swift

    class func point(_ point: SFPoint!, onLine line: SFLineString!, withEpsilon epsilon: Double) -> Bool

    Parameters

    point

    point

    line

    line

    epsilon

    epsilon line tolerance

    Return Value

    true if on the line

  • Check if the point is on the line represented by the points

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point onLinePoints:(NSArray<SFPoint *> *)points;

    Swift

    class func point(_ point: SFPoint!, onLinePoints points: [SFPoint]!) -> Bool

    Parameters

    point

    point

    points

    line points

    Return Value

    true if on the line

  • Check if the point is on the line represented by the points

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point
        onLinePoints:(NSArray<SFPoint *> *)points
         withEpsilon:(double)epsilon;

    Swift

    class func point(_ point: SFPoint!, onLinePoints points: [SFPoint]!, withEpsilon epsilon: Double) -> Bool

    Parameters

    point

    point

    points

    line points

    epsilon

    epsilon line tolerance

    Return Value

    true if on the line

  • Check if the point is on the path between point 1 and point 2

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point
        onPathPoint1:(SFPoint *)point1
           andPoint2:(SFPoint *)point2;

    Swift

    class func point(_ point: SFPoint!, onPathPoint1 point1: SFPoint!, andPoint2 point2: SFPoint!) -> Bool

    Parameters

    point

    point

    point1

    path point 1

    point2

    path point 2

    Return Value

    true if on the path

  • Check if the point is on the path between point 1 and point 2

    Declaration

    Objective-C

    + (BOOL)point:(SFPoint *)point
        onPathPoint1:(SFPoint *)point1
           andPoint2:(SFPoint *)point2
         withEpsilon:(double)epsilon;

    Swift

    class func point(_ point: SFPoint!, onPathPoint1 point1: SFPoint!, andPoint2 point2: SFPoint!, withEpsilon epsilon: Double) -> Bool

    Parameters

    point

    point

    point1

    path point 1

    point2

    path point 2

    epsilon

    epsilon line tolerance

    Return Value

    true if on the path

  • Determine if the geometries contain a Z value

    Declaration

    Objective-C

    + (BOOL)hasZ:(NSArray<SFGeometry *> *)geometries;

    Swift

    class func hasZ(_ geometries: [SFGeometry]!) -> Bool

    Parameters

    geometries

    list of geometries

    Return Value

    true if has z

  • Determine if the geometries contain a M value

    Declaration

    Objective-C

    + (BOOL)hasM:(NSArray<SFGeometry *> *)geometries;

    Swift

    class func hasM(_ geometries: [SFGeometry]!) -> Bool

    Parameters

    geometries

    list of geometries

    Return Value

    true if has m

  • Get the parent type hierarchy of the provided geometry type starting with the immediate parent. If the argument is GEOMETRY, an empty list is returned, else the final type in the list will be GEOMETRY.

    Declaration

    Objective-C

    + (NSArray<NSNumber *> *)parentHierarchyOfType:
        (enum SFGeometryType)geometryType;

    Swift

    class func parentHierarchy(of geometryType: SFGeometryType) -> [NSNumber]!

    Parameters

    geometryType

    geometry type

    Return Value

    list of increasing parent types

  • Get the parent Geometry Type of the provided geometry type

    Declaration

    Objective-C

    + (enum SFGeometryType)parentTypeOfType:(enum SFGeometryType)geometryType;

    Swift

    class func parentType(of geometryType: SFGeometryType) -> SFGeometryType

    Parameters

    geometryType

    geometry type

    Return Value

    parent geometry type or null if argument is GEOMETRY (no parent type)

  • Get the child type hierarchy of the provided geometry type.

    Declaration

    Objective-C

    + (NSDictionary<NSNumber *, NSDictionary *> *)childHierarchyOfType:
        (enum SFGeometryType)geometryType;

    Swift

    class func childHierarchy(of geometryType: SFGeometryType) -> [NSNumber : [AnyHashable : Any]]!

    Parameters

    geometryType

    geometry type

    Return Value

    child type hierarchy, null if no children

  • Get the immediate child Geometry Types of the provided geometry type

    Declaration

    Objective-C

    + (NSArray<NSNumber *> *)childTypesOfType:(enum SFGeometryType)geometryType;

    Swift

    class func childTypes(of geometryType: SFGeometryType) -> [NSNumber]!

    Parameters

    geometryType

    geometry type

    Return Value

    child geometry types, empty list if no child types

  • Encode the geometry to data

    Declaration

    Objective-C

    + (NSData *)encodeGeometry:(SFGeometry *)geometry;

    Swift

    class func encode(_ geometry: SFGeometry!) -> Data!

    Parameters

    geometry

    geometry

    Return Value

    encoded dta

  • Decode the data into a geometry

    Declaration

    Objective-C

    + (SFGeometry *)decodeGeometry:(NSData *)data;

    Swift

    class func decodeGeometry(_ data: Data!) -> SFGeometry!

    Parameters

    data

    encoded data

    Return Value

    geometry