Class MapUtil

java.lang.Object
com.imc.iss.maps.MapUtil

public final class MapUtil extends Object
  • Field Details

    • EARTH_RADIUS

      public static double EARTH_RADIUS
      The radius of the earth used in all of the calculations, in meter
  • Constructor Details

    • MapUtil

      public MapUtil(BaseContext ctx)
  • Method Details

    • addLineString

      public static String addLineString(String geojson, LatLng[] latLngs)
      Add a LineString geometry object into the GeoJSON
      Parameters:
      geojson - The GeoJSON to be modified
      latLngs - The list of coordinate points that makes up the LineString
      Returns:
      The updated GeoJSON string
    • addLineString

      public static String addLineString(String geojson, LatLng[] latLngs, Map<String,Object> properties)
      Add a LineString geometry object into the GeoJSON with properties
      Parameters:
      geojson - The GeoJSON to be modified
      latLngs - The list of coordinate points that makes up the LineString
      properties - The list of key-value pairs to be set as the LineString's properties
      Returns:
      The updated GeoJSON string
    • addLineString

      public static String addLineString(String geojson, LatLng[] latLngs, String typeUri)
      Add a LineString geometry object into the GeoJSON with a type
      Parameters:
      geojson - The GeoJSON to be modified
      latLngs - The list of coordinate points that makes up the LineString
      typeUri - 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 modified
      latLngs - The list of coordinate points that makes up the LineString
      typeUri - The URI of the Geographical Line Type master data to assign for this LineString
      properties - The list of key-value pairs to be set as the LineString's properties
      Returns:
      The updated GeoJSON string
    • addPoint

      public static String addPoint(String geojson, LatLng latLng)
      Add a Point geometry object into the GeoJSON
      Parameters:
      geojson - The GeoJSON to be modified
      latLng - The coordinate of the Point
      Returns:
      The updated GeoJSON string
    • addPoint

      public static String addPoint(String geojson, LatLng latLng, Map<String,Object> properties)
      Add a Point geometry object into the GeoJSON with properties
      Parameters:
      geojson - The GeoJSON to be modified
      latLng - The coordinate of the Point
      properties - The list of key-value pairs to be set as the Point properties
      Returns:
      The updated GeoJSON string
    • addPoint

      public static String addPoint(String geojson, LatLng latLng, String typeUri)
      Add a Point geometry object into the GeoJSON with a type
      Parameters:
      geojson - The GeoJSON to be modified
      latLng - The coordinate of the Point
      typeUri - 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 modified
      latLng - The coordinate of the Point
      typeUri - The URI of the Geographical Point Type master data to assign for this Point
      properties - The list of key-value pairs to be set as the Point properties
      Returns:
      The updated GeoJSON string
    • addTextString

      public static String addTextString(String geojson, LatLng latLng, String text)
      Add a TextString geometry object into the GeoJSON
      Parameters:
      geojson - The GeoJSON to be modified
      latLng - The coordinate of the Point
      text - 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 modified
      latLng - The coordinate of the TextString
      typeUri - The URI of the Geographical TextString Type master data to assign for this Point
      properties - 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 point
      p2 - 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 Point
      polygon - 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 point
      to - 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 point
      distance - The distance to move, in meter
      heading - The direction to move, expressed in degrees clockwise from North within the range [-180,180)
      Returns:
      The coordinate of the resulting point
    • getAllLineStringsVertices

      public 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.

      If the GeoJSON does not contain such a LineString, it will return an empty List.
      Parameters:
      geojson - The GeoJSON to be read
      typeUri - 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

      public static List<LatLng> getAllMarkersCoordinate(String geojson, String typeUri)
      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 read
      typeUri - The URI of the type master data that has been assigned to the Point
      Returns:
      List of the coordinates of the Points
    • getAllPolygonsVertices

      public 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.

      If the GeoJSON does not contain such a Polygon, it will return an empty List.
      Parameters:
      geojson - The GeoJSON to be read
      typeUri - 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 Point
      polygon - 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:
      IOException
      ApiException
      InterruptedException
      IMCException
    • getFeatureProperty

      public static Object getFeatureProperty(String geojson, String typeUri, String propertyName)
      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 read
      typeUri - The URI of the type master data that has been assigned to the feature
      propertyName - The name of the property to retrieve
      Returns:
      The value of the property
    • getLineStringVertices

      public static LatLng[] getLineStringVertices(String geojson, String typeUri)
      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 read
      typeUri - 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

      public static LatLng getMarkerCoordinate(String geojson, String typeUri)
      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 read
      typeUri - The URI of the type master data that has been assigned to the Point
      Returns:
      The coordinate of the Point
    • getPolygonVertices

      public static LatLng[] getPolygonVertices(String geojson, String typeUri)
      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 read
      typeUri - 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 point
      to - The coordinate of the ending point
      fraction -
      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 point
      polygon - The list of coordinates of the polygon's vertex
      Returns:
      The coordinate of the resulting point
    • isUsingImperialUnits

      public static boolean isUsingImperialUnits(String geojson)
      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

      public static boolean isUsingMetricUnits(String geojson)
      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 point
      line_endA - The coordinate of the starting point of the line
      line_endB - The coordinate of the ending point of the line
      Returns:
      The coordinate of the resulting point
    • removeFeatureById

      public static String removeFeatureById(String geojson, String id)
      Remove the feature that has the given feature id
      Parameters:
      geojson - The GeoJSON to be modified
      id - The id of the feature
      Returns:
      The updated GeoJSON string
    • removeFeatureByType

      public static String removeFeatureByType(String geojson, String typeURI)
      Remove the feature that has the given type
      Parameters:
      geojson - The GeoJSON to be modified
      typeUri - 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 modified
      typeUri - The URI of the type master data that has been assigned to the feature
      propertyName - The name of the property to be updated
      propertyValue - The value of the property to be updated
      Returns:
      The updated GeoJSON string