All Downloads are FREE. Search and download functionalities are using the official Maven repository.

berlin.softwaretechnik.geojsonrenderer.GeoBoundingBox.scala Maven / Gradle / Ivy

The newest version!
package berlin.softwaretechnik.geojsonrenderer

import berlin.softwaretechnik.geojsonrenderer.Math._

case class GeoBoundingBox(west: Double,
                          south: Double,
                          east: Double,
                          north: Double) {
  assert(-90 <= south && south <= north && north <= 90, s"Invalid or inconsistent latitudes: $this")
  assert(-180 <= west && west <= 180, s"Invalid west longitude: $this")
  assert(-180 <= east && east <= 180, s"Invalid east longitude: $this")

  def upperLeft(): GeoCoord = GeoCoord(north, west)
  def lowerRight(): GeoCoord = GeoCoord(south, east)

  def centralLongitude: Double =
    GeoCoord.normalizeLongitude(
      west + floorMod(east - west, 360) / 2
    )
}

object GeoBoundingBox {

  def apply(coordinates: Seq[GeoCoord]): GeoBoundingBox = {
    import Ordering.Double.IeeeOrdering
    GeoBoundingBox(
      west = GeoCoord.normalizeLongitude(coordinates.map(_.lon).min),
      south = coordinates.map(_.lat).min,
      east = GeoCoord.normalizeLongitude(coordinates.map(_.lon).max),
      north = coordinates.map(_.lat).max
    )
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy