Package com.mapbox.turf
Class TurfConversion
java.lang.Object
com.mapbox.turf.TurfConversion
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 TypeMethodDescriptionstatic com.mapbox.geojson.FeatureCollectioncombine(com.mapbox.geojson.FeatureCollection originalFeatureCollection) Combines a FeatureCollection of geometries and returns aFeatureCollectionwith "Multi-" geometries in it.static doubleconvertLength(double distance, String originalUnit) Converts a distance to the default units.static doubleconvertLength(double distance, String originalUnit, String finalUnit) Converts a distance to a different unit specified.static doubledegreesToRadians(double degrees) Converts an angle in degrees to radians.static com.mapbox.geojson.FeatureCollectionexplode(com.mapbox.geojson.Feature feature) Takes aFeatureand returns its position as aPointobjects.static com.mapbox.geojson.FeatureCollectionexplode(com.mapbox.geojson.FeatureCollection featureCollection) Takes aFeatureCollectionand returns all positions asPointobjects.static doublelengthToDegrees(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 doublelengthToRadians(double distance) Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians.static doublelengthToRadians(double distance, String units) Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians.static com.mapbox.geojson.FeatureCollectionmultiPolygonToLine(com.mapbox.geojson.Feature feature) Takes aFeaturethat containsMultiPolygonand covert it to aFeatureCollectionthat contains list ofFeatureofLineStringorMultiLineString.static com.mapbox.geojson.FeatureCollectionmultiPolygonToLine(com.mapbox.geojson.Feature feature, com.google.gson.JsonObject properties) Takes aFeaturethat containsMultiPolygonand a propertiesJsonObjectand covert it to aFeatureCollectionthat contains list ofFeatureofLineStringorMultiLineString.static com.mapbox.geojson.FeaturepolygonToLine(com.mapbox.geojson.Feature feature) Takes aFeaturethat containsPolygonand covert it to aFeaturethat containsLineStringorMultiLineString.static com.mapbox.geojson.FeaturepolygonToLine(com.mapbox.geojson.Feature feature, com.google.gson.JsonObject properties) Takes aFeaturethat containsPolygonand a propertiesJsonObjectand covert it to aFeaturethat containsLineStringorMultiLineString.static com.mapbox.geojson.FeatureCollectionpolygonToLine(com.mapbox.geojson.MultiPolygon multiPolygon) Takes aMultiPolygonand covert it to aFeatureCollectionthat contains list ofFeatureofLineStringorMultiLineString.static com.mapbox.geojson.FeatureCollectionpolygonToLine(com.mapbox.geojson.MultiPolygon multiPolygon, com.google.gson.JsonObject properties) Takes aMultiPolygonand a propertiesJsonObjectand covert it to aFeatureCollectionthat contains list ofFeatureofLineStringorMultiLineString.static com.mapbox.geojson.FeaturepolygonToLine(com.mapbox.geojson.Polygon polygon) Takes aPolygonand covert it to aFeaturethat containsLineStringorMultiLineString.static com.mapbox.geojson.FeaturepolygonToLine(com.mapbox.geojson.Polygon polygon, com.google.gson.JsonObject properties) Takes aPolygonand a propertiesJsonObjectand covert it to aFeaturethat containsLineStringorMultiLineString.static doubleradiansToDegrees(double radians) Converts an angle in radians to degrees.static doubleradiansToLength(double radians) Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.static doubleradiansToLength(double radians, String units) Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
-
Method Details
-
lengthToDegrees
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 unitsunits- 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
Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.- Parameters:
radians- a double using unit radianunits- pass in one of the units defined inTurfConstants.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
Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians.- Parameters:
distance- double representing a distance valueunits- pass in one of the units defined inTurfConstants.TurfUnitCriteria- Returns:
- converted distance to radians value
- Since:
- 1.2.0
-
convertLength
Converts a distance to the default units. UseconvertLength(double, String, String)to specify a unit to convert to.- Parameters:
distance- double representing a distance valueoriginalUnit- of the distance, must be one of the units defined inTurfConstants.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 convertedoriginalUnit- of the distance, must be one of the units defined inTurfConstants.TurfUnitCriteriafinalUnit- returned unit,TurfConstants.UNIT_DEFAULTif 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 aFeatureCollectionand returns all positions asPointobjects.- Parameters:
featureCollection- aFeatureCollectionobject- Returns:
- a new
FeatureCollectionobject withPointobjects - Since:
- 4.8.0
-
explode
public static com.mapbox.geojson.FeatureCollection explode(@NonNull com.mapbox.geojson.Feature feature) Takes aFeatureand returns its position as aPointobjects.- Parameters:
feature- aFeatureobject- Returns:
- a new
FeatureCollectionobject withPointobjects - Since:
- 4.8.0
-
polygonToLine
public static com.mapbox.geojson.Feature polygonToLine(@NonNull com.mapbox.geojson.Feature feature) Takes aFeaturethat containsPolygonand covert it to aFeaturethat containsLineStringorMultiLineString.- Parameters:
feature- aFeatureobject that containsPolygon- Returns:
- a
Featureobject that containsLineStringorMultiLineString - 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 aFeaturethat containsPolygonand a propertiesJsonObjectand covert it to aFeaturethat containsLineStringorMultiLineString.- Parameters:
feature- aFeatureobject that containsPolygonproperties- aJsonObjectthat represents a feature's properties- Returns:
- a
Featureobject that containsLineStringorMultiLineString - Since:
- 4.9.0
-
polygonToLine
public static com.mapbox.geojson.Feature polygonToLine(@NonNull com.mapbox.geojson.Polygon polygon) Takes aPolygonand covert it to aFeaturethat containsLineStringorMultiLineString.- Parameters:
polygon- aPolygonobject- Returns:
- a
Featureobject that containsLineStringorMultiLineString - Since:
- 4.9.0
-
polygonToLine
public static com.mapbox.geojson.FeatureCollection polygonToLine(@NonNull com.mapbox.geojson.MultiPolygon multiPolygon) Takes aMultiPolygonand covert it to aFeatureCollectionthat contains list ofFeatureofLineStringorMultiLineString.- Parameters:
multiPolygon- aMultiPolygonobject- Returns:
- a
FeatureCollectionobject that contains list ofFeatureofLineStringorMultiLineString - 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 aPolygonand a propertiesJsonObjectand covert it to aFeaturethat containsLineStringorMultiLineString.- Parameters:
polygon- aPolygonobjectproperties- aJsonObjectthat represents a feature's properties- Returns:
- a
Featureobject that containsLineStringorMultiLineString - 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 aMultiPolygonand a propertiesJsonObjectand covert it to aFeatureCollectionthat contains list ofFeatureofLineStringorMultiLineString.- Parameters:
multiPolygon- aMultiPolygonobjectproperties- aJsonObjectthat represents a feature's properties- Returns:
- a
FeatureCollectionobject that contains list ofFeatureofLineStringorMultiLineString - Since:
- 4.9.0
-
multiPolygonToLine
public static com.mapbox.geojson.FeatureCollection multiPolygonToLine(@NonNull com.mapbox.geojson.Feature feature) Takes aFeaturethat containsMultiPolygonand covert it to aFeatureCollectionthat contains list ofFeatureofLineStringorMultiLineString.- Parameters:
feature- aFeatureobject that containsPolygon- Returns:
- a
FeatureCollectionobject that contains list ofFeatureofLineStringorMultiLineString - 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 aFeaturethat containsMultiPolygonand a propertiesJsonObjectand covert it to aFeatureCollectionthat contains list ofFeatureofLineStringorMultiLineString.- Parameters:
feature- aFeatureobject that containsMultiPolygonproperties- aJsonObjectthat represents a feature's properties- Returns:
- a
FeatureCollectionobject that contains list ofFeatureofLineStringorMultiLineString - 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
FeatureCollectionwith "Multi-" geometries in it. If the original FeatureCollection parameter hasPoint(s) and/orMultiPoints), the returned FeatureCollection will include aMultiPointobject.If the original FeatureCollection parameter has
LineString(s) and/orMultiLineStrings), the returned FeatureCollection will include aMultiLineStringobject.If the original FeatureCollection parameter has
Polygon(s) and/orMultiPolygons), the returned FeatureCollection will include aMultiPolygonobject.- Parameters:
originalFeatureCollection- aFeatureCollection- Returns:
- a
FeatureCollectionwith a "Multi-" geometry or "Multi-" geometries. - Since:
- 4.10.0
-