Package com.mapbox.turf
Class TurfMeasurement
java.lang.Object
com.mapbox.turf.TurfMeasurement
Class contains an assortment of methods used to calculate measurements such as bearing,
destination, midpoint, etc.
- Since:
- 1.2.0
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic com.mapbox.geojson.PointTakes a line and returns a point at a specified distance along the line.static com.mapbox.geojson.PointTakes a list of points and returns a point at a specified distance along the line.static doublearea(com.mapbox.geojson.Feature feature) Takes oneFeatureand returns it's area in square meters.static doublearea(com.mapbox.geojson.FeatureCollection featureCollection) Takes oneFeatureCollectionand returns it's area in square meters.static doublearea(com.mapbox.geojson.Geometry geometry) Takes oneGeometryand returns its area in square meters.static double[]bbox(com.mapbox.geojson.Feature feature) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.static double[]bbox(com.mapbox.geojson.FeatureCollection featureCollection) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.static double[]bbox(com.mapbox.geojson.GeoJson geoJson) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.static double[]bbox(com.mapbox.geojson.Geometry geometry) Takes an arbitraryGeometryand calculates a bounding box.static double[]bbox(com.mapbox.geojson.LineString lineString) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.static double[]bbox(com.mapbox.geojson.MultiLineString multiLineString) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.static double[]bbox(com.mapbox.geojson.MultiPoint multiPoint) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.static double[]bbox(com.mapbox.geojson.MultiPolygon multiPolygon) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.static double[]bbox(com.mapbox.geojson.Point point) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.static double[]bbox(com.mapbox.geojson.Polygon polygon) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.static com.mapbox.geojson.FeaturebboxPolygon(double[] bbox) Takes a bbox and uses its coordinates to create aPolygongeometry.static com.mapbox.geojson.FeaturebboxPolygon(double[] bbox, com.google.gson.JsonObject properties, String id) Takes a bbox and uses its coordinates to create aPolygongeometry.static com.mapbox.geojson.FeaturebboxPolygon(com.mapbox.geojson.BoundingBox boundingBox) Takes aBoundingBoxand uses its coordinates to create aPolygongeometry.static com.mapbox.geojson.FeaturebboxPolygon(com.mapbox.geojson.BoundingBox boundingBox, com.google.gson.JsonObject properties, String id) Takes aBoundingBoxand uses its coordinates to create aPolygongeometry.static doublebearing(com.mapbox.geojson.Point point1, com.mapbox.geojson.Point point2) Takes twoPoints and finds the geographic bearing between them.static com.mapbox.geojson.Featurecenter(com.mapbox.geojson.Feature feature) Takes aFeatureand returns the absolute center of theFeature.static com.mapbox.geojson.Featurecenter(com.mapbox.geojson.FeatureCollection featureCollection) TakesFeatureCollectionand returns the absolute center of theFeatures in theFeatureCollection.static com.mapbox.geojson.Featurecenter(com.mapbox.geojson.FeatureCollection featureCollection, com.google.gson.JsonObject properties, String id) TakesFeatureCollectionand returns the absolute center of theFeatures in theFeatureCollection.static com.mapbox.geojson.FeatureTakes aFeatureand returns the absolute center of theFeature.static com.mapbox.geojson.Pointdestination(com.mapbox.geojson.Point point, double distance, double bearing, String units) Takes a Point and calculates the location of a destination point given a distance in degrees, radians, miles, or kilometers; and bearing in degrees.static doubledistance(com.mapbox.geojson.Point point1, com.mapbox.geojson.Point point2) Calculates the distance between two points in kilometers.static doubleCalculates the distance between two points in degress, radians, miles, or kilometers.static com.mapbox.geojson.Polygonenvelope(com.mapbox.geojson.GeoJson geoJson) Takes any number of features and returns a rectangular Polygon that encompasses all vertices.static doubleTakes aLineStringand measures its length in the specified units.static doubleTakes aMultiLineStringand measures its length in the specified units.static doubleTakes aMultiPolygonand measures each polygons perimeter in the specified units.static doubleTakes aPolygonand measures its perimeter in the specified units.static doubleTakes aListofPointand measures its length in the specified units.static com.mapbox.geojson.Pointmidpoint(com.mapbox.geojson.Point from, com.mapbox.geojson.Point to) Takes twoPoints and returns a point midway between them.static com.mapbox.geojson.BoundingBoxsquare(com.mapbox.geojson.BoundingBox boundingBox) Takes a bounding box and calculates the minimum square bounding box that would contain the input.
-
Field Details
-
EARTH_RADIUS
public static double EARTH_RADIUSEarth's radius in meters.
-
-
Method Details
-
bearing
public static double bearing(@NonNull com.mapbox.geojson.Point point1, @NonNull com.mapbox.geojson.Point point2) Takes twoPoints and finds the geographic bearing between them.- Parameters:
point1- first point used for calculating the bearingpoint2- second point used for calculating the bearing- Returns:
- bearing in decimal degrees
- Since:
- 1.3.0
- See Also:
-
destination
@NonNull public static com.mapbox.geojson.Point destination(@NonNull com.mapbox.geojson.Point point, double distance, double bearing, @NonNull String units) 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.- Parameters:
point- starting point used for calculating the destinationdistance- distance from the starting pointbearing- ranging from -180 to 180 in decimal degreesunits- one of the units found insideTurfConstants.TurfUnitCriteria- Returns:
- destination
Pointresult where you specified - Since:
- 1.2.0
- See Also:
-
distance
public static double distance(@NonNull com.mapbox.geojson.Point point1, @NonNull com.mapbox.geojson.Point point2) Calculates the distance between two points in kilometers. This uses the Haversine formula to account for global curvature.- Parameters:
point1- first point used for calculating the bearingpoint2- second point used for calculating the bearing- Returns:
- distance between the two points in kilometers
- Since:
- 1.2.0
- See Also:
-
distance
public static double distance(@NonNull com.mapbox.geojson.Point point1, @NonNull com.mapbox.geojson.Point point2, @NonNull String units) Calculates the distance between two points in degress, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature.- Parameters:
point1- first point used for calculating the bearingpoint2- second point used for calculating the bearingunits- one of the units found insideTurfConstants.TurfUnitCriteria- Returns:
- distance between the two points in kilometers
- Since:
- 1.2.0
- See Also:
-
length
public static double length(@NonNull com.mapbox.geojson.LineString lineString, @NonNull String units) Takes aLineStringand measures its length in the specified units.- Parameters:
lineString- geometry to measureunits- one of the units found insideTurfConstants.TurfUnitCriteria- Returns:
- length of the input line in the units specified
- Since:
- 1.2.0
- See Also:
-
length
public static double length(@NonNull com.mapbox.geojson.MultiLineString multiLineString, @NonNull String units) Takes aMultiLineStringand measures its length in the specified units.- Parameters:
multiLineString- geometry to measureunits- one of the units found insideTurfConstants.TurfUnitCriteria- Returns:
- length of the input lines combined, in the units specified
- Since:
- 1.2.0
- See Also:
-
length
Takes aPolygonand measures its perimeter in the specified units. if the polygon contains holes, the perimeter will also be included.- Parameters:
polygon- geometry to measureunits- one of the units found insideTurfConstants.TurfUnitCriteria- Returns:
- total perimeter of the input polygon in the units specified
- Since:
- 1.2.0
- See Also:
-
length
public static double length(@NonNull com.mapbox.geojson.MultiPolygon multiPolygon, @NonNull String units) Takes aMultiPolygonand measures each polygons perimeter in the specified units. if one of the polygons contains holes, the perimeter will also be included.- Parameters:
multiPolygon- geometry to measureunits- one of the units found insideTurfConstants.TurfUnitCriteria- Returns:
- total perimeter of the input polygons combined, in the units specified
- Since:
- 1.2.0
- See Also:
-
length
Takes aListofPointand measures its length in the specified units.- Parameters:
coords- geometry to measureunits- one of the units found insideTurfConstants.TurfUnitCriteria- Returns:
- length of the input line in the units specified
- Since:
- 5.2.0
- See Also:
-
midpoint
public static com.mapbox.geojson.Point midpoint(@NonNull com.mapbox.geojson.Point from, @NonNull com.mapbox.geojson.Point to) Takes twoPoints and returns a point midway between them. The midpoint is calculated geodesically, meaning the curvature of the earth is taken into account.- Parameters:
from- first point used for calculating the midpointto- second point used for calculating the midpoint- Returns:
- a
Pointmidway between point1 and point2 - Since:
- 1.3.0
- See Also:
-
along
public static com.mapbox.geojson.Point along(@NonNull com.mapbox.geojson.LineString line, double distance, @NonNull String units) Takes a line and returns a point at a specified distance along the line.- Parameters:
line- that the point should be placed upondistance- along the linestring geometry which the point should be placed onunits- one of the units found insideTurfConstants.TurfUnitCriteria- Returns:
- a
Pointwhich is on the linestring provided and at the distance from the origin of that line to the end of the distance - Since:
- 1.3.0
-
along
public static com.mapbox.geojson.Point along(@NonNull List<com.mapbox.geojson.Point> coords, double distance, @NonNull String units) Takes a list of points and returns a point at a specified distance along the line.- Parameters:
coords- that the point should be placed upondistance- along the linestring geometry which the point should be placed onunits- one of the units found insideTurfConstants.TurfUnitCriteria- Returns:
- a
Pointwhich is on the linestring provided and at the distance from the origin of that line to the end of the distance - Since:
- 5.2.0
-
bbox
public static double[] bbox(@NonNull com.mapbox.geojson.Point point) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.- Parameters:
point- aPointobject- Returns:
- A double array defining the bounding box in this order
[minX, minY, maxX, maxY] - Since:
- 2.0.0
-
bbox
public static double[] bbox(@NonNull com.mapbox.geojson.LineString lineString) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.- Parameters:
lineString- aLineStringobject- Returns:
- A double array defining the bounding box in this order
[minX, minY, maxX, maxY] - Since:
- 2.0.0
-
bbox
public static double[] bbox(@NonNull com.mapbox.geojson.MultiPoint multiPoint) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.- Parameters:
multiPoint- aMultiPointobject- Returns:
- a double array defining the bounding box in this order
[minX, minY, maxX, maxY] - Since:
- 2.0.0
-
bbox
public static double[] bbox(@NonNull com.mapbox.geojson.Polygon polygon) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.- Parameters:
polygon- aPolygonobject- Returns:
- a double array defining the bounding box in this order
[minX, minY, maxX, maxY] - Since:
- 2.0.0
-
bbox
public static double[] bbox(@NonNull com.mapbox.geojson.MultiLineString multiLineString) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.- Parameters:
multiLineString- aMultiLineStringobject- Returns:
- a double array defining the bounding box in this order
[minX, minY, maxX, maxY] - Since:
- 2.0.0
-
bbox
public static double[] bbox(com.mapbox.geojson.MultiPolygon multiPolygon) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.- Parameters:
multiPolygon- aMultiPolygonobject- Returns:
- a double array defining the bounding box in this order
[minX, minY, maxX, maxY] - Since:
- 2.0.0
-
bbox
public static double[] bbox(com.mapbox.geojson.GeoJson geoJson) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.- Parameters:
geoJson- aGeoJsonobject- Returns:
- a double array defining the bounding box in this order
[minX, minY, maxX, maxY] - Since:
- 4.8.0
-
bbox
public static double[] bbox(com.mapbox.geojson.FeatureCollection featureCollection) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.- Parameters:
featureCollection- aFeatureCollectionobject- Returns:
- a double array defining the bounding box in this order
[minX, minY, maxX, maxY] - Since:
- 4.8.0
-
bbox
public static double[] bbox(com.mapbox.geojson.Feature feature) Takes a set of features, calculates the bbox of all input features, and returns a bounding box.- Parameters:
feature- aFeatureobject- Returns:
- a double array defining the bounding box in this order
[minX, minY, maxX, maxY] - Since:
- 4.8.0
-
bbox
public static double[] bbox(com.mapbox.geojson.Geometry geometry) Takes an arbitraryGeometryand calculates a bounding box.- Parameters:
geometry- aGeometryobject- Returns:
- a double array defining the bounding box in this order
[minX, minY, maxX, maxY] - Since:
- 2.0.0
-
bboxPolygon
public static com.mapbox.geojson.Feature bboxPolygon(@NonNull com.mapbox.geojson.BoundingBox boundingBox) Takes aBoundingBoxand uses its coordinates to create aPolygongeometry.- Parameters:
boundingBox- aBoundingBoxobject to calculate with- Returns:
- a
Featureobject - Since:
- 4.9.0
- See Also:
-
bboxPolygon
public static com.mapbox.geojson.Feature bboxPolygon(@NonNull com.mapbox.geojson.BoundingBox boundingBox, @Nullable com.google.gson.JsonObject properties, @Nullable String id) Takes aBoundingBoxand uses its coordinates to create aPolygongeometry.- Parameters:
boundingBox- aBoundingBoxobject to calculate withproperties- aJsonObjectcontaining the feature propertiesid- common identifier of this feature- Returns:
- a
Featureobject - Since:
- 4.9.0
- See Also:
-
bboxPolygon
public static com.mapbox.geojson.Feature bboxPolygon(@NonNull double[] bbox) Takes a bbox and uses its coordinates to create aPolygongeometry.- Parameters:
bbox- a double[] object to calculate with- Returns:
- a
Featureobject - Since:
- 4.9.0
- See Also:
-
bboxPolygon
public static com.mapbox.geojson.Feature bboxPolygon(@NonNull double[] bbox, @Nullable com.google.gson.JsonObject properties, @Nullable String id) Takes a bbox and uses its coordinates to create aPolygongeometry.- Parameters:
bbox- a double[] object to calculate withproperties- aJsonObjectcontaining the feature propertiesid- common identifier of this feature- Returns:
- a
Featureobject - Since:
- 4.9.0
- See Also:
-
envelope
public static com.mapbox.geojson.Polygon envelope(com.mapbox.geojson.GeoJson geoJson) Takes any number of features and returns a rectangular Polygon that encompasses all vertices.- Parameters:
geoJson- input features- Returns:
- a rectangular Polygon feature that encompasses all vertices
- Since:
- 4.9.0
-
square
public static com.mapbox.geojson.BoundingBox square(@NonNull com.mapbox.geojson.BoundingBox boundingBox) Takes a bounding box and calculates the minimum square bounding box that would contain the input.- Parameters:
boundingBox- extent in west, south, east, north order- Returns:
- a square surrounding bbox
- Since:
- 4.9.0
-
area
public static double area(@NonNull com.mapbox.geojson.Feature feature) Takes oneFeatureand returns it's area in square meters.- Parameters:
feature- inputFeature- Returns:
- area in square meters
- Since:
- 4.10.0
-
area
public static double area(@NonNull com.mapbox.geojson.FeatureCollection featureCollection) Takes oneFeatureCollectionand returns it's area in square meters.- Parameters:
featureCollection- inputFeatureCollection- Returns:
- area in square meters
- Since:
- 4.10.0
-
area
public static double area(@NonNull com.mapbox.geojson.Geometry geometry) Takes oneGeometryand returns its area in square meters.- Parameters:
geometry- inputGeometry- Returns:
- area in square meters
- Since:
- 4.10.0
-
center
public static com.mapbox.geojson.Feature center(com.mapbox.geojson.Feature feature, @Nullable com.google.gson.JsonObject properties, @Nullable String id) Takes aFeatureand returns the absolute center of theFeature.- Parameters:
feature- the singleFeatureto find the center of.properties- a optionalJsonObjectcontaining the properties that should be placed in the returnedFeature.id- an optional common identifier that should be placed in the returnedFeature.- Returns:
- a
Featurewith aPointgeometry type. - Since:
- 5.3.0
-
center
public static com.mapbox.geojson.Feature center(com.mapbox.geojson.Feature feature) Takes aFeatureand returns the absolute center of theFeature.- Parameters:
feature- the singleFeatureto find the center of.- Returns:
- a
Featurewith aPointgeometry type. - Since:
- 5.3.0
-
center
public static com.mapbox.geojson.Feature center(com.mapbox.geojson.FeatureCollection featureCollection, @Nullable com.google.gson.JsonObject properties, @Nullable String id) TakesFeatureCollectionand returns the absolute center of theFeatures in theFeatureCollection.- Parameters:
featureCollection- the singleFeatureCollectionto find the center of.properties- a optionalJsonObjectcontaining the properties that should be placed in the returnedFeature.id- an optional common identifier that should be placed in the returnedFeature.- Returns:
- a
Featurewith aPointgeometry type. - Since:
- 5.3.0
-
center
public static com.mapbox.geojson.Feature center(com.mapbox.geojson.FeatureCollection featureCollection) TakesFeatureCollectionand returns the absolute center of theFeatures in theFeatureCollection.- Parameters:
featureCollection- the singleFeatureCollectionto find the center of.- Returns:
- a
Featurewith aPointgeometry type. - Since:
- 5.3.0
-