Package org.openstreetmap.josm.data
Class Bounds
- java.lang.Object
-
- org.openstreetmap.josm.data.Bounds
-
- All Implemented Interfaces:
IBounds
- Direct Known Subclasses:
SourceBounds
public class Bounds extends java.lang.Object implements IBounds
This is a simple data class for "rectangular" areas of the world, given in lat/lon min/max values. The values are rounded to server precision- See Also:
to represent invalid areas.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Bounds.ParseMethod
The method used by theBounds(String, String, ParseMethod)
constructor
-
Constructor Summary
Constructors Constructor Description Bounds(double... coords)
Constructs bounds out of two points.Bounds(double[] coords, boolean roundToOsmPrecision)
Constructs bounds out of two points.Bounds(double lat, double lon, boolean roundToOsmPrecision)
Single point Bounds defined by point [lat,lon].Bounds(double minLat, double minLon, double maxLat, double maxLon)
Constructs bounds out of two points.Bounds(double minLat, double minLon, double maxLat, double maxLon, boolean roundToOsmPrecision)
Constructs bounds out of two points.Bounds(java.awt.geom.Rectangle2D rect)
Creates newBounds
from a rectangle.Bounds(java.lang.String asString, java.lang.String separator)
Parse the bounds in orderBounds.ParseMethod.MINLAT_MINLON_MAXLAT_MAXLON
Bounds(java.lang.String asString, java.lang.String separator, Bounds.ParseMethod parseMethod)
Parse the bounds from a given string and round to OSM precisionBounds(java.lang.String asString, java.lang.String separator, Bounds.ParseMethod parseMethod, boolean roundToOsmPrecision)
Parse the bounds from a given stringBounds(Bounds other)
Creates newBounds
from an existing one.Bounds(LatLon b)
Constructs bounds out a single point.Bounds(LatLon b, boolean roundToOsmPrecision)
Single point Bounds defined by lat/lonb
.Bounds(LatLon center, double latExtent, double lonExtent)
Creates new bounds around a coordinate paircenter
.Bounds(LatLon min, LatLon max)
Construct bounds out of two points.Bounds(LatLon min, LatLon max, boolean roundToOsmPrecision)
Constructs bounds out of two points.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.geom.Rectangle2D.Double
asRect()
Converts the lat/lon bounding box to an object of type Rectangle2D.Doubleboolean
contains(ILatLon ll)
Determines if the given pointll
is within these bounds.boolean
contains(LatLon ll)
Determines if the given pointll
is within these bounds.boolean
crosses180thMeridian()
Determines if this Bounds object crosses the 180th Meridian.java.lang.String
encodeAsString(java.lang.String separator)
Encodes this as a string so that it may be parsed using theBounds.ParseMethod.MINLAT_MINLON_MAXLAT_MAXLON
orderboolean
equals(java.lang.Object obj)
void
extend(double lat, double lon)
Extend the bounds if necessary to include the given point [lat,lon].void
extend(Bounds b)
Extends this bounds to enclose an other bounding boxvoid
extend(LatLon ll)
Extend the bounds if necessary to include the given point.double
getArea()
Gets the area of this bounds (in lat/lon space)LatLon
getCenter()
Returns center of the bounding box.double
getHeight()
Returns the bounds width.LatLon
getMax()
Gets the point that has both the maximum lat and lon coordinatedouble
getMaxLat()
Returns max latitude of bounds.double
getMaxLon()
Returns max longitude of bounds.LatLon
getMin()
Gets the point that has both the minimal lat and lon coordinatedouble
getMinLat()
Returns min latitude of bounds.double
getMinLon()
Returns min longitude of bounds.double
getWidth()
Returns the bounds width.int
hashCode()
protected static double
initLat(double value, boolean roundToOsmPrecision)
protected static double
initLon(double value, boolean roundToOsmPrecision)
boolean
intersects(Bounds b)
The two bounds intersect? Compared to java Shape.intersects, if does not use the interior but the closure.boolean
intersects(IBounds b)
The two bounds intersect? Compared to java Shape.intersects, if does not use the interior but the closure.private static boolean
intersectsLonCrossing(IBounds crossing, IBounds notCrossing)
boolean
isCollapsed()
Replies true, if this bounds are collapsed, i.e.boolean
isOutOfTheWorld()
Determines if these bounds are out of the world.void
normalize()
Clamp the bounds to be inside the world.BBox
toBBox()
Creates BBox with same coordinates.java.lang.String
toShortString(java.text.DecimalFormat format)
Converts this bounds to a human readable short stringjava.lang.String
toString()
-
-
-
Constructor Detail
-
Bounds
public Bounds(LatLon min, LatLon max)
Construct bounds out of two points. Coords will be rounded.- Parameters:
min
- min lat/lonmax
- max lat/lon
-
Bounds
public Bounds(LatLon min, LatLon max, boolean roundToOsmPrecision)
Constructs bounds out of two points.- Parameters:
min
- min lat/lonmax
- max lat/lonroundToOsmPrecision
- defines if lat/lon will be rounded
-
Bounds
public Bounds(LatLon b)
Constructs bounds out a single point. Coords will be rounded.- Parameters:
b
- lat/lon
-
Bounds
public Bounds(LatLon b, boolean roundToOsmPrecision)
Single point Bounds defined by lat/lonb
. Coordinates will be rounded to osm precision ifroundToOsmPrecision
is true.- Parameters:
b
- lat/lon of given point.roundToOsmPrecision
- defines if lat/lon will be rounded.
-
Bounds
public Bounds(double lat, double lon, boolean roundToOsmPrecision)
Single point Bounds defined by point [lat,lon]. Coordinates will be rounded to osm precision ifroundToOsmPrecision
is true.- Parameters:
lat
- latitude of given point.lon
- longitude of given point.roundToOsmPrecision
- defines if lat/lon will be rounded.- Since:
- 6203
-
Bounds
public Bounds(double minLat, double minLon, double maxLat, double maxLon)
Constructs bounds out of two points. Coords will be rounded.- Parameters:
minLat
- min latminLon
- min lonmaxLat
- max latmaxLon
- max lon
-
Bounds
public Bounds(double minLat, double minLon, double maxLat, double maxLon, boolean roundToOsmPrecision)
Constructs bounds out of two points.- Parameters:
minLat
- min latminLon
- min lonmaxLat
- max latmaxLon
- max lonroundToOsmPrecision
- defines if lat/lon will be rounded
-
Bounds
public Bounds(double... coords)
Constructs bounds out of two points. Coords will be rounded.- Parameters:
coords
- exactly 4 values: min lat, min lon, max lat, max lon- Throws:
java.lang.IllegalArgumentException
- if coords does not contain 4 double values
-
Bounds
public Bounds(double[] coords, boolean roundToOsmPrecision)
Constructs bounds out of two points.- Parameters:
coords
- exactly 4 values: min lat, min lon, max lat, max lonroundToOsmPrecision
- defines if lat/lon will be rounded- Throws:
java.lang.IllegalArgumentException
- if coords does not contain 4 double values
-
Bounds
public Bounds(java.lang.String asString, java.lang.String separator)
Parse the bounds in orderBounds.ParseMethod.MINLAT_MINLON_MAXLAT_MAXLON
- Parameters:
asString
- The stringseparator
- The separation regex
-
Bounds
public Bounds(java.lang.String asString, java.lang.String separator, Bounds.ParseMethod parseMethod)
Parse the bounds from a given string and round to OSM precision- Parameters:
asString
- The stringseparator
- The separation regexparseMethod
- The order of the numbers
-
Bounds
public Bounds(java.lang.String asString, java.lang.String separator, Bounds.ParseMethod parseMethod, boolean roundToOsmPrecision)
Parse the bounds from a given string- Parameters:
asString
- The stringseparator
- The separation regexparseMethod
- The order of the numbersroundToOsmPrecision
- Whether to round to OSM precision
-
Bounds
public Bounds(Bounds other)
Creates newBounds
from an existing one.- Parameters:
other
- The bounds to copy
-
Bounds
public Bounds(java.awt.geom.Rectangle2D rect)
Creates newBounds
from a rectangle.- Parameters:
rect
- The rectangle
-
Bounds
public Bounds(LatLon center, double latExtent, double lonExtent)
Creates new bounds around a coordinate paircenter
. The new bounds shall have an extension in latitude direction oflatExtent
, and in longitude direction oflonExtent
.- Parameters:
center
- the center coordinate pair. Must not be null.latExtent
- the latitude extent. > 0 required.lonExtent
- the longitude extent. > 0 required.- Throws:
java.lang.IllegalArgumentException
- if center is nulljava.lang.IllegalArgumentException
- if latExtent <= 0java.lang.IllegalArgumentException
- if lonExtent <= 0
-
-
Method Detail
-
getMinLat
public double getMinLat()
Returns min latitude of bounds. Efficient shortcut forgetMin().lat()
.
-
getMinLon
public double getMinLon()
Returns min longitude of bounds. Efficient shortcut forgetMin().lon()
.
-
getMaxLat
public double getMaxLat()
Returns max latitude of bounds. Efficient shortcut forgetMax().lat()
.
-
getMaxLon
public double getMaxLon()
Returns max longitude of bounds. Efficient shortcut forgetMax().lon()
.
-
initLat
protected static double initLat(double value, boolean roundToOsmPrecision)
-
initLon
protected static double initLon(double value, boolean roundToOsmPrecision)
-
toBBox
public BBox toBBox()
Creates BBox with same coordinates.- Returns:
- BBox with same coordinates.
- Since:
- 6203
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toShortString
public java.lang.String toShortString(java.text.DecimalFormat format)
Converts this bounds to a human readable short string- Parameters:
format
- The number format to use- Returns:
- The string
-
extend
public void extend(LatLon ll)
Extend the bounds if necessary to include the given point.- Parameters:
ll
- The point to include into these bounds
-
extend
public void extend(double lat, double lon)
Extend the bounds if necessary to include the given point [lat,lon]. Good to use if you know coordinates to avoid creation of LatLon object.- Parameters:
lat
- Latitude of point to include into these boundslon
- Longitude of point to include into these bounds- Since:
- 6203
-
extend
public void extend(Bounds b)
Extends this bounds to enclose an other bounding box- Parameters:
b
- The other bounds to enclose
-
contains
public boolean contains(LatLon ll)
Determines if the given pointll
is within these bounds.Points with unknown coordinates are always outside the coordinates.
- Parameters:
ll
- The lat/lon to check- Returns:
true
ifll
is within these bounds,false
otherwise
-
contains
public boolean contains(ILatLon ll)
Determines if the given pointll
is within these bounds.Points with unknown coordinates are always outside the coordinates.
-
intersectsLonCrossing
private static boolean intersectsLonCrossing(IBounds crossing, IBounds notCrossing)
-
intersects
public boolean intersects(Bounds b)
The two bounds intersect? Compared to java Shape.intersects, if does not use the interior but the closure. (">=" instead of ">")- Parameters:
b
- other bounds- Returns:
true
if the two bounds intersect
-
intersects
public boolean intersects(IBounds b)
Description copied from interface:IBounds
The two bounds intersect? Compared to java Shape.intersects, if does not use the interior but the closure. (">=" instead of ">")- Specified by:
intersects
in interfaceIBounds
- Parameters:
b
- other bounds- Returns:
true
if the two bounds intersect
-
crosses180thMeridian
public boolean crosses180thMeridian()
Determines if this Bounds object crosses the 180th Meridian. See 180th Meridian.- Specified by:
crosses180thMeridian
in interfaceIBounds
- Returns:
- true if this Bounds object crosses the 180th Meridian.
-
asRect
public java.awt.geom.Rectangle2D.Double asRect()
Converts the lat/lon bounding box to an object of type Rectangle2D.Double- Returns:
- the bounding box to Rectangle2D.Double
-
getHeight
public double getHeight()
Returns the bounds width.
-
getWidth
public double getWidth()
Returns the bounds width.
-
getArea
public double getArea()
Gets the area of this bounds (in lat/lon space)
-
encodeAsString
public java.lang.String encodeAsString(java.lang.String separator)
Encodes this as a string so that it may be parsed using theBounds.ParseMethod.MINLAT_MINLON_MAXLAT_MAXLON
order- Parameters:
separator
- The separator- Returns:
- The string encoded bounds
-
isCollapsed
public boolean isCollapsed()
Replies true, if this bounds are collapsed, i.e. if the min and the max corner are equal.
- Returns:
- true, if this bounds are collapsed
-
isOutOfTheWorld
public boolean isOutOfTheWorld()
Determines if these bounds are out of the world.- Returns:
- true if lat outside of range [-90,90] or lon outside of range [-180,180]
-
normalize
public void normalize()
Clamp the bounds to be inside the world.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-