Class DefaultGeographicBoundingBox
- All Implemented Interfaces:
Serializable, Emptiable, LenientComparable, IdentifiedObject, GeographicBoundingBox, GeographicExtent
The following properties are mandatory in a well-formed metadata according ISO 19115:
EX_GeographicBoundingBox
├─westBoundLongitude…… The western-most coordinate of the limit of the dataset extent.
├─eastBoundLongitude…… The eastern-most coordinate of the limit of the dataset extent.
├─southBoundLatitude…… The southern-most coordinate of the limit of the dataset extent.
└─northBoundLatitude…… The northern-most, coordinate of the limit of the dataset extent.setBounds(double, double, double, double)for setting the extent from (λ,φ) values.setBounds(Envelope)for setting the extent from the given envelope.setBounds(GeographicBoundingBox)for setting the extent from another bounding box.add(GeographicBoundingBox)for expanding this extent to include another bounding box.intersect(GeographicBoundingBox)for the intersection between the two bounding boxes.
Validation and normalization
All constructors and setter methods in this class perform the following argument validation or normalization:- If the south bound latitude is greater than the north bound latitude, then an exception is thrown.
- If any latitude is set to a value outside the [-90 … 90]° range, then that latitude will be clamped.
- If any longitude is set to a value outside the [-180 … 180]° range, then a multiple of 360° will be added or subtracted to that longitude in order to bring it back inside the range.
Relationship with Envelope classes
Theorg.apache.sis.geometry package provides various Envelope classes serving a similar purpose.
The main difference is that envelopes can be expressed in any Coordinate Reference System (for example using any map projection), may have any number of dimensions,
may have axes is any direction
(some maps are south-oriented), and may use any units of measurement.
By contrast, GeographicBoundingBox is restricted to two-dimensional
geographic CRS
with latitude and longitude in decimal degrees in the [-90 … +90]° and [-180 … +180]° range respectively,
increasing toward north and east respectively,
and with longitude measured from the international reference meridian (Greenwich).
However, GeographicBoundingBox said nothing about the
geodetic reference frame.
Consequently, this box should be used only as a convenient way to give an approximate description of a location.
Users can assume a precision of about 0.01° for the latitude and longitude values in this class.
If more precision is desired, an Envelope should be considered instead.
Limitations
- Instances of this class are not synchronized for multi-threading. Synchronization, if needed, is caller's responsibility.
- Serialized objects of this class are not guaranteed to be compatible with future Apache SIS releases.
Serialization support is appropriate for short term storage or RMI between applications running the
same version of Apache SIS. For long term storage, use
XMLinstead.
- Since:
- 0.3
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class ModifiableMetadata
ModifiableMetadata.StateModifier and TypeClassDescriptionstatic enumWhether the metadata is still editable or has been made final. -
Field Summary
Fields inherited from class ISOMetadata
identifiersModifier and TypeFieldDescriptionprotected Collection<Identifier> All identifiers associated with this metadata, ornullif none. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an initially empty geographic bounding box.DefaultGeographicBoundingBox(double westBoundLongitude, double eastBoundLongitude, double southBoundLatitude, double northBoundLatitude) Creates a geographic bounding box initialized to the specified values.Constructs a new instance initialized with the values from the specified metadata object. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a geographic bounding box to this box.castOrCopy(GeographicBoundingBox object) Returns a SIS metadata implementation with the values of the given arbitrary implementation.booleanequals(Object object, ComparisonMode mode) Compares this geographic bounding box with the specified object for equality.doubleReturns the eastern-most coordinate of the limit of the dataset extent.doubleReturns the northern-most, coordinate of the limit of the dataset extent.doubleReturns the southern-most coordinate of the limit of the dataset extent.doubleReturns the western-most coordinate of the limit of the dataset extent.voidSets this bounding box to the intersection of this box with the specified one.booleanisEmpty()Returnstrueif this metadata is empty.voidsetBounds(double westBoundLongitude, double eastBoundLongitude, double southBoundLatitude, double northBoundLatitude) Sets the bounding box to the specified values.voidsetBounds(Envelope envelope) Sets the bounding box to the specified envelope.voidSets the bounding box to the same values as the specified box.voidsetEastBoundLongitude(double newValue) Sets the eastern-most coordinate of the limit of the dataset extent.voidsetNorthBoundLatitude(double newValue) Sets the northern-most, coordinate of the limit of the dataset extent.voidsetSouthBoundLatitude(double newValue) Sets the southern-most coordinate of the limit of the dataset extent.voidsetWestBoundLongitude(double newValue) Sets the western-most coordinate of the limit of the dataset extent.Methods inherited from class AbstractGeographicExtent
castOrCopy, getInclusion, setInclusionModifier and TypeMethodDescriptionstatic AbstractGeographicExtentcastOrCopy(GeographicExtent object) Returns a SIS metadata implementation with the values of the given arbitrary implementation.Indication of whether the bounding polygon encompasses an area covered by the data (inclusion) or an area where data is not present (exclusion).voidsetInclusion(Boolean newValue) Sets whether the bounding polygon encompasses an area covered by the data (inclusion) or an area where data is not present (exclusion).Methods inherited from class ISOMetadata
getIdentifier, getIdentifierMap, getIdentifiers, getStandard, setIdentifierModifier and TypeMethodDescriptionprotected IdentifierReturns the first identifier which is presumed to be defined by ISO 19115 conceptual model.A map view of the identifiers collection as (authority, code) entries.Returns all identifiers associated with this object (from conceptual model and from XML document).Returns the metadata standard implemented by subclasses, which is ISO 19115.protected voidsetIdentifier(Identifier newValue) Sets the identifier for metadata objects that are expected to contain at most one ISO 19115 identifier.Methods inherited from class ModifiableMetadata
checkWritePermission, copyCollection, copyList, copyMap, copySet, deepCopy, merge, nonNullCollection, nonNullList, nonNullMap, nonNullSet, singleton, state, writeCollection, writeList, writeMap, writeSetModifier and TypeMethodDescriptionprotected voidcheckWritePermission(Object current) Checks if changes in the metadata are allowed.protected static <E> Collection<E> copyCollection(Collection<? extends E> source, Class<E> elementType) Creates a list or set with the content of thesourcecollection, or returnsnullif the source isnullor empty.protected static <E> List<E> copyList(Collection<? extends E> source, Class<E> elementType) Creates a list with the content of thesourcecollection, or returnsnullif the source isnullor empty.protected static <K,V> Map <K, V> Creates a map with the content of thesourcemap, or returnsnullif the source isnullor empty.protected static <E> Set<E> copySet(Collection<? extends E> source, Class<E> elementType) Creates a set with the content of thesourcecollection, or returnsnullif the source isnullor empty.deepCopy(ModifiableMetadata.State target) Copies (if necessary) this metadata and all its children.voidMerges the data from the given source into this metadata.protected final <E> Collection<E> nonNullCollection(Collection<E> current, Class<E> elementType) Returns the specified collection, or a new one ifcurrentis null.protected final <E> List<E> nonNullList(List<E> current, Class<E> elementType) Returns the specified list, or a new one ifcurrentis null.protected final <K,V> Map <K, V> nonNullMap(Map<K, V> current, Class<K> keyType) Returns the specified map, or a new one ifcurrentis null.protected final <E> Set<E> nonNullSet(Set<E> current, Class<E> elementType) Returns the specified set, or a new one ifcurrentis null.protected static <E> Collection<E> Creates a singleton list or set containing only the given value, if non-null.state()Tells whether this instance of metadata is editable.protected final <E> Collection<E> writeCollection(Collection<? extends E> source, Collection<E> target, Class<E> elementType) Writes the content of thesourcecollection into thetargetlist or set, creating it if needed.protected final <E> List<E> writeList(Collection<? extends E> source, List<E> target, Class<E> elementType) Writes the content of thesourcecollection into thetargetlist, creating it if needed.protected final <K,V> Map <K, V> Writes the content of thesourcemap into thetargetmap, creating it if needed.protected final <E> Set<E> writeSet(Collection<? extends E> source, Set<E> target, Class<E> elementType) Writes the content of thesourcecollection into thetargetset, creating it if needed.Methods inherited from class AbstractMetadata
asMap, asTreeTable, clone, equals, getInterface, getStandardType, hashCode, nilReasons, prune, toStringModifier and TypeMethodDescriptionasMap()Returns a view of the property values in aMap.Returns the property types and values as a tree table.protected AbstractMetadataclone()Returns a shallow clone of this metadata.final booleanPerforms a strict comparison of this metadata with the given object.final Class<?> Deprecated, for removal: This API element is subject to removal in a future version.Returns the metadata interface implemented by this class.intComputes a hash code value for this metadata using Java reflection.Returns a view of the reasons why some properties are missing.voidprune()Removes all references to empty properties.Returns a string representation of this metadata.
-
Constructor Details
-
DefaultGeographicBoundingBox
public DefaultGeographicBoundingBox()Constructs an initially empty geographic bounding box. All longitude and latitude values are initialized toDouble.NaN. -
DefaultGeographicBoundingBox
public DefaultGeographicBoundingBox(double westBoundLongitude, double eastBoundLongitude, double southBoundLatitude, double northBoundLatitude) throws IllegalArgumentException Creates a geographic bounding box initialized to the specified values. The inclusion property is set totrue.Caution: Arguments are expected in the same order as they appear in the ISO 19115 specification. This is different than the order commonly found in the Java2D world, which is rather (xmin, ymin, xmax, ymax).
- Parameters:
westBoundLongitude- the minimal λ value.eastBoundLongitude- the maximal λ value.southBoundLatitude- the minimal φ value.northBoundLatitude- the maximal φ value.- Throws:
IllegalArgumentException- if (south bound > north bound). Note that NaN values are allowed.- See Also:
-
DefaultGeographicBoundingBox
Constructs a new instance initialized with the values from the specified metadata object. This is a shallow copy constructor, because the other metadata contained in the given object are not recursively copied.- Parameters:
object- the metadata to copy values from, ornullif none.- See Also:
-
-
Method Details
-
castOrCopy
Returns a SIS metadata implementation with the values of the given arbitrary implementation. This method performs the first applicable action in the following choices:- If the given object is
null, then this method returnsnull. - Otherwise if the given object is already an instance of
DefaultGeographicBoundingBox, then it is returned unchanged. - Otherwise a new
DefaultGeographicBoundingBoxinstance is created using the copy constructor and returned. Note that this is a shallow copy operation, because the other metadata contained in the given object are not recursively copied.
- Parameters:
object- the object to get as a SIS implementation, ornullif none.- Returns:
- a SIS implementation containing the values of the given object (may be the
given object itself), or
nullif the argument was null.
- If the given object is
-
getWestBoundLongitude
Returns the western-most coordinate of the limit of the dataset extent. The value is expressed in longitude in decimal degrees (positive east).Note that the returned value is greater than the east bound longitude if this box is crossing the anti-meridian.
- Specified by:
getWestBoundLongitudein interfaceGeographicBoundingBox- Returns:
- the western-most longitude between -180° and +180° inclusive, or NaN if undefined.
-
setWestBoundLongitude
public void setWestBoundLongitude(double newValue) Sets the western-most coordinate of the limit of the dataset extent. The value is expressed in longitude in decimal degrees (positive east). Values outside the [-180 … 180]° range are normalized.- Parameters:
newValue- the western-most longitude between -180° and +180° inclusive, or NaN to undefine.
-
getEastBoundLongitude
Returns the eastern-most coordinate of the limit of the dataset extent. The value is expressed in longitude in decimal degrees (positive east).Note that the returned value is smaller than the west bound longitude if this box is crossing the anti-meridian.
- Specified by:
getEastBoundLongitudein interfaceGeographicBoundingBox- Returns:
- the eastern-most longitude between -180° and +180° inclusive, or NaN if undefined.
-
setEastBoundLongitude
public void setEastBoundLongitude(double newValue) Sets the eastern-most coordinate of the limit of the dataset extent. The value is expressed in longitude in decimal degrees (positive east). Values outside the [-180 … 180]° range are normalized.- Parameters:
newValue- the eastern-most longitude between -180° and +180° inclusive, or NaN to undefine.
-
getSouthBoundLatitude
Returns the southern-most coordinate of the limit of the dataset extent. The value is expressed in latitude in decimal degrees (positive north).- Specified by:
getSouthBoundLatitudein interfaceGeographicBoundingBox- Returns:
- the southern-most latitude between -90° and +90° inclusive, or NaN if undefined.
-
setSouthBoundLatitude
public void setSouthBoundLatitude(double newValue) Sets the southern-most coordinate of the limit of the dataset extent. The value is expressed in latitude in decimal degrees (positive north). Values outside the [-90 … 90]° range are clamped. If the result is greater than the north bound latitude, then the north bound is set toDouble.NaN.- Parameters:
newValue- the southern-most latitude between -90° and +90° inclusive, or NaN to undefine.
-
getNorthBoundLatitude
Returns the northern-most, coordinate of the limit of the dataset extent. The value is expressed in latitude in decimal degrees (positive north).- Specified by:
getNorthBoundLatitudein interfaceGeographicBoundingBox- Returns:
- the northern-most latitude between -90° and +90° inclusive, or NaN if undefined.
-
setNorthBoundLatitude
public void setNorthBoundLatitude(double newValue) Sets the northern-most, coordinate of the limit of the dataset extent. The value is expressed in latitude in decimal degrees (positive north). Values outside the [-90 … 90]° range are clamped. If the result is smaller than the south bound latitude, then the south bound is set toDouble.NaN.- Parameters:
newValue- the northern-most latitude between -90° and +90° inclusive, or NaN to undefine.
-
setBounds
public void setBounds(double westBoundLongitude, double eastBoundLongitude, double southBoundLatitude, double northBoundLatitude) throws IllegalArgumentException Sets the bounding box to the specified values. The inclusion property is left unchanged.Caution: Arguments are expected in the same order as they appear in the ISO 19115 specification. This is different than the order commonly found in the Java2D world, which is rather (xmin, ymin, xmax, ymax).
- Parameters:
westBoundLongitude- the minimal λ value.eastBoundLongitude- the maximal λ value.southBoundLatitude- the minimal φ value.northBoundLatitude- the maximal φ value.- Throws:
IllegalArgumentException- if (south bound > north bound). Note that NaN values are allowed.
-
setBounds
Sets the bounding box to the specified envelope. If the envelope contains a CRS, then the bounding box may be projected to a geographic CRS. Otherwise, the envelope is assumed already in appropriate CRS.When coordinate transformation is required, the target geographic CRS is not necessarily WGS84. This method preserves the same ellipsoid than in the envelope CRS when possible. This is because geographic bounding box are only approximated and the ISO specification does not mandates a particular CRS, so we avoid transformations that are not strictly necessary.
Note: this method is available only if the referencing module is on the module path.
- Parameters:
envelope- the envelope to use for setting this geographic bounding box.- Throws:
UnsupportedOperationException- if the referencing module is not on the module path.TransformException- if the envelope cannot be transformed to a geographic extent.- See Also:
-
setBounds
Sets the bounding box to the same values as the specified box.- Parameters:
box- the geographic bounding box to use for setting the values of this box.
-
add
Adds a geographic bounding box to this box. This method behavior depends on whether the bounding boxes encompass an area covered by the data (inclusion) or an area where data is not present (exclusion):- If the inclusion status is the same for this box and the box to be added, then the resulting bounding box is the union of the two boxes.
- If the inclusion/exclusion status are opposite, then this method attempts to exclude some area of the specified box from this box. The resulting bounding box is smaller if the exclusion can be performed without ambiguity.
Comparison with other API
This class is stricter about NaN values than other classes likeGeneralEnvelope. The reason is that computations onGeographicBoundingBoxinstances are rare (Envelopeinstances are preferred for this purpose). Usually,GeographicBoundingBoxvalues come directly from some metadata structure. Consequently, NaN values inGeographicBoundingBoxmeansinformation is unknown
more often thannot yet calculated
.- Parameters:
box- the geographic bounding box to add to this box.- See Also:
-
intersect
Sets this bounding box to the intersection of this box with the specified one. The inclusion status must be the same for both boxes.If there is no intersection between the two bounding boxes, then this method sets both longitudes and/or both latitudes to NaN. If either this box or the specified box has NaN bounds, then the corresponding bounds of the intersection result will bet set to NaN.
- Parameters:
box- the geographic bounding box to intersect with this box.- Throws:
IllegalArgumentException- if the inclusion status is not the same for both boxes.- See Also:
-
isEmpty
public boolean isEmpty()Returnstrueif this metadata is empty. This metadata is considered empty if every bound values are NaN. Note that this is different than the Java2D or envelope definition of "emptiness", since we don't test if the area is greater than zero - this method is a metadata test, not a geometric test.- Specified by:
isEmptyin interfaceEmptiable- Overrides:
isEmptyin classAbstractMetadata- Returns:
trueif this metadata does not define any bound value.- See Also:
-
equals
Compares this geographic bounding box with the specified object for equality.- Specified by:
equalsin interfaceLenientComparable- Overrides:
equalsin classAbstractMetadata- Parameters:
object- the object to compare for equality.mode- the strictness level of the comparison.- Returns:
trueif the given object is equal to this box.- See Also:
-
AbstractMetadata.getStandardType()for integration withLenientComparable.