turf library

Classes

BBox
Please make sure, you arrange your parameters like this: Longitude 1, Latitude 1, Altitude 1 (optional), Longitude 2, Latitude 2, Altitude 2 (optional) You can either specify 4 or 6 parameters If you are using the default constructor with two dimensional positions (lng + lat only), please use the constructor like this: BBox(lng1, lat1, lng2, lat2);
CoordinateType
Coordinate types, following https://tools.ietf.org/html/rfc7946#section-4
Feature<T extends GeometryObject>
Feature, as specified here https://tools.ietf.org/html/rfc7946#section-3.2
FeatureCollection<T extends GeometryObject>
FeatureCollection, as specified here https://tools.ietf.org/html/rfc7946#section-3.3
GeoJSONObject
GeometryCollection
GeometryCollection, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.8
GeometryObject
GeometryType<T>
LineString
LineString, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.4
MultiLineString
MultiLineString, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.5
MultiPoint
MultiPoint, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.3
MultiPolygon
MultiPolygon, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.7
Point
Point, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.2
Polygon
Polygon, as specified here https://tools.ietf.org/html/rfc7946#section-3.1.6
Polyline
Based off of the offical Google document Some parts from this implementation by Mark McClure
Position
Please make sure, you arrange your parameters like this:

Constants

areaFactors → const Map<Unit, num>
Area of measurement factors based on 1 square meter.
earthRadius → const double
Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
factors → const Map<Unit, num>
Unit of measurement factors using a spherical (non-ellipsoid) earth radius. Keys are the name of the unit, values are the number of that unit in a single radian
unitsFactors → const Map<Unit, num>

Functions

along(Feature<LineString> line, num distance, [Unit unit = Unit.kilometers]) Feature<Point>
Takes a line and returns a Point at a specified distance along the line.
area(GeoJSONObject geojson) num?
Takes a GeoJSONObject and returns their area in square meters.
bbox(GeoJSONObject geoJson, {bool recompute = false}) BBox
Calculates the bounding box for any geoJson object, including FeatureCollection. If recompute is not set and the bbox is not null, the function uses the bbox of the given GeoJSONObject.
bearing(Point start, Point end, {bool calcFinal = false}) num
Takes two Points and finds the geographic bearing between them, i.e. the angle measured in degrees from the north line (0 degrees) For example:
bearingRaw(Position start, Position end, {bool calcFinal = false}) num
bearingToAzimuth(num bearing) num
Converts any bearing angle from the north line direction (positive clockwise) and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
calculateFinalBearing(Point start, Point end) num
Calculates Final Bearing
calculateFinalBearingRaw(Position start, Position end) num
center(GeoJSONObject geoJSON, {dynamic id, BBox? bbox, Map<String, dynamic>? properties}) Feature<Point>
Takes a Feature or a FeatureCollection and returns the absolute center point of all feature(s).
centroid(GeoJSONObject geoJSON, {Map<String, dynamic>? properties}) Feature<Point>
Takes a Feature or a FeatureCollection and computes the centroid as the mean of all vertices within the object.
convertArea(num area, [dynamic originalUnit = Unit.meters, dynamic finalUnit = Unit.kilometers]) num
Converts a area to the requested unit. Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches, hectares
convertLength(num length, [Unit originalUnit = Unit.kilometers, Unit finalUnit = Unit.kilometers]) num
Converts a length to the requested unit. Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
degreesToRadians(num degrees) num
Converts an angle in degrees to radians
destination(Point origin, num distance, num bearing, [Unit unit = Unit.kilometers]) Point
Takes a Point and calculates the location of a destination point given a distance in degrees, radians, miles, or kilometers; and bearing in degrees. This uses the Haversine formula to account for global curvature. For example:
destinationRaw(Position origin, num distance, num bearing, [Unit unit = Unit.kilometers]) Position
distance(Point from, Point to, [Unit unit = Unit.kilometers]) num
Calculates the distance between two Points in degrees, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature. For example:
distanceRaw(Position from, Position to, [Unit unit = Unit.kilometers]) num
length(Feature<LineString> line, [Unit unit = Unit.kilometers]) num
Takes a line and measures its length in the specified unit.
lengthToDegrees(num distance, [Unit unit = Unit.kilometers]) num
Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
lengthToRadians(num distance, [Unit unit = Unit.kilometers]) num
Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
midpoint(Point point1, Point point2) Point
Takes two Points and returns a point midway between them. The midpoint is calculated geodesically, meaning the curvature of the earth is taken into account. For example:
midpointRaw(Position point1, Position point2) Position
nearestPoint(Feature<Point> targetPoint, FeatureCollection<Point> points) Feature<Point>
Takes a reference Point and a FeatureCollection of Features with Point geometries and returns the point from the FeatureCollection closest to the reference. This calculation is geodesic. For example:
nearestPointOnLine(LineString line, Point point, [Unit unit = Unit.kilometers]) Feature<Point>
Takes a Point and a LineString and calculates the closest Point on the LineString.
nearestPointOnMultiLine(MultiLineString lines, Point point, [Unit unit = Unit.kilometers]) Feature<Point>?
Takes a Point and a MultiLineString and calculates the closest Point on the MultiLineString.
radiansToDegrees(num radians) num
Converts an angle in radians to degrees
radiansToLength(num radians, [Unit unit = Unit.kilometers]) num
Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit. Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
round(num value, [num precision = 0]) num
Round number to precision