Class TurfConversion

java.lang.Object
com.mapbox.turf.TurfConversion

public final class TurfConversion extends Object
This class is made up of methods that take in an object, convert it, and then return the object in the desired units or object.
Since:
1.2.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static com.mapbox.geojson.FeatureCollection
    combine(com.mapbox.geojson.FeatureCollection originalFeatureCollection)
    Combines a FeatureCollection of geometries and returns a FeatureCollection with "Multi-" geometries in it.
    static double
    convertLength(double distance, String originalUnit)
    Converts a distance to the default units.
    static double
    convertLength(double distance, String originalUnit, String finalUnit)
    Converts a distance to a different unit specified.
    static double
    degreesToRadians(double degrees)
    Converts an angle in degrees to radians.
    static com.mapbox.geojson.FeatureCollection
    explode(com.mapbox.geojson.Feature feature)
    Takes a Feature and returns its position as a Point objects.
    static com.mapbox.geojson.FeatureCollection
    explode(com.mapbox.geojson.FeatureCollection featureCollection)
    Takes a FeatureCollection and returns all positions as Point objects.
    static double
    lengthToDegrees(double distance, String units)
    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.
    static double
    lengthToRadians(double distance)
    Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians.
    static double
    lengthToRadians(double distance, String units)
    Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians.
    static com.mapbox.geojson.FeatureCollection
    multiPolygonToLine(com.mapbox.geojson.Feature feature)
    Takes a Feature that contains MultiPolygon and covert it to a FeatureCollection that contains list of Feature of LineString or MultiLineString.
    static com.mapbox.geojson.FeatureCollection
    multiPolygonToLine(com.mapbox.geojson.Feature feature, com.google.gson.JsonObject properties)
    Takes a Feature that contains MultiPolygon and a properties JsonObject and covert it to a FeatureCollection that contains list of Feature of LineString or MultiLineString.
    static com.mapbox.geojson.Feature
    polygonToLine(com.mapbox.geojson.Feature feature)
    Takes a Feature that contains Polygon and covert it to a Feature that contains LineString or MultiLineString.
    static com.mapbox.geojson.Feature
    polygonToLine(com.mapbox.geojson.Feature feature, com.google.gson.JsonObject properties)
    Takes a Feature that contains Polygon and a properties JsonObject and covert it to a Feature that contains LineString or MultiLineString.
    static com.mapbox.geojson.FeatureCollection
    polygonToLine(com.mapbox.geojson.MultiPolygon multiPolygon)
    Takes a MultiPolygon and covert it to a FeatureCollection that contains list of Feature of LineString or MultiLineString.
    static com.mapbox.geojson.FeatureCollection
    polygonToLine(com.mapbox.geojson.MultiPolygon multiPolygon, com.google.gson.JsonObject properties)
    Takes a MultiPolygon and a properties JsonObject and covert it to a FeatureCollection that contains list of Feature of LineString or MultiLineString.
    static com.mapbox.geojson.Feature
    polygonToLine(com.mapbox.geojson.Polygon polygon)
    Takes a Polygon and covert it to a Feature that contains LineString or MultiLineString.
    static com.mapbox.geojson.Feature
    polygonToLine(com.mapbox.geojson.Polygon polygon, com.google.gson.JsonObject properties)
    Takes a Polygon and a properties JsonObject and covert it to a Feature that contains LineString or MultiLineString.
    static double
    radiansToDegrees(double radians)
    Converts an angle in radians to degrees.
    static double
    radiansToLength(double radians)
    Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
    static double
    radiansToLength(double radians, String units)
    Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • lengthToDegrees

      public static double lengthToDegrees(double distance, String units)
      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.
      Parameters:
      distance - in real units
      units - can be degrees, radians, miles, or kilometers inches, yards, metres, meters, kilometres, kilometers.
      Returns:
      a double value representing the distance in degrees
      Since:
      3.0.0
    • degreesToRadians

      public static double degreesToRadians(double degrees)
      Converts an angle in degrees to radians.
      Parameters:
      degrees - angle between 0 and 360 degrees
      Returns:
      angle in radians
      Since:
      3.1.0
    • radiansToDegrees

      public static double radiansToDegrees(double radians)
      Converts an angle in radians to degrees.
      Parameters:
      radians - angle in radians
      Returns:
      degrees between 0 and 360 degrees
      Since:
      3.0.0
    • radiansToLength

      public static double radiansToLength(double radians)
      Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit. The units used here equals the default.
      Parameters:
      radians - a double using unit radian
      Returns:
      converted radian to distance value
      Since:
      1.2.0
    • radiansToLength

      public static double radiansToLength(double radians, @NonNull String units)
      Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
      Parameters:
      radians - a double using unit radian
      units - pass in one of the units defined in TurfConstants.TurfUnitCriteria
      Returns:
      converted radian to distance value
      Since:
      1.2.0
    • lengthToRadians

      public static double lengthToRadians(double distance)
      Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians.
      Parameters:
      distance - double representing a distance value assuming the distance units is in kilometers
      Returns:
      converted distance to radians value
      Since:
      1.2.0
    • lengthToRadians

      public static double lengthToRadians(double distance, @NonNull String units)
      Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians.
      Parameters:
      distance - double representing a distance value
      units - pass in one of the units defined in TurfConstants.TurfUnitCriteria
      Returns:
      converted distance to radians value
      Since:
      1.2.0
    • convertLength

      public static double convertLength(double distance, @NonNull String originalUnit)
      Converts a distance to the default units. Use convertLength(double, String, String) to specify a unit to convert to.
      Parameters:
      distance - double representing a distance value
      originalUnit - of the distance, must be one of the units defined in TurfConstants.TurfUnitCriteria
      Returns:
      converted distance in the default unit
      Since:
      2.2.0
    • convertLength

      public static double convertLength(double distance, @NonNull String originalUnit, @Nullable String finalUnit)
      Converts a distance to a different unit specified.
      Parameters:
      distance - the distance to be converted
      originalUnit - of the distance, must be one of the units defined in TurfConstants.TurfUnitCriteria
      finalUnit - returned unit, TurfConstants.UNIT_DEFAULT if not specified
      Returns:
      the converted distance
      Since:
      2.2.0
    • explode

      public static com.mapbox.geojson.FeatureCollection explode(@NonNull com.mapbox.geojson.FeatureCollection featureCollection)
      Takes a FeatureCollection and returns all positions as Point objects.
      Parameters:
      featureCollection - a FeatureCollection object
      Returns:
      a new FeatureCollection object with Point objects
      Since:
      4.8.0
    • explode

      public static com.mapbox.geojson.FeatureCollection explode(@NonNull com.mapbox.geojson.Feature feature)
      Takes a Feature and returns its position as a Point objects.
      Parameters:
      feature - a Feature object
      Returns:
      a new FeatureCollection object with Point objects
      Since:
      4.8.0
    • polygonToLine

      public static com.mapbox.geojson.Feature polygonToLine(@NonNull com.mapbox.geojson.Feature feature)
      Takes a Feature that contains Polygon and covert it to a Feature that contains LineString or MultiLineString.
      Parameters:
      feature - a Feature object that contains Polygon
      Returns:
      a Feature object that contains LineString or MultiLineString
      Since:
      4.9.0
    • polygonToLine

      public static com.mapbox.geojson.Feature polygonToLine(@NonNull com.mapbox.geojson.Feature feature, @Nullable com.google.gson.JsonObject properties)
      Takes a Feature that contains Polygon and a properties JsonObject and covert it to a Feature that contains LineString or MultiLineString.
      Parameters:
      feature - a Feature object that contains Polygon
      properties - a JsonObject that represents a feature's properties
      Returns:
      a Feature object that contains LineString or MultiLineString
      Since:
      4.9.0
    • polygonToLine

      public static com.mapbox.geojson.Feature polygonToLine(@NonNull com.mapbox.geojson.Polygon polygon)
      Takes a Polygon and covert it to a Feature that contains LineString or MultiLineString.
      Parameters:
      polygon - a Polygon object
      Returns:
      a Feature object that contains LineString or MultiLineString
      Since:
      4.9.0
    • polygonToLine

      public static com.mapbox.geojson.FeatureCollection polygonToLine(@NonNull com.mapbox.geojson.MultiPolygon multiPolygon)
      Takes a MultiPolygon and covert it to a FeatureCollection that contains list of Feature of LineString or MultiLineString.
      Parameters:
      multiPolygon - a MultiPolygon object
      Returns:
      a FeatureCollection object that contains list of Feature of LineString or MultiLineString
      Since:
      4.9.0
    • polygonToLine

      public static com.mapbox.geojson.Feature polygonToLine(@NonNull com.mapbox.geojson.Polygon polygon, @Nullable com.google.gson.JsonObject properties)
      Takes a Polygon and a properties JsonObject and covert it to a Feature that contains LineString or MultiLineString.
      Parameters:
      polygon - a Polygon object
      properties - a JsonObject that represents a feature's properties
      Returns:
      a Feature object that contains LineString or MultiLineString
      Since:
      4.9.0
    • polygonToLine

      public static com.mapbox.geojson.FeatureCollection polygonToLine(@NonNull com.mapbox.geojson.MultiPolygon multiPolygon, @Nullable com.google.gson.JsonObject properties)
      Takes a MultiPolygon and a properties JsonObject and covert it to a FeatureCollection that contains list of Feature of LineString or MultiLineString.
      Parameters:
      multiPolygon - a MultiPolygon object
      properties - a JsonObject that represents a feature's properties
      Returns:
      a FeatureCollection object that contains list of Feature of LineString or MultiLineString
      Since:
      4.9.0
    • multiPolygonToLine

      public static com.mapbox.geojson.FeatureCollection multiPolygonToLine(@NonNull com.mapbox.geojson.Feature feature)
      Takes a Feature that contains MultiPolygon and covert it to a FeatureCollection that contains list of Feature of LineString or MultiLineString.
      Parameters:
      feature - a Feature object that contains Polygon
      Returns:
      a FeatureCollection object that contains list of Feature of LineString or MultiLineString
      Since:
      4.9.0
    • multiPolygonToLine

      public static com.mapbox.geojson.FeatureCollection multiPolygonToLine(@NonNull com.mapbox.geojson.Feature feature, @Nullable com.google.gson.JsonObject properties)
      Takes a Feature that contains MultiPolygon and a properties JsonObject and covert it to a FeatureCollection that contains list of Feature of LineString or MultiLineString.
      Parameters:
      feature - a Feature object that contains MultiPolygon
      properties - a JsonObject that represents a feature's properties
      Returns:
      a FeatureCollection object that contains list of Feature of LineString or MultiLineString
      Since:
      4.9.0
    • combine

      public static com.mapbox.geojson.FeatureCollection combine(@NonNull com.mapbox.geojson.FeatureCollection originalFeatureCollection)

      Combines a FeatureCollection of geometries and returns a FeatureCollection with "Multi-" geometries in it. If the original FeatureCollection parameter has Point(s) and/or MultiPoints), the returned FeatureCollection will include a MultiPoint object.

      If the original FeatureCollection parameter has LineString(s) and/or MultiLineStrings), the returned FeatureCollection will include a MultiLineString object.

      If the original FeatureCollection parameter has Polygon(s) and/or MultiPolygons), the returned FeatureCollection will include a MultiPolygon object.

      Parameters:
      originalFeatureCollection - a FeatureCollection
      Returns:
      a FeatureCollection with a "Multi-" geometry or "Multi-" geometries.
      Since:
      4.10.0