Class CountryBoundaries

java.lang.Object
de.westnordost.countryboundaries.CountryBoundaries

public class CountryBoundaries extends Object
  • Method Details

    • load

      public static CountryBoundaries load(InputStream is) throws IOException
      Throws:
      IOException
    • isInAny

      public boolean isInAny(double longitude, double latitude, Collection<String> ids)
      Parameters:
      longitude - longitude of geo position (-180...180)
      latitude - latitude of geo position (-90...90)
      ids - ids of the countries to look for. Note that if you have many ids, you should use a Set to increase performance
      Returns:
      whether the given position is in any of the countries with the given ids
      Throws:
      IllegalArgumentException - if any parameter is not finite (NaN or Infinite) or latitude is not between -90.0 and +90.0
    • isIn

      public boolean isIn(double longitude, double latitude, String id)
      Parameters:
      longitude - longitude of geo position (-180...180)
      latitude - latitude of geo position (-90...90)
      id - id of the country to look for
      Returns:
      whether the given position is in the country with the given id
      Throws:
      IllegalArgumentException - if any parameter is not finite (NaN or Infinite) or latitude is not between -90.0 and +90.0
    • getIds

      public List<String> getIds(double longitude, double latitude)
      Parameters:
      longitude - longitude of geo position (-180...180)
      latitude - latitude of geo position (-90...90)
      Returns:
      the ids of the countries the given position is contained in, ordered by size ascending
    • getContainingIds

      public Set<String> getContainingIds(double minLongitude, double minLatitude, double maxLongitude, double maxLatitude)
      Identify which countries are guaranteed to contain the given bounding box fully. The given bounding box may wrap around the 180th longitude, i.e minLongitude = 170 and maxLongitude = -170.
      Parameters:
      minLongitude - minimum longitude of geo position (-180...180)
      minLatitude - minimum latitude of geo position (-90...90)
      maxLongitude - maximum longitude of geo position (-180...180)
      maxLatitude - maximum latitude of geo position (-90...90)
      Returns:
      the ids of the countries the given bounding box is guaranteed to be contained in, not in any particular order
      Throws:
      IllegalArgumentException - if any parameter is not finite (NaN or Infinite), minLatitude is greater than maxLatitude or any latitude is not between -90.0 and +90.0
    • getIntersectingIds

      public Set<String> getIntersectingIds(double minLongitude, double minLatitude, double maxLongitude, double maxLatitude)
      Identify which countries may intersect with the given bounding box. In other words, any point within the given bounding box can only be in any of the returned countries (or none). So, from the technical point of view, it just returns which countries are in the same cell(s) of the raster as the bounding box. The given bounding box may wrap around the 180th longitude, i.e minLongitude = 170 and maxLongitude = -170.
      Parameters:
      minLongitude - minimum longitude of geo position (-180...180)
      minLatitude - minimum latitude of geo position (-90...90)
      maxLongitude - maximum longitude of geo position (-180...180)
      maxLatitude - maximum latitude of geo position (-90...90)
      Returns:
      the ids of the countries the given bounding box may intersects with, not in any particular order
      Throws:
      IllegalArgumentException - if any parameter is not finite (NaN or Infinite), minLatitude is greater than maxLatitude or any latitude is not between -90.0 and +90.0
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object