Package org.apache.sis.internal.feature
Class SpatialOperationContext
java.lang.Object
org.apache.sis.internal.feature.SpatialOperationContext
- All Implemented Interfaces:
Serializable
Context (such as desired CRS) in which a spatial operator will be executed.
Instances of this class are immutable and thread-safe.
The serialization form is not a committed API and may change in any future version.
- Since:
- 1.1
- Version:
- 1.3
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classCreates projections centered on a given geometry. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.opengis.metadata.extent.GeographicBoundingBoxApproximate geographic area of geometries, ornullif unspecified.private static final intThe 2 value, for identifying code that assume two-dimensional objects.(package private) org.opengis.referencing.crs.CoordinateReferenceSystemThe common CRS found bytransform(GeometryWrapper[]).private final org.opengis.referencing.crs.CoordinateReferenceSystemThe target CRS in which to transform geometries, ornullfor inferring automatically.private static final longFor cross-version compatibility.private final intIndex of the geometry associated to the common CRS, or -1 if none.private final javax.measure.Unit<?>If the CRS needs to be in some units of measurement, theUnit.getSystemUnit()value. -
Constructor Summary
ConstructorsConstructorDescriptionSpatialOperationContext(org.opengis.metadata.extent.GeographicBoundingBox areaOfInterest, GeometryWrapper<?> literal, javax.measure.Unit<?> systemUnit, int skipIndex) Creates a new context. -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleanisCompatibleUnit(org.opengis.referencing.crs.CoordinateReferenceSystem crs, javax.measure.Unit<?> systemUnit) Returnstrueif the units of measurement of the given CRS are compatible with the given units.static booleanThe value to return when a test cannot be applied.static booleanThe value to return when a test cannot be applied.private static org.opengis.referencing.crs.CoordinateReferenceSystemto2D(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Returns the two first dimensions of the given CRS.<G> GeometryWrapper<G>transform(GeometryWrapper<G> geometry) Transforms the specified geometry to the computation CRS.(package private) final <G> booleantransform(GeometryWrapper<G>[] geometries) Transforms the specified geometries to the common CRS.private static org.opengis.referencing.crs.CoordinateReferenceSystemusingSystemUnit(GeometryWrapper<?> geometry, org.opengis.referencing.crs.CoordinateReferenceSystem geometryCRS, org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS, javax.measure.Unit<?> systemUnit) Returns a coordinate reference system using the unit of measurement compatible with given system unit.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
BIDIMENSIONAL
private static final int BIDIMENSIONALThe 2 value, for identifying code that assume two-dimensional objects.- See Also:
-
areaOfInterest
private final org.opengis.metadata.extent.GeographicBoundingBox areaOfInterestApproximate geographic area of geometries, ornullif unspecified. -
computationCRS
private final org.opengis.referencing.crs.CoordinateReferenceSystem computationCRSThe target CRS in which to transform geometries, ornullfor inferring automatically. -
systemUnit
private final javax.measure.Unit<?> systemUnitIf the CRS needs to be in some units of measurement, theUnit.getSystemUnit()value. For example, is units need to be linear, thensystemUnitshall beUnits.METRE. Note that it does not mean that the units of measurement must be meters; only that they must be compatible with meters. -
skipIndex
private final int skipIndexIndex of the geometry associated to the common CRS, or -1 if none. This is used for avoiding unnecessary check of its CRS. -
commonCRS
org.opengis.referencing.crs.CoordinateReferenceSystem commonCRSThe common CRS found bytransform(GeometryWrapper[]). May be null.
-
-
Constructor Details
-
SpatialOperationContext
public SpatialOperationContext(org.opengis.metadata.extent.GeographicBoundingBox areaOfInterest, GeometryWrapper<?> literal, javax.measure.Unit<?> systemUnit, int skipIndex) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException, javax.measure.IncommensurableException Creates a new context.- Parameters:
areaOfInterest- approximate geographic area of geometries, ornullif unspecified.literal- if a geometry operand is a literal, that literal. Otherwisenull.systemUnit- if the CRS needs to be in some units of measurement, theUnit.getSystemUnit()value.skipIndex- index of the geometry associated tocommonCRS, or -1 if none.- Throws:
org.opengis.util.FactoryException- if an error occurred while fetchingliteralCRS.org.opengis.referencing.operation.TransformException- if a coordinate conversion was required but failed.javax.measure.IncommensurableException- if a coordinate system does not use the expected units.
-
-
Method Details
-
to2D
private static org.opengis.referencing.crs.CoordinateReferenceSystem to2D(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Returns the two first dimensions of the given CRS. This is usually thecrsargument unchanged (which may benull), unless a three- or four-dimensional CRS has been specified. We work with two dimensional CRS because the wrapped geometries are 2D and for avoiding thatReferencingUtilities.getUnit(CoordinateSystem)returnsnull. -
transform
public <G> GeometryWrapper<G> transform(GeometryWrapper<G> geometry) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException Transforms the specified geometry to the computation CRS. Geometries with unspecified CRS will be used as-is, without transformation. The common CRS is stored in thecommonCRSfield.- Type Parameters:
G- geometry implementation base class.- Parameters:
geometry- the geometry to transform.- Returns:
- the transformed geometry, or the same instance if no transformation was applied.
- Throws:
org.opengis.util.FactoryException- if an error occurred while fetching a CRS.org.opengis.referencing.operation.TransformException- if a coordinate conversion was required but failed.
-
transform
final <G> boolean transform(GeometryWrapper<G>[] geometries) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException, javax.measure.IncommensurableException Transforms the specified geometries to the common CRS. IfcomputationCRSisnull, then this method tries to infer one automatically. Geometries with unspecified CRS will be used as-is, without transformation. The common CRS is stored in thecommonCRSfield.- Type Parameters:
G- geometry implementation base class.- Parameters:
geometries- the geometries to transform. Results will be stored in-place.- Returns:
- whether this method has been able to find a common CRS.
- Throws:
org.opengis.util.FactoryException- if an error occurred while fetching a CRS.org.opengis.referencing.operation.TransformException- if a coordinate conversion was required but failed.javax.measure.IncommensurableException- if a geographic CRS does not use angular units (should not happen).
-
isCompatibleUnit
private static boolean isCompatibleUnit(org.opengis.referencing.crs.CoordinateReferenceSystem crs, javax.measure.Unit<?> systemUnit) Returnstrueif the units of measurement of the given CRS are compatible with the given units. All CRS axes should have the same units, otherwise this method returnsfalse.- Parameters:
crs- the CRS for which to test the units of measurement.systemUnit- theUnit.getSystemUnit()value of the desired unit.- Returns:
- whether the CRS units of measurement are compatible.
-
usingSystemUnit
private static org.opengis.referencing.crs.CoordinateReferenceSystem usingSystemUnit(GeometryWrapper<?> geometry, org.opengis.referencing.crs.CoordinateReferenceSystem geometryCRS, org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS, javax.measure.Unit<?> systemUnit) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException, javax.measure.IncommensurableException Returns a coordinate reference system using the unit of measurement compatible with given system unit. This is usually for creating aProjectedCRSwhen the user requested linear units, but it can also returnGeographicCRSif the user requested angular units.- Parameters:
geometry- one of the geometry used in the operation. Will determine projection center.geometryCRS- the CRS ofgeometry.targetCRS- initial proposal of CRS to use for coordinate operation.systemUnit-Unit.getSystemUnit()value on the unit requested by user.- Returns:
- a CRS derived from
targetCRSwith units compatible with the specified units. - Throws:
org.opengis.util.FactoryException- if an error occurred while fetching a CRS.org.opengis.referencing.operation.TransformException- if a coordinate conversion was required but failed.javax.measure.IncommensurableException- if a coordinate system does not use the expected units.
-
negativeResult
The value to return when a test cannot be applied. This method is defined for having a single place to update if more operator types need to be recognized.- Parameters:
type- the test that could not be applied.- Returns:
- the operation result to assume.
-
negativeResult
The value to return when a test cannot be applied. This method is defined for having a single place to update if more operator types need to be recognized.- Parameters:
type- the test that could not be applied.- Returns:
- the operation result to assume.
-