Package com.imc.iss.maps
Class MapUtil
java.lang.Object
com.imc.iss.maps.MapUtil
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic doubleThe radius of the earth used in all of the calculations, in meter -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringaddLineString(String geojson, LatLng[] latLngs) Add a LineString geometry object into the GeoJSONstatic StringaddLineString(String geojson, LatLng[] latLngs, String typeUri) Add a LineString geometry object into the GeoJSON with a typestatic StringAdd a LineString geometry object into the GeoJSON with a type and propertiesstatic StringaddLineString(String geojson, LatLng[] latLngs, Map<String, Object> properties) Add a LineString geometry object into the GeoJSON with propertiesstatic StringAdd a Point geometry object into the GeoJSONstatic StringAdd a Point geometry object into the GeoJSON with a typestatic StringAdd a Point geometry object into the GeoJSON with a type and propertiesstatic StringAdd a Point geometry object into the GeoJSON with propertiesstatic StringaddTextString(String geojson, LatLng latLng, String text) Add a TextString geometry object into the GeoJSONstatic StringAdd a TextString geometry object into the GeoJSON with propertiesstatic doublecomputeDistance(LatLng p1, LatLng p2) Compute the surface distance between two coordinates.static doublecomputeDistanceToPolygon(LatLng point, LatLng[] polygon) Returns the closest distance between the given point and polygon.static doublecomputeHeading(LatLng from, LatLng to) Compute the heading from point 1 to point 2.static LatLngcomputeOffset(LatLng from, double distance, double heading) Compute the coordinate of the point that would be the result of moving a certain distance from a point in the given direction.static List<LatLng[]>getAllLineStringsVertices(String geojson, String typeUri) Gets the coordinates of the vertices of all the LineStrings that have been assigned a particular type.static List<LatLng>getAllMarkersCoordinate(String geojson, String typeUri) Gets the coordinate of all the Points that have been assigned a particular type.static List<LatLng[]>getAllPolygonsVertices(String geojson, String typeUri) Gets the coordinates of the vertices of all the Polygons that have been assigned a particular type.static LatLnggetClosestPointOnPolygon(LatLng point, LatLng[] polygon) Returns the coordinate on a polygon that is closest to the given point.getElevations(LatLng[] points) Retrieves the elevation data for the given coordinates.static ObjectgetFeatureProperty(String geojson, String typeUri, String propertyName) Gets a property of the feature that has been assigned a particular type.static LatLng[]getLineStringVertices(String geojson, String typeUri) Gets the coordinates of the vertices of the LineString that has been assigned a particular type.static LatLnggetMarkerCoordinate(String geojson, String typeUri) Gets the coordinate of the Point that has been assigned a particular type.static LatLng[]getPolygonVertices(String geojson, String typeUri) Gets the coordinates of the vertices of the Polygon that has been assigned a particular type.static LatLnginterpolate(LatLng from, LatLng to, double fraction) Compute the coordinate of the point which lies the given fraction of the way between the origin and the ending point.static booleanisPointInsidePolygon(LatLng point, LatLng[] polygon) Checks if point lies on or inside a closed polygon.static booleanisUsingImperialUnits(String geojson) Whether the properties in the GeoJSON is in terms of Imperial units (i.e.static booleanisUsingMetricUnits(String geojson) Whether the properties in the GeoJSON is in terms of Metric units (i.e.static LatLngprojectPointToLine(LatLng point, LatLng line_endA, LatLng line_endB) Compute the coordinate of the point which is the projection of a point to a line.static StringremoveFeatureById(String geojson, String id) Remove the feature that has the given feature idstatic StringremoveFeatureByType(String geojson, String typeURI) Remove the feature that has the given typestatic StringupdateFeatureProperty(String geojson, String typeURI, String propertyName, Object propertyValue) Updates the property of the feature that has the given type
-
Field Details
-
EARTH_RADIUS
public static double EARTH_RADIUSThe radius of the earth used in all of the calculations, in meter
-
-
Constructor Details
-
MapUtil
public MapUtil(BaseContext ctx)
-
-
Method Details
-
addLineString
Add a LineString geometry object into the GeoJSON- Parameters:
geojson- The GeoJSON to be modifiedlatLngs- The list of coordinate points that makes up the LineString- Returns:
- The updated GeoJSON string
-
addLineString
Add a LineString geometry object into the GeoJSON with properties- Parameters:
geojson- The GeoJSON to be modifiedlatLngs- The list of coordinate points that makes up the LineStringproperties- The list of key-value pairs to be set as the LineString's properties- Returns:
- The updated GeoJSON string
-
addLineString
Add a LineString geometry object into the GeoJSON with a type- Parameters:
geojson- The GeoJSON to be modifiedlatLngs- The list of coordinate points that makes up the LineStringtypeUri- The URI of the Geographical Line Type master data to assign for this LineString- Returns:
- The updated GeoJSON string
-
addLineString
public static String addLineString(String geojson, LatLng[] latLngs, String typeUri, Map<String, Object> properties) Add a LineString geometry object into the GeoJSON with a type and properties- Parameters:
geojson- The GeoJSON to be modifiedlatLngs- The list of coordinate points that makes up the LineStringtypeUri- The URI of the Geographical Line Type master data to assign for this LineStringproperties- The list of key-value pairs to be set as the LineString's properties- Returns:
- The updated GeoJSON string
-
addPoint
Add a Point geometry object into the GeoJSON- Parameters:
geojson- The GeoJSON to be modifiedlatLng- The coordinate of the Point- Returns:
- The updated GeoJSON string
-
addPoint
Add a Point geometry object into the GeoJSON with properties- Parameters:
geojson- The GeoJSON to be modifiedlatLng- The coordinate of the Pointproperties- The list of key-value pairs to be set as the Point properties- Returns:
- The updated GeoJSON string
-
addPoint
Add a Point geometry object into the GeoJSON with a type- Parameters:
geojson- The GeoJSON to be modifiedlatLng- The coordinate of the PointtypeUri- The URI of the Geographical Point Type master data to assign for this Point- Returns:
- The updated GeoJSON string
-
addPoint
public static String addPoint(String geojson, LatLng latLng, String typeUri, Map<String, Object> properties) Add a Point geometry object into the GeoJSON with a type and properties- Parameters:
geojson- The GeoJSON to be modifiedlatLng- The coordinate of the PointtypeUri- The URI of the Geographical Point Type master data to assign for this Pointproperties- The list of key-value pairs to be set as the Point properties- Returns:
- The updated GeoJSON string
-
addTextString
Add a TextString geometry object into the GeoJSON- Parameters:
geojson- The GeoJSON to be modifiedlatLng- The coordinate of the Pointtext- Input text- Returns:
- The updated GeoJSON string
-
addTextString
public static String addTextString(String geojson, LatLng latLng, String text, Map<String, Object> properties) Add a TextString geometry object into the GeoJSON with properties- Parameters:
geojson- The GeoJSON to be modifiedlatLng- The coordinate of the TextStringtypeUri- The URI of the Geographical TextString Type master data to assign for this Pointproperties- The list of key-value pairs to be set as the TextString properties- Returns:
- The updated GeoJSON string
-
computeDistance
public static double computeDistance(LatLng p1, LatLng p2) Compute the surface distance between two coordinates.
The calculation takes into account the curvature of the Earth (approximated as a perfect sphere)- Parameters:
p1- The coordinate of the first pointp2- The coordinate of the second point- Returns:
- The surface distance in meter
-
computeDistanceToPolygon
public static double computeDistanceToPolygon(LatLng point, LatLng[] polygon) Returns the closest distance between the given point and polygon. If the point lies inside or on the polygon, the value will be zero.- Parameters:
point- The coordinate of the Pointpolygon- The coordinates array of the vertices of the Polygon- Returns:
- The coordinate of the closest point
-
computeHeading
public static double computeHeading(LatLng from, LatLng to) Compute the heading from point 1 to point 2.
The calculation takes into account the curvature of the Earth (approximated as a perfect sphere)- Parameters:
from- The coordinate of the origin pointto- The coordinate of the ending point- Returns:
- The heading expressed in degrees clockwise from North within the range [-180,180)
-
computeOffset
public static LatLng computeOffset(LatLng from, double distance, double heading) Compute the coordinate of the point that would be the result of moving a certain distance from a point in the given direction.
The calculation takes into account the curvature of the Earth (approximated as a perfect sphere)- Parameters:
from- The coordinate of the origin pointdistance- The distance to move, in meterheading- The direction to move, expressed in degrees clockwise from North within the range [-180,180)- Returns:
- The coordinate of the resulting point
-
getAllLineStringsVertices
Gets the coordinates of the vertices of all the LineStrings that have been assigned a particular type.
If the GeoJSON does not contain such a LineString, it will return an empty List.- Parameters:
geojson- The GeoJSON to be readtypeUri- The URI of the type master data that has been assigned to the LineString- Returns:
- List of the coordinates array of the vertices of the LineStrings
-
getAllMarkersCoordinate
Gets the coordinate of all the Points that have been assigned a particular type.
If the GeoJSON does not contain such a Point, it will return an empty List.- Parameters:
geojson- The GeoJSON to be readtypeUri- The URI of the type master data that has been assigned to the Point- Returns:
- List of the coordinates of the Points
-
getAllPolygonsVertices
Gets the coordinates of the vertices of all the Polygons that have been assigned a particular type.
If the GeoJSON does not contain such a Polygon, it will return an empty List.- Parameters:
geojson- The GeoJSON to be readtypeUri- The URI of the type master data that has been assigned to the Polygon- Returns:
- List of the coordinates array of the vertices of the Polygon
-
getClosestPointOnPolygon
public static LatLng getClosestPointOnPolygon(LatLng point, LatLng[] polygon) Returns the coordinate on a polygon that is closest to the given point. If the point lies inside the polygon, it will just be the coordinate of the point itself.- Parameters:
point- The coordinate of the Pointpolygon- The coordinates array of the vertices of the Polygon- Returns:
- The coordinate of the closest point
-
getElevations
public static Map<LatLng,Double> getElevations(LatLng[] points) throws IOException, ApiException, InterruptedException, IMCException Retrieves the elevation data for the given coordinates.
Note, each call of this method will be charged. Thus, it is best to merge multiple points and retrieves their elevation data together, instead of making multiple calls for each individual points.- Parameters:
points- The list of coordinates to get elevation data for- Returns:
- A map of coordinates to elevation data (in meter). Note that the coordinates in the output may not be exactly the same as the input coordinates, since Google has limited resolution for their elevation data
- Throws:
IOExceptionApiExceptionInterruptedExceptionIMCException
-
getFeatureProperty
Gets a property of the feature that has been assigned a particular type.
If the GeoJSON does not contain such a feature or the feature does not have such a property, it will return null. If there are multiple features having the same type, only the property value of first one will be returned- Parameters:
geojson- The GeoJSON to be readtypeUri- The URI of the type master data that has been assigned to the featurepropertyName- The name of the property to retrieve- Returns:
- The value of the property
-
getLineStringVertices
Gets the coordinates of the vertices of the LineString that has been assigned a particular type.
If the GeoJSON does not contain such a LineString, it will return null. If there are multiple LineStrings having the same type, only the coordinates of the vertices of the first one will be returned- Parameters:
geojson- The GeoJSON to be readtypeUri- The URI of the type master data that has been assigned to the LineString- Returns:
- The coordinates array of the vertices of the LineString
-
getMarkerCoordinate
Gets the coordinate of the Point that has been assigned a particular type.
If the GeoJSON does not contain such a Point, it will return null. If there are multiple Points having the same type, only the coordinate of first one will be returned- Parameters:
geojson- The GeoJSON to be readtypeUri- The URI of the type master data that has been assigned to the Point- Returns:
- The coordinate of the Point
-
getPolygonVertices
Gets the coordinates of the vertices of the Polygon that has been assigned a particular type.
If the GeoJSON does not contain such a Polygon, it will return null. If there are multiple Polygons having the same type, only the coordinates of the vertices of the first one will be returned- Parameters:
geojson- The GeoJSON to be readtypeUri- The URI of the type master data that has been assigned to the Polygon- Returns:
- The coordinates array of the vertices of the Polygon
-
interpolate
public static LatLng interpolate(LatLng from, LatLng to, double fraction) Compute the coordinate of the point which lies the given fraction of the way between the origin and the ending point.
The calculation takes into account the curvature of the Earth (approximated as a perfect sphere)- Parameters:
from- The coordinate of the origin pointto- The coordinate of the ending pointfraction-- Returns:
- The coordinate of the resulting point
-
isPointInsidePolygon
public static boolean isPointInsidePolygon(LatLng point, LatLng[] polygon) Checks if point lies on or inside a closed polygon. Inside is defined as not containing the South Pole -- the South Pole is always outside- Parameters:
point- The coordinate of the pointpolygon- The list of coordinates of the polygon's vertex- Returns:
- The coordinate of the resulting point
-
isUsingImperialUnits
Whether the properties in the GeoJSON is in terms of Imperial units (i.e. feet and acre)- Parameters:
geojson- The GeoJSON to be read
-
isUsingMetricUnits
Whether the properties in the GeoJSON is in terms of Metric units (i.e. meter and hectare)- Parameters:
geojson- The GeoJSON to be read
-
projectPointToLine
public static LatLng projectPointToLine(LatLng point, LatLng line_endA, LatLng line_endB) Compute the coordinate of the point which is the projection of a point to a line.
The calculation takes into account the curvature of the Earth (approximated as a perfect sphere)- Parameters:
point- The coordinate of the pointline_endA- The coordinate of the starting point of the lineline_endB- The coordinate of the ending point of the line- Returns:
- The coordinate of the resulting point
-
removeFeatureById
Remove the feature that has the given feature id- Parameters:
geojson- The GeoJSON to be modifiedid- The id of the feature- Returns:
- The updated GeoJSON string
-
removeFeatureByType
Remove the feature that has the given type- Parameters:
geojson- The GeoJSON to be modifiedtypeUri- The URI of the type master data that has been assigned to the feature- Returns:
- The updated GeoJSON string
-
updateFeatureProperty
public static String updateFeatureProperty(String geojson, String typeURI, String propertyName, Object propertyValue) Updates the property of the feature that has the given type- Parameters:
geojson- The GeoJSON to be modifiedtypeUri- The URI of the type master data that has been assigned to the featurepropertyName- The name of the property to be updatedpropertyValue- The value of the property to be updated- Returns:
- The updated GeoJSON string
-