You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2025/07/21 14:43:56 UTC
(sis) branch main updated (42a3d15915 -> a5507ba075)
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/sis.git
from 42a3d15915 Merge branch 'geoapi-3.1', excluding the `org.apache.sis.geometry` module (incubator). That geometry module depends on GeoAPI interfaces that are not released (and may not). A review of the geometry module is necessary before it can be merged to the main branch.
add 4552d77166 Fix a code of `TransformSeparator` where the accurracy of matrix elements could be lost.
add b705f8c455 Refactor matrix classes between sis referencing Matrix and the new geometry module matrix classes
add ad6153efb4 Minor editions to new matrix methods:
add f373d1fcd8 Fix documentation relative to EPSG in the `README` files and in Javadoc of installation script providers. Some sentences where from the days when the EPSG optional modules were on the SVN source code repository.
add 531f0165a6 Write catalog name in a way more compliant with what the database driver expects. Omit the catalog name and/or schema name when they are the current catalog/schema.
add 559ad8b78c Replace the MS-Access SQL dialect by ANSI SQL in EPSG factory. For example, use "Datum" instead of [Datum] in hard-coded queries (before this commit, [Datum] was replaced by "Datum" at runtime).
add 6e7b9ad37e Add enumeration values for new tables and new types introduced in EPSG 10. Update the documentation about the new tables.
add 4f5de477ca Hide default geometry implementations in a privy package, add geometry factory class as replacement
add 540ea55fa4 fix(Referencing): prevent NPE on complex crs conversion analysis
add 4f46412557 `MissingFactoryResourceException` needs to be propagated when a NADCON file is not found. NTv2 was okay, but nevertheless apply the same pattern to other grid formats for safety.
add f4aee41bc4 `DefaultDatumEnsemble` implements `Datum` with a documentation saying that this is non-standard. Note that the EPSG database does something similar by storing ensembles in the datum table. The `PseudoDatum` class is replaced by `DatumOrEnsemble` with static methods.
add e75a1a0b49 Add geometry classes and reference from OGC Features and Geometries JSON draft
add 4ac0d9f4bb Tuple interface do not inherit DirecPosition anymore
add e0ad3091f1 Add CRS declaration in shapefile geometry user data
add 16c01f5cdf Add a mechanism for letting `MetadataStandard` know that the `Datum` interface implemented by `DefaultDatumEnsemble` should be ignored.
add b1954e2e7f Add `getCharacteristicValue(…)` for making possible to ask for a characteristic without forcing the creation of a `Property` instance in the common case where the characteristic does not exist.
add 5fb125cf40 If `Feature` property contains a geometry without CRS, fallback on the CRS defined in the `FeatureType`.
add 843e15d6d6 Fix the error message when a datum shift grid file has not been found. Opportunistic minor code formatting.
add 75624a737d Fix the case of GeoTIFF files not read correctly when the image is untiled but the tile is unnecessary large (larger than the actual image).
add 252ab98b78 Adjust the default sample dimensions created by the GeoTIFF reader. If a "no data" category is added, then a "data" category should also be added.
add 788778542c Documentation fixes.
add 88c4efc2c7 Merge branch 'geoapi-4.0' into geoapi-3.1. Contains work in preparation to upgrade of the EPSG database and improvement in the handling of CRS of geometries of features.
add 343f672ec6 Add implementation for deprecated GeoAPI 3.1 methods that have been removed in GeoAPI 4.0.
new a5507ba075 Merge branch 'geoapi-3.1' Contains work in preparation to upgrade of the EPSG database and improvement in the handling of CRS of geometries of features.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../org/apache/sis/coverage/SampleDimension.java | 10 +-
.../org/apache/sis/coverage/grid/GridCoverage.java | 2 +-
.../org/apache/sis/feature/AbstractFeature.java | 57 +-
.../main/org/apache/sis/feature/DenseFeature.java | 35 +-
.../org/apache/sis/feature/EnvelopeOperation.java | 2 +-
.../main/org/apache/sis/feature/Features.java | 8 +-
.../main/org/apache/sis/feature/SparseFeature.java | 35 +-
.../sis/feature/privy/AttributeConvention.java | 66 +-
.../apache/sis/filter/BinaryGeometryFilter.java | 34 +-
.../org/apache/sis/filter/BinarySpatialFilter.java | 5 +-
.../main/org/apache/sis/filter/DistanceFilter.java | 5 +-
.../apache/sis/filter/InvalidXPathException.java | 2 +-
.../sis/filter/internal/GeometryConverter.java | 48 +-
.../sis/filter/internal/GeometryFromFeature.java | 107 +++
.../main/org/apache/sis/filter/internal/Node.java | 38 +-
.../apache/sis/filter/sqlmm/FunctionWithSRID.java | 4 +-
.../apache/sis/filter/sqlmm/GeometryParser.java | 3 +-
.../org/apache/sis/filter/sqlmm/ST_Transform.java | 6 +-
.../apache/sis/geometry/wrapper/Geometries.java | 74 +-
.../sis/geometry/wrapper/GeometryWithCRS.java | 92 ---
.../sis/geometry/wrapper/GeometryWrapper.java | 270 ++++---
.../apache/sis/geometry/wrapper/esri/Wrapper.java | 3 +-
.../apache/sis/geometry/wrapper/j2d/Factory.java | 2 +-
.../sis/geometry/wrapper/j2d/PointWrapper.java | 13 +-
.../apache/sis/geometry/wrapper/j2d/Wrapper.java | 8 +-
.../apache/sis/geometry/wrapper/jts/Factory.java | 28 +-
.../org/apache/sis/geometry/wrapper/jts/JTS.java | 45 +-
.../apache/sis/geometry/wrapper/jts/Wrapper.java | 79 +--
.../main/org/apache/sis/image/PixelIterator.java | 6 +-
.../apache/sis/image/privy/ColorModelFactory.java | 3 +
.../apache/sis/image/privy/ColorScaleBuilder.java | 17 +-
.../feature/builder/AttributeTypeBuilderTest.java | 2 +-
.../sis/feature/privy/AttributeConventionTest.java | 9 +-
.../apache/sis/geometry/wrapper/jts/JTSTest.java | 6 +-
.../org/apache/sis/metadata/MetadataStandard.java | 67 +-
.../org/apache/sis/metadata/PropertyAccessor.java | 4 +-
.../sis/metadata/StandardImplementation.java | 3 +-
.../main/org/apache/sis/metadata/TreeNode.java | 2 +-
.../org/apache/sis/metadata/TreeNodeChildren.java | 2 +-
.../apache/sis/metadata/internal/ExcludedSet.java | 6 +-
.../privy/SecondaryTrait.java} | 25 +-
.../apache/sis/metadata/sql/MetadataSource.java | 6 +-
.../org/apache/sis/metadata/sql/privy/Dialect.java | 20 +-
.../apache/sis/metadata/sql/privy/Reflection.java | 2 -
.../apache/sis/metadata/sql/privy/SQLBuilder.java | 59 +-
.../sis/metadata/sql/privy/SQLUtilities.java | 9 +-
.../sis/metadata/sql/privy/ScriptRunner.java | 15 +-
.../apache/sis/metadata/sql/privy/Supports.java | 12 +-
.../org/apache/sis/metadata/sql/privy/Syntax.java | 76 +-
.../org/apache/sis/portrayal/CanvasContext.java | 8 +-
.../org/apache/sis/geometry/CoordinateFormat.java | 4 +-
.../main/org/apache/sis/io/wkt/VerticalInfo.java | 6 +-
.../main/org/apache/sis/referencing/CRS.java | 7 +-
.../main/org/apache/sis/referencing/CommonCRS.java | 6 +-
.../referencing/EllipsoidalHeightSeparator.java | 6 +-
.../apache/sis/referencing/GeodeticCalculator.java | 9 +-
.../sis/referencing/MultiRegisterOperations.java | 2 +-
.../sis/referencing/crs/AbstractSingleCRS.java | 37 +-
.../sis/referencing/crs/DefaultGeographicCRS.java | 6 +-
.../sis/referencing/crs/DefaultTemporalCRS.java | 4 +-
.../sis/referencing/crs/ExplicitParameters.java | 4 +-
.../sis/referencing/datum/DatumOrEnsemble.java | 447 ++++++++++++
.../referencing/datum/DefaultDatumEnsemble.java | 581 +++++++++++++++-
.../referencing/datum/DefaultPrimeMeridian.java | 2 +-
.../apache/sis/referencing/datum/PseudoDatum.java | 774 ---------------------
.../referencing/factory/GeodeticObjectFactory.java | 2 +-
.../referencing/factory/sql/EPSGCodeFinder.java | 10 +-
.../referencing/factory/sql/EPSGDataAccess.java | 176 ++---
.../sis/referencing/factory/sql/EPSGFactory.java | 24 +-
.../sis/referencing/factory/sql/EPSGInstaller.java | 34 +-
.../sis/referencing/factory/sql/EPSG_Prepare.sql | 18 +-
.../sis/referencing/factory/sql/EPSG_README.md | 15 +-
.../factory/sql/InstallationScriptProvider.java | 102 ++-
.../sis/referencing/factory/sql/SQLTranslator.java | 385 +++++-----
.../sis/referencing/factory/sql/TableInfo.java | 69 +-
.../sis/referencing/factory/sql/package-info.java | 4 +-
.../internal/ParameterizedTransformBuilder.java | 6 +-
.../apache/sis/referencing/internal/Resources.java | 2 +-
.../sis/referencing/internal/Resources.properties | 2 +-
.../referencing/internal/Resources_fr.properties | 2 +-
.../referencing/internal/SignReversalComment.java | 4 +-
.../operation/CoordinateOperationFinder.java | 33 +-
.../operation/CoordinateOperationRegistry.java | 6 +-
.../operation/DefaultConcatenatedOperation.java | 4 +-
.../referencing/operation/DefaultConversion.java | 3 +-
.../DefaultCoordinateOperationFactory.java | 4 +-
.../referencing/operation/SubOperationInfo.java | 1 +
.../referencing/operation/gridded/GridFile.java | 8 +-
.../sis/referencing/operation/matrix/Matrix1.java | 13 +
.../sis/referencing/operation/matrix/Matrix2.java | 37 +
.../sis/referencing/operation/matrix/Matrix3.java | 18 +
.../sis/referencing/operation/matrix/Matrix4.java | 20 +
.../referencing/operation/matrix/MatrixSIS.java | 8 +-
.../operation/provider/AbstractProvider.java | 8 +-
.../provider/FranceGeocentricInterpolation.java | 2 +
.../sis/referencing/operation/provider/NADCON.java | 2 +
.../sis/referencing/operation/provider/NTv2.java | 2 +
.../operation/transform/AbstractMathTransform.java | 2 +-
.../transform/DefaultMathTransformFactory.java | 6 +-
.../operation/transform/TransformSeparator.java | 10 +-
.../sis/referencing/privy/AffineTransform2D.java | 10 +-
.../sis/referencing/privy/DefinitionVerifier.java | 38 +-
.../privy/EllipsoidalHeightCombiner.java | 6 +-
.../referencing/privy/GeodeticObjectBuilder.java | 4 +-
.../referencing/privy/ReferencingUtilities.java | 90 ---
.../apache/sis/referencing/privy/WKTUtilities.java | 6 +-
.../sis/io/wkt/GeodeticObjectParserTest.java | 2 +-
.../sis/referencing/GeodesicsOnEllipsoidTest.java | 4 +-
.../referencing/factory/sql/EPSGInstallerTest.java | 12 +-
.../sis/referencing/factory/sql/TableInfoTest.java | 7 +-
.../transform/InterpolatedTransformTest.java | 2 +-
.../main/org/apache/sis/storage/landsat/Band.java | 13 +-
.../sis/storage/geotiff/CompressedSubset.java | 23 +-
.../org/apache/sis/storage/geotiff/DataCube.java | 19 +-
.../org/apache/sis/storage/geotiff/DataSubset.java | 26 +-
.../sis/storage/geotiff/ImageFileDirectory.java | 110 ++-
.../apache/sis/storage/geotiff/inflater/LZW.java | 3 +-
.../sis/storage/geotiff/reader/CRSBuilder.java | 6 +-
.../sis/storage/geotiff/writer/GeoEncoder.java | 6 +-
.../apache/sis/storage/netcdf/base/CRSBuilder.java | 8 +-
.../sis/storage/netcdf/base/GridMapping.java | 4 +-
.../apache/sis/storage/sql/feature/Analyzer.java | 5 +-
.../apache/sis/storage/sql/feature/Database.java | 6 +-
.../sis/storage/sql/feature/FeatureAdapter.java | 4 +-
.../sis/storage/sql/feature/FeatureIterator.java | 4 +-
.../sis/storage/sql/feature/FeatureStream.java | 34 +-
.../sis/storage/sql/feature/InfoStatements.java | 17 +-
.../sis/storage/sql/postgis/ExtentEstimator.java | 6 +-
.../apache/sis/storage/sql/postgis/Postgres.java | 2 +-
.../storage/sql/feature/GeometryGetterTest.java | 8 +-
.../apache/sis/storage/base/TiledGridCoverage.java | 55 +-
.../apache/sis/storage/base/TiledGridResource.java | 25 +-
.../main/org/apache/sis/storage/csv/Store.java | 4 +-
.../sis/storage/modifier/CoverageModifier.java | 103 +--
.../main/org/apache/sis/system/DataDirectory.java | 2 +-
.../sis/util/privy/UnmodifiableArrayList.java | 2 +-
.../org/apache/sis/util/CharSequencesTest.java | 63 +-
.../sis/storage/geopackage/GpkgStoreTest.java | 2 +-
.../sis/storage/shapefile/ShapefileStore.java | 19 +
.../sis/storage/shapefile/ShapefileStoreTest.java | 4 +
netbeans-project/nbproject/project.xml | 1 +
.../main/org/apache/sis/gui/map/StatusBar.java | 55 +-
.../org/apache/sis/gui/map/ValuesFormatter.java | 25 +-
.../org/apache/sis/gui/map/ValuesFromCoverage.java | 9 +-
.../sis/referencing/factory/sql/epsg/README.md | 25 +-
.../factory/sql/epsg/DataScriptFormatter.java | 30 +-
.../sis/referencing/factory/sql/epsg/README.md | 87 +--
.../factory/sql/epsg/ScriptProviderTest.java | 2 +-
148 files changed, 3014 insertions(+), 2361 deletions(-)
create mode 100644 endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/internal/GeometryFromFeature.java
delete mode 100644 endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWithCRS.java
copy endorsed/src/org.apache.sis.metadata/main/org/apache/sis/{pending/geoapi/evolution/InterimType.java => metadata/privy/SecondaryTrait.java} (58%)
create mode 100644 endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/DatumOrEnsemble.java
delete mode 100644 endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/PseudoDatum.java
(sis) 01/01: Merge branch 'geoapi-3.1' Contains work in preparation to upgrade of the EPSG database and improvement in the handling of CRS of geometries of features.
Posted by de...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/sis.git
commit a5507ba075ff85fe753c20c727cf756683077e64
Merge: 42a3d15915 343f672ec6
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Mon Jul 21 16:42:35 2025 +0200
Merge branch 'geoapi-3.1'
Contains work in preparation to upgrade of the EPSG database
and improvement in the handling of CRS of geometries of features.
.../org/apache/sis/coverage/SampleDimension.java | 10 +-
.../org/apache/sis/coverage/grid/GridCoverage.java | 2 +-
.../org/apache/sis/feature/AbstractFeature.java | 57 +-
.../main/org/apache/sis/feature/DenseFeature.java | 35 +-
.../org/apache/sis/feature/EnvelopeOperation.java | 2 +-
.../main/org/apache/sis/feature/Features.java | 8 +-
.../main/org/apache/sis/feature/SparseFeature.java | 35 +-
.../sis/feature/privy/AttributeConvention.java | 66 +-
.../apache/sis/filter/BinaryGeometryFilter.java | 34 +-
.../org/apache/sis/filter/BinarySpatialFilter.java | 5 +-
.../main/org/apache/sis/filter/DistanceFilter.java | 5 +-
.../apache/sis/filter/InvalidXPathException.java | 2 +-
.../sis/filter/internal/GeometryConverter.java | 48 +-
.../sis/filter/internal/GeometryFromFeature.java | 107 +++
.../main/org/apache/sis/filter/internal/Node.java | 38 +-
.../apache/sis/filter/sqlmm/FunctionWithSRID.java | 4 +-
.../apache/sis/filter/sqlmm/GeometryParser.java | 3 +-
.../org/apache/sis/filter/sqlmm/ST_Transform.java | 6 +-
.../apache/sis/geometry/wrapper/Geometries.java | 74 +-
.../sis/geometry/wrapper/GeometryWithCRS.java | 92 ---
.../sis/geometry/wrapper/GeometryWrapper.java | 270 ++++---
.../apache/sis/geometry/wrapper/esri/Wrapper.java | 3 +-
.../apache/sis/geometry/wrapper/j2d/Factory.java | 2 +-
.../sis/geometry/wrapper/j2d/PointWrapper.java | 13 +-
.../apache/sis/geometry/wrapper/j2d/Wrapper.java | 8 +-
.../apache/sis/geometry/wrapper/jts/Factory.java | 28 +-
.../org/apache/sis/geometry/wrapper/jts/JTS.java | 45 +-
.../apache/sis/geometry/wrapper/jts/Wrapper.java | 79 +--
.../main/org/apache/sis/image/PixelIterator.java | 6 +-
.../apache/sis/image/privy/ColorModelFactory.java | 3 +
.../apache/sis/image/privy/ColorScaleBuilder.java | 17 +-
.../feature/builder/AttributeTypeBuilderTest.java | 2 +-
.../sis/feature/privy/AttributeConventionTest.java | 9 +-
.../apache/sis/geometry/wrapper/jts/JTSTest.java | 6 +-
.../org/apache/sis/metadata/MetadataStandard.java | 67 +-
.../org/apache/sis/metadata/PropertyAccessor.java | 4 +-
.../sis/metadata/StandardImplementation.java | 3 +-
.../main/org/apache/sis/metadata/TreeNode.java | 2 +-
.../org/apache/sis/metadata/TreeNodeChildren.java | 2 +-
.../apache/sis/metadata/internal/ExcludedSet.java | 6 +-
.../apache/sis/metadata/privy/SecondaryTrait.java | 45 ++
.../apache/sis/metadata/sql/MetadataSource.java | 6 +-
.../org/apache/sis/metadata/sql/privy/Dialect.java | 20 +-
.../apache/sis/metadata/sql/privy/Reflection.java | 2 -
.../apache/sis/metadata/sql/privy/SQLBuilder.java | 59 +-
.../sis/metadata/sql/privy/SQLUtilities.java | 9 +-
.../sis/metadata/sql/privy/ScriptRunner.java | 15 +-
.../apache/sis/metadata/sql/privy/Supports.java | 12 +-
.../org/apache/sis/metadata/sql/privy/Syntax.java | 76 +-
.../org/apache/sis/portrayal/CanvasContext.java | 8 +-
.../org/apache/sis/geometry/CoordinateFormat.java | 4 +-
.../main/org/apache/sis/io/wkt/VerticalInfo.java | 6 +-
.../main/org/apache/sis/referencing/CRS.java | 7 +-
.../main/org/apache/sis/referencing/CommonCRS.java | 6 +-
.../referencing/EllipsoidalHeightSeparator.java | 6 +-
.../apache/sis/referencing/GeodeticCalculator.java | 9 +-
.../sis/referencing/MultiRegisterOperations.java | 2 +-
.../sis/referencing/crs/AbstractSingleCRS.java | 37 +-
.../sis/referencing/crs/DefaultGeographicCRS.java | 6 +-
.../sis/referencing/crs/DefaultTemporalCRS.java | 4 +-
.../sis/referencing/crs/ExplicitParameters.java | 4 +-
.../sis/referencing/datum/DatumOrEnsemble.java | 447 ++++++++++++
.../referencing/datum/DefaultDatumEnsemble.java | 581 +++++++++++++++-
.../referencing/datum/DefaultPrimeMeridian.java | 2 +-
.../apache/sis/referencing/datum/PseudoDatum.java | 774 ---------------------
.../referencing/factory/GeodeticObjectFactory.java | 2 +-
.../referencing/factory/sql/EPSGCodeFinder.java | 10 +-
.../referencing/factory/sql/EPSGDataAccess.java | 176 ++---
.../sis/referencing/factory/sql/EPSGFactory.java | 24 +-
.../sis/referencing/factory/sql/EPSGInstaller.java | 34 +-
.../sis/referencing/factory/sql/EPSG_Prepare.sql | 18 +-
.../sis/referencing/factory/sql/EPSG_README.md | 15 +-
.../factory/sql/InstallationScriptProvider.java | 102 ++-
.../sis/referencing/factory/sql/SQLTranslator.java | 385 +++++-----
.../sis/referencing/factory/sql/TableInfo.java | 69 +-
.../sis/referencing/factory/sql/package-info.java | 4 +-
.../internal/ParameterizedTransformBuilder.java | 6 +-
.../apache/sis/referencing/internal/Resources.java | 2 +-
.../sis/referencing/internal/Resources.properties | 2 +-
.../referencing/internal/Resources_fr.properties | 2 +-
.../referencing/internal/SignReversalComment.java | 4 +-
.../operation/CoordinateOperationFinder.java | 33 +-
.../operation/CoordinateOperationRegistry.java | 6 +-
.../operation/DefaultConcatenatedOperation.java | 4 +-
.../referencing/operation/DefaultConversion.java | 3 +-
.../DefaultCoordinateOperationFactory.java | 4 +-
.../referencing/operation/SubOperationInfo.java | 1 +
.../referencing/operation/gridded/GridFile.java | 8 +-
.../sis/referencing/operation/matrix/Matrix1.java | 13 +
.../sis/referencing/operation/matrix/Matrix2.java | 37 +
.../sis/referencing/operation/matrix/Matrix3.java | 18 +
.../sis/referencing/operation/matrix/Matrix4.java | 20 +
.../referencing/operation/matrix/MatrixSIS.java | 8 +-
.../operation/provider/AbstractProvider.java | 8 +-
.../provider/FranceGeocentricInterpolation.java | 2 +
.../sis/referencing/operation/provider/NADCON.java | 2 +
.../sis/referencing/operation/provider/NTv2.java | 2 +
.../operation/transform/AbstractMathTransform.java | 2 +-
.../transform/DefaultMathTransformFactory.java | 6 +-
.../operation/transform/TransformSeparator.java | 10 +-
.../sis/referencing/privy/AffineTransform2D.java | 10 +-
.../sis/referencing/privy/DefinitionVerifier.java | 38 +-
.../privy/EllipsoidalHeightCombiner.java | 6 +-
.../referencing/privy/GeodeticObjectBuilder.java | 4 +-
.../referencing/privy/ReferencingUtilities.java | 90 ---
.../apache/sis/referencing/privy/WKTUtilities.java | 6 +-
.../sis/io/wkt/GeodeticObjectParserTest.java | 2 +-
.../sis/referencing/GeodesicsOnEllipsoidTest.java | 4 +-
.../referencing/factory/sql/EPSGInstallerTest.java | 12 +-
.../sis/referencing/factory/sql/TableInfoTest.java | 7 +-
.../transform/InterpolatedTransformTest.java | 2 +-
.../main/org/apache/sis/storage/landsat/Band.java | 13 +-
.../sis/storage/geotiff/CompressedSubset.java | 23 +-
.../org/apache/sis/storage/geotiff/DataCube.java | 19 +-
.../org/apache/sis/storage/geotiff/DataSubset.java | 26 +-
.../sis/storage/geotiff/ImageFileDirectory.java | 110 ++-
.../apache/sis/storage/geotiff/inflater/LZW.java | 3 +-
.../sis/storage/geotiff/reader/CRSBuilder.java | 6 +-
.../sis/storage/geotiff/writer/GeoEncoder.java | 6 +-
.../apache/sis/storage/netcdf/base/CRSBuilder.java | 8 +-
.../sis/storage/netcdf/base/GridMapping.java | 4 +-
.../apache/sis/storage/sql/feature/Analyzer.java | 5 +-
.../apache/sis/storage/sql/feature/Database.java | 6 +-
.../sis/storage/sql/feature/FeatureAdapter.java | 4 +-
.../sis/storage/sql/feature/FeatureIterator.java | 4 +-
.../sis/storage/sql/feature/FeatureStream.java | 34 +-
.../sis/storage/sql/feature/InfoStatements.java | 17 +-
.../sis/storage/sql/postgis/ExtentEstimator.java | 6 +-
.../apache/sis/storage/sql/postgis/Postgres.java | 2 +-
.../storage/sql/feature/GeometryGetterTest.java | 8 +-
.../apache/sis/storage/base/TiledGridCoverage.java | 55 +-
.../apache/sis/storage/base/TiledGridResource.java | 25 +-
.../main/org/apache/sis/storage/csv/Store.java | 4 +-
.../sis/storage/modifier/CoverageModifier.java | 103 +--
.../main/org/apache/sis/system/DataDirectory.java | 2 +-
.../sis/util/privy/UnmodifiableArrayList.java | 2 +-
.../org/apache/sis/util/CharSequencesTest.java | 63 +-
.../sis/storage/geopackage/GpkgStoreTest.java | 2 +-
.../sis/storage/shapefile/ShapefileStore.java | 19 +
.../sis/storage/shapefile/ShapefileStoreTest.java | 4 +
netbeans-project/nbproject/project.xml | 1 +
.../main/org/apache/sis/gui/map/StatusBar.java | 55 +-
.../org/apache/sis/gui/map/ValuesFormatter.java | 25 +-
.../org/apache/sis/gui/map/ValuesFromCoverage.java | 9 +-
.../sis/referencing/factory/sql/epsg/README.md | 25 +-
.../factory/sql/epsg/DataScriptFormatter.java | 30 +-
.../sis/referencing/factory/sql/epsg/README.md | 87 +--
.../factory/sql/epsg/ScriptProviderTest.java | 2 +-
148 files changed, 3046 insertions(+), 2349 deletions(-)
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/AbstractFeature.java
index d1341ebc49,1ac43343df..6cc3b37b6b
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/AbstractFeature.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/AbstractFeature.java
@@@ -339,7 -349,12 +340,11 @@@ public abstract class AbstractFeature i
*
* @see AbstractAttribute#getValue()
*/
- public abstract Object getPropertyValue(final String name) throws IllegalArgumentException;
- @Override
- public Object getPropertyValue(final String name) throws PropertyNotFoundException {
++ public Object getPropertyValue(final String name) throws IllegalArgumentException {
+ final Object value = getValueOrFallback(name, MISSING);
+ if (value != MISSING) return value;
- throw new PropertyNotFoundException(propertyNotFound(type, getName(), name));
++ throw new IllegalArgumentException(propertyNotFound(type, getName(), name));
+ }
/**
* Sets the value for the property of the given name.
@@@ -367,7 -383,7 +372,7 @@@
* {@snippet lang="java" :
* try {
* return getPropertyValue(name);
-- * } catch (PropertyNotFoundException ignore) {
++ * } catch (IllegalArgumentException ignore) {
* return missingPropertyFallback
* }
* }
@@@ -458,6 -475,50 +463,50 @@@
}
}
+ /**
+ * Returns the explicit or default value of a characteristic of a property.
+ * This is a shortcut for the following chain of method invocations
+ * (cast and null checks omitted for brevity),
+ * except that the actual implementation is potentially more efficient:
+ *
+ * {@snippet lang="java" :
+ * return Optional.ofNullable(
+ * ((Attribute<?>) getProperty(property))
+ * .characteristics()
+ * .get(characteristic)
+ * .getValue());
+ * }
+ *
+ * If the attribute has no {@linkplain AbstractAttribute#characteristics() characteristic} of the given name,
+ * then this method fallbacks on the default value of the {@linkplain DefaultAttributeType#characteristics()
+ * characteristics of the attribute type}.
+ *
+ * @param property name of the property for which to get a characteristic.
+ * @param characteristic name of the characteristic of the property of the given name.
+ * @return value of the specified characteristic on the specified property, or an empty value
+ * if the property is not an attribute or the attribute has no such characteristic.
- * @throws PropertyNotFoundException if the {@code property} argument is not the name of a property of this feature.
++ * @throws IllegalArgumentException if the {@code property} argument is not the name of a property of this feature.
+ *
+ * @since 1.5
+ */
+ public Optional<?> getCharacteristicValue(final String property, final String characteristic)
- throws PropertyNotFoundException
++ throws IllegalArgumentException
+ {
- Property p = getProperty(property);
- if (p instanceof Attribute<?>) {
- var attribute = (Attribute<?>) p;
- Attribute<?> ca = attribute.characteristics().get(characteristic);
++ Object p = getProperty(property);
++ if (p instanceof AbstractAttribute<?>) {
++ var attribute = (AbstractAttribute<?>) p;
++ AbstractAttribute<?> ca = attribute.characteristics().get(characteristic);
+ if (ca != null) {
+ // If the characteristic is present, assume that an explicitly null value is intentional.
+ return Optional.ofNullable(ca.getValue());
+ } else {
+ return Optional.ofNullable(attribute.getType().characteristics().get(characteristic))
- .map(AttributeType::getDefaultValue);
++ .map(DefaultAttributeType::getDefaultValue);
+ }
+ }
+ return Optional.empty();
+ }
+
/**
* Returns the value of the given attribute, as a singleton or as a collection depending
* on the maximum number of occurrences.
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/DenseFeature.java
index bbdfb52a4a,db9fd2c693..a95fe10933
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/DenseFeature.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/DenseFeature.java
@@@ -252,6 -245,20 +239,20 @@@ final class DenseFeature extends Abstra
setPropertyValue(property, value);
}
+ /**
+ * Returns the explicit or default value of a characteristic of a property.
+ * Overridden for skipping the creation of property instances when there is no characteristic.
+ */
+ @Override
+ public Optional<?> getCharacteristicValue(final String property, final String characteristic)
- throws PropertyNotFoundException
++ throws IllegalArgumentException
+ {
+ if (properties instanceof Property[]) {
+ return super.getCharacteristicValue(property, characteristic);
+ }
+ return Optional.empty();
+ }
+
/**
* Verifies if all current properties met the constraints defined by the feature type. This method returns
* {@linkplain org.apache.sis.metadata.iso.quality.DefaultDataQuality#getReports() reports} for all invalid
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/Features.java
index 1053c4aad2,6cd9577401..b7ab05ba13
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/Features.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/Features.java
@@@ -171,9 -185,9 +173,9 @@@ public final class Features extends Sta
* contain a cycle. However, given that the consequence of an infinite cycle here
* would be thread freeze, we check as a safety.
*/
- final Map<AbstractIdentifiedType,Boolean> done = new IdentityHashMap<>(4);
- final var done = new IdentityHashMap<IdentifiedType,Boolean>(4);
- while (!target.isInstance(type = ((Operation) type).getResult())) {
- if (!(type instanceof Operation) || done.put(type, Boolean.TRUE) != null) {
++ final var done = new IdentityHashMap<AbstractIdentifiedType,Boolean>(4);
+ while (!target.isInstance(type = ((AbstractOperation) type).getResult())) {
+ if (!(type instanceof AbstractOperation) || done.put(type, Boolean.TRUE) != null) {
return Optional.empty();
}
}
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/SparseFeature.java
index 21ce42eade,76a110b426..e74ed55aff
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/SparseFeature.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/SparseFeature.java
@@@ -315,6 -309,20 +302,20 @@@ final class SparseFeature extends Abstr
}
}
+ /**
+ * Returns the explicit or default value of a characteristic of a property.
+ * Overridden for skipping the creation of property instances when there is no characteristic.
+ */
+ @Override
+ public Optional<?> getCharacteristicValue(final String property, final String characteristic)
- throws PropertyNotFoundException
++ throws IllegalArgumentException
+ {
+ if (valuesKind != VALUES) {
+ return super.getCharacteristicValue(property, characteristic);
+ }
+ return Optional.empty();
+ }
+
/**
* Verifies if all current properties met the constraints defined by the feature type. This method returns
* {@linkplain org.apache.sis.metadata.iso.quality.DefaultDataQuality#getReports() reports} for all invalid
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/privy/AttributeConvention.java
index a5ce49d90a,c927308d49..d781d9cc5b
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/privy/AttributeConvention.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/privy/AttributeConvention.java
@@@ -24,14 -24,19 +24,13 @@@ import org.opengis.referencing.crs.Coor
import org.apache.sis.util.Static;
import org.apache.sis.util.iso.Names;
import org.apache.sis.feature.Features;
-import org.apache.sis.feature.AbstractFeature;
import org.apache.sis.geometry.wrapper.Geometries;
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.feature.Feature;
-import org.opengis.feature.Attribute;
-import org.opengis.feature.AttributeType;
-import org.opengis.feature.IdentifiedType;
-import org.opengis.feature.Operation;
-import org.opengis.feature.Property;
-import org.opengis.feature.PropertyType;
-import org.opengis.feature.FeatureType;
-import org.opengis.feature.PropertyNotFoundException;
+// Specific to the main branch:
+import org.apache.sis.feature.AbstractFeature;
- import org.apache.sis.feature.AbstractAttribute;
+import org.apache.sis.feature.AbstractIdentifiedType;
+import org.apache.sis.feature.DefaultAttributeType;
+import org.apache.sis.feature.DefaultFeatureType;
/**
@@@ -134,7 -139,7 +133,7 @@@ public final class AttributeConvention
* <p>The {@linkplain org.apache.sis.feature.DefaultAttributeType#getValueClass() value class} should be
* {@link org.opengis.referencing.crs.CoordinateReferenceSystem}.</p>
*
- * @see #getCRSCharacteristic(Object)
- * @see #getCRSCharacteristic(Feature, String)
++ * @see #getCRSCharacteristic(AbstractFeature, String)
*/
public static final ScopedName CRS_CHARACTERISTIC = Names.createScopedName(SCOPE, null, "crs");
@@@ -164,7 -169,7 +163,7 @@@
* <p>The {@linkplain org.apache.sis.feature.DefaultAttributeType#getValueClass() value class} should be
* {@link Integer}.</p>
*
- * @see #getMaximalLengthCharacteristic(Object)
- * @see #getMaximalLengthCharacteristic(Feature, String)
++ * @see #getMaximalLengthCharacteristic(AbstractFeature, String)
*/
public static final ScopedName MAXIMAL_LENGTH_CHARACTERISTIC = Names.createScopedName(SCOPE, null, "maximalLength");
@@@ -191,7 -196,7 +190,7 @@@
/**
* String representation of the {@link #ENVELOPE_PROPERTY} name.
-- * This can be used in calls to {@link Feature#getPropertyValue(String)}.
++ * This can be used in calls to {@link AbstractFeature#getPropertyValue(String)}.
*/
public static final String ENVELOPE = "sis:envelope";
@@@ -305,8 -312,8 +306,8 @@@
*
* @see org.apache.sis.feature.builder.AttributeTypeBuilder#setCRS(CoordinateReferenceSystem)
*/
- public static CoordinateReferenceSystem getCRSCharacteristic(final Object attribute) {
- return (CoordinateReferenceSystem) getCharacteristic(attribute, CRS);
- public static CoordinateReferenceSystem getCRSCharacteristic(final Feature feature, final String property) {
++ public static CoordinateReferenceSystem getCRSCharacteristic(final AbstractFeature feature, final String property) {
+ return (CoordinateReferenceSystem) getCharacteristic(feature, property, CRS);
}
/**
@@@ -315,8 -322,8 +316,8 @@@
* If the given property is a link, then this method follows the link in the given feature type (if non-null).
*
* <p>This method should be used only when the actual property instance is unknown.
- * Otherwise, {@code getCRSCharacteristic(Property)} should be used because the CRS
- * may vary for each property instance.</p>
- * Otherwise, {@link #getCRSCharacteristic(Feature, String)} should be used because
++ * Otherwise, {@link #getCRSCharacteristic(AbstractFeature, String)} should be used because
+ * the <abbr>CRS</abbr> may vary for each property instance.</p>
*
* @param feature the feature type in which to follow links, or {@code null} if none.
* @param attribute the attribute type for which to get the CRS, or {@code null}.
@@@ -351,8 -360,8 +354,8 @@@
*
* @see org.apache.sis.feature.builder.AttributeTypeBuilder#setMaximalLength(Integer)
*/
- public static Integer getMaximalLengthCharacteristic(final Object attribute) {
- return (Integer) getCharacteristic(attribute, MAXIMAL_LENGTH);
- public static Integer getMaximalLengthCharacteristic(final Feature feature, final String property) {
++ public static Integer getMaximalLengthCharacteristic(final AbstractFeature feature, final String property) {
+ return (Integer) getCharacteristic(feature, property, MAXIMAL_LENGTH);
}
/**
@@@ -361,8 -370,8 +364,8 @@@
* If the given property is a link, then this method follows the link in the given feature type (if non-null).
*
* <p>This method should be used only when the actual property instance is unknown.
- * Otherwise, {@code getMaximalLengthCharacteristic(Property)} should be used because
- * the maximal length may vary for each property instance.</p>
- * Otherwise, {@link #getMaximalLengthCharacteristic(Feature, String)} should be used
++ * Otherwise, {@link #getMaximalLengthCharacteristic(AbstractFeature, String)} should be used
+ * because the maximal length may vary for each property instance.</p>
*
* @param feature the feature type in which to follow links, or {@code null} if none.
* @param attribute the attribute type for which to get the maximal length, or {@code null}.
@@@ -395,29 -404,35 +398,18 @@@
}
/**
- * Fetches from the given property the value or default value of the named characteristic.
- * If the given property is null, or is not an attribute, or does not have characteristics
+ * Fetches from the specified property the value or default value of the named characteristic.
+ * If the specified property is null, or is not an attribute, or does not have characteristics
* of the given name, then this method returns {@code null}.
*
- * @param attribute the attribute from which to get the characteristic value or default value, or {@code null}.
- * @param name name of the characteristic to get.
- * @return the value or default value of the given characteristic in the given property, or {@code null} if none.
+ * @param feature the feature instance from which to get the characteristic.
+ * @param property name of the property for which to get the characteristic.
+ * @param characteristic name of the characteristic from which to get the value or default value.
+ * @return the value or default value of the specified characteristic in the specified property, or {@code null} if none.
+ * @throws PropertyNotFoundException if the {@code property} argument is not the name of a property of the given feature.
*/
- private static Object getCharacteristic(final Object attribute, final String name) {
- if (attribute instanceof AbstractAttribute<?>) {
- final AbstractAttribute<?> at = ((AbstractAttribute<?>) attribute).characteristics().get(name);
- private static Object getCharacteristic(final Feature feature, final String property, final String characteristic) {
- if (feature instanceof AbstractFeature) {
- return ((AbstractFeature) feature).getCharacteristicValue(property, characteristic).orElse(null);
- }
- final Property attribute = feature.getProperty(property);
- if (attribute instanceof Attribute<?>) {
- final Attribute<?> at = ((Attribute<?>) attribute).characteristics().get(characteristic);
-- if (at != null) {
-- final Object value = at.getValue();
-- if (value != null) {
-- return value;
-- }
-- }
- final DefaultAttributeType<?> type = ((AbstractAttribute<?>) attribute).getType().characteristics().get(name);
- final AttributeType<?> type = ((Attribute<?>) attribute).getType().characteristics().get(characteristic);
-- if (type != null) {
-- return type.getDefaultValue();
-- }
-- }
-- return null;
++ private static Object getCharacteristic(final AbstractFeature feature, final String property, final String characteristic) {
++ return feature.getCharacteristicValue(property, characteristic).orElse(null);
}
/**
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/BinaryGeometryFilter.java
index 13024054a0,92502c388f..892b6d6f98
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/BinaryGeometryFilter.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/BinaryGeometryFilter.java
@@@ -27,11 -25,18 +25,12 @@@ import org.apache.sis.geometry.wrapper.
import org.apache.sis.geometry.wrapper.SpatialOperationContext;
import org.apache.sis.feature.privy.AttributeConvention;
import org.apache.sis.filter.internal.Node;
+ import org.apache.sis.util.Exceptions;
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.filter.Filter;
-import org.opengis.filter.Literal;
-import org.opengis.filter.Expression;
-import org.opengis.filter.ValueReference;
-import org.opengis.filter.SpatialOperator;
-import org.opengis.filter.BinarySpatialOperator;
-import org.opengis.filter.InvalidFilterValueException;
-import org.opengis.feature.FeatureType;
-import org.opengis.feature.PropertyNotFoundException;
+// Specific to the main branch:
+import org.apache.sis.feature.DefaultFeatureType;
+import org.apache.sis.pending.geoapi.filter.Literal;
+import org.apache.sis.pending.geoapi.filter.ValueReference;
/**
@@@ -118,8 -128,8 +118,8 @@@ abstract class BinaryGeometryFilter<R>
}
}
}
- } catch (FactoryException | TransformException | IncommensurableException e) {
- throw new IllegalArgumentException(e);
+ } catch (Exception e) {
- throw new InvalidFilterValueException(Exceptions.unwrap(e));
++ throw new IllegalArgumentException(Exceptions.unwrap(e));
}
this.expression1 = expression1;
this.expression2 = expression2;
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/BinarySpatialFilter.java
index 607cd0ec15,3e03ba7213..02c3a978dd
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/BinarySpatialFilter.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/BinarySpatialFilter.java
@@@ -23,9 -23,12 +23,10 @@@ import org.apache.sis.geometry.Wraparou
import org.apache.sis.geometry.wrapper.SpatialOperationContext;
import org.apache.sis.geometry.wrapper.GeometryWrapper;
import org.apache.sis.geometry.wrapper.Geometries;
+ import org.apache.sis.util.Exceptions;
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.filter.Expression;
-import org.opengis.filter.SpatialOperatorName;
-import org.opengis.filter.BinarySpatialOperator;
+// Specific to the main branch:
+import org.apache.sis.pending.geoapi.filter.SpatialOperatorName;
/**
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/DistanceFilter.java
index aec9b2e313,3fd8a10447..aae97abf5a
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/DistanceFilter.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/DistanceFilter.java
@@@ -25,10 -25,13 +25,11 @@@ import org.opengis.geometry.Geometry
import org.apache.sis.geometry.wrapper.Geometries;
import org.apache.sis.geometry.wrapper.GeometryWrapper;
import org.apache.sis.geometry.wrapper.SpatialOperationContext;
+ import org.apache.sis.util.Exceptions;
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.filter.Literal;
-import org.opengis.filter.Expression;
-import org.opengis.filter.DistanceOperator;
-import org.opengis.filter.DistanceOperatorName;
+// Specific to the main branch:
+import org.apache.sis.pending.geoapi.filter.Literal;
+import org.apache.sis.pending.geoapi.filter.DistanceOperatorName;
/**
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/InvalidXPathException.java
index 86379fdf59,39c1a5d428..aae8e467e6
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/InvalidXPathException.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/InvalidXPathException.java
@@@ -16,9 -16,12 +16,9 @@@
*/
package org.apache.sis.filter;
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.filter.InvalidFilterValueException;
-
/**
- * Exceptions thrown when the XPath in an expression is invalid or unsupported.
+ * Exception thrown when the XPath in an expression is invalid or unsupported.
* Apache SIS currently supports only a small subset of XPath syntax, mostly paths of
* the form {@code "a/b/c"} (and not everywhere) and the {@code "Q{namespace}"} syntax.
*
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/internal/GeometryConverter.java
index 9ef6b01901,5e77717b8c..6e28225258
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/internal/GeometryConverter.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/internal/GeometryConverter.java
@@@ -29,11 -29,13 +29,12 @@@ import org.apache.sis.geometry.Immutabl
import org.apache.sis.geometry.WraparoundMethod;
import org.apache.sis.geometry.wrapper.Geometries;
import org.apache.sis.geometry.wrapper.GeometryWrapper;
+ import org.apache.sis.feature.internal.Resources;
import org.apache.sis.filter.Optimization;
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.filter.Expression;
-import org.opengis.filter.InvalidFilterValueException;
-import org.opengis.coordinate.MismatchedDimensionException;
+// Specific to the main branch:
+import org.opengis.geometry.MismatchedDimensionException;
+import org.apache.sis.filter.Expression;
/**
@@@ -73,14 -78,40 +77,40 @@@ class GeometryConverter<R,G> extends No
final Expression<R,?> expression;
/**
- * Creates a new converter expression.
+ * Creates a new converter for the given expression producing library-specific objects.
+ * This constructor is for subclasses. Use {@link #create(Geometries, Expression)} instead.
*
* @param library the geometry library to use.
- * @param expression the expression providing source values.
+ * @param expression the expression providing geometric objects of the given library.
*/
- public GeometryConverter(final Geometries<G> library, final Expression<R,?> expression) {
- this.expression = Objects.requireNonNull(expression);
+ GeometryConverter(final Geometries<G> library, final Expression<R,?> expression) {
this.library = Objects.requireNonNull(library);
+ this.expression = Objects.requireNonNull(expression);
+ }
+
+ /**
+ * Creates a new converter for the given expression producing library-specific objects.
+ *
+ * @param library the geometry library to use.
+ * @param expression the expression providing geometric objects of the given library.
+ * @return the geometry converter.
+ */
+ @SuppressWarnings("unchecked")
+ public static <R,G> GeometryConverter<R,G> create(final Geometries<G> library, final Expression<R,?> expression) {
+ if (expression instanceof GeometryConverter<?,?>) {
+ final var candidate = (GeometryConverter<R,?>) expression;
+ if (library.equals(candidate.library)) {
+ return (GeometryConverter<R,G>) expression;
+ }
- throw new InvalidFilterValueException(Resources.format(
++ throw new IllegalArgumentException(Resources.format(
+ Resources.Keys.MixedGeometryImplementation_2,
+ library.library, candidate.library.library));
+ }
+ GeometryConverter<?,G> candidate = GeometryFromFeature.tryCreate(library, expression);
+ if (candidate == null) {
+ return new GeometryConverter<>(library, expression);
+ }
+ return (GeometryConverter<R,G>) candidate;
}
/**
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/internal/GeometryFromFeature.java
index 0000000000,178a668113..339a344190
mode 000000,100644..100644
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/internal/GeometryFromFeature.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/internal/GeometryFromFeature.java
@@@ -1,0 -1,108 +1,107 @@@
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ package org.apache.sis.filter.internal;
+
+ import org.opengis.referencing.crs.CoordinateReferenceSystem;
+ import org.apache.sis.geometry.wrapper.Geometries;
+ import org.apache.sis.geometry.wrapper.GeometryWrapper;
+ import org.apache.sis.feature.privy.AttributeConvention;
+ import org.apache.sis.filter.privy.XPath;
+
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.feature.Feature;
-import org.opengis.filter.Expression;
-import org.opengis.filter.ValueReference;
-import org.opengis.filter.InvalidFilterValueException;
++// Specific to the main branch:
++import org.apache.sis.filter.Expression;
++import org.apache.sis.feature.AbstractFeature;
++import org.apache.sis.pending.geoapi.filter.ValueReference;
+
+
+ /**
+ * Expression whose input is a feature instance and output is a geometry wrapper.
+ * This converter evaluates another expression, which is given at construction time,
+ * then wraps the result in a {@link GeometryWrapper}.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ *
+ * @param <G> the geometry implementation type.
+ */
-final class GeometryFromFeature<G> extends GeometryConverter<Feature, G> {
++final class GeometryFromFeature<G> extends GeometryConverter<AbstractFeature, G> {
+ /**
+ * For cross-version compatibility.
+ */
+ private static final long serialVersionUID = -550060050444279386L;
+
+ /**
+ * Name of the property from which the geometry object is read, or {@code null} if none.
+ * This is used for fetching the default <abbr>CRS</abbr> when the geometry has none.
+ */
+ private final String propertyName;
+
+ /**
+ * Creates a new converter for the given expression producing library-specific objects.
+ *
+ * @param library the geometry library to use.
+ * @param expression the expression providing geometric objects of the given library.
+ */
- private GeometryFromFeature(Geometries<G> library, Expression<Feature,?> expression, String propertyName) {
++ private GeometryFromFeature(Geometries<G> library, Expression<AbstractFeature,?> expression, String propertyName) {
+ super(library, expression);
+ this.propertyName = propertyName;
+ }
+
+ /**
+ * Tries to create a new converter for the given expression.
+ *
+ * @param library the geometry library to use.
+ * @param expression the expression providing geometric objects of the given library.
+ * @return the geometry converter, or {@code null} if the given expression cannot be used.
+ */
+ static <G> GeometryFromFeature<G> tryCreate(final Geometries<G> library, final Expression<?,?> expression) {
- if (Feature.class.isAssignableFrom(expression.getResourceClass()) && expression instanceof ValueReference<?,?>) {
++ if (AbstractFeature.class.isAssignableFrom(expression.getResourceClass()) && expression instanceof ValueReference<?,?>) {
+ final var xpath = new XPath(((ValueReference<?,?>) expression).getXPath());
+ if (xpath.path == null) {
+ /*
+ * The expression type is actually <? extends R>, so it is not really correct to cast to <R>.
+ * However, we are going to use <R> as input only, not as output. In such case, it is okay to
+ * ignore the fact that <R> may be a subtype of `Feature`.
+ */
+ @SuppressWarnings("unchecked")
- final var ve = (Expression<Feature,?>) expression;
++ final var ve = (Expression<AbstractFeature,?>) expression;
+ return new GeometryFromFeature<>(library, ve, xpath.tip);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Evaluates the expression and converts the value to a geometry wrapper.
+ * If the geometry library does not store the <abbr>CRS</abbr>,
+ * the coordinate reference system is taken from the feature.
+ *
+ * @param input the geometry to evaluate with this expression.
+ * @return the geometry wrapper, or {@code null} if the evaluated value is null.
+ * @throws InvalidFilterValueException if the expression result is not an instance of a supported type.
+ */
+ @Override
- public GeometryWrapper apply(final Feature input) {
++ public GeometryWrapper apply(final AbstractFeature input) {
+ final GeometryWrapper wrapper = super.apply(input);
+ if (wrapper.getCoordinateReferenceSystem() == null) {
+ final CoordinateReferenceSystem crs = AttributeConvention.getCRSCharacteristic(input, propertyName);
+ if (crs != null) {
+ wrapper.setCoordinateReferenceSystem(crs);
+ }
+ }
+ return wrapper;
+ }
+ }
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/internal/Node.java
index 1add37fb1b,5be96dd66d..45fd2b8a69
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/internal/Node.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/internal/Node.java
@@@ -91,10 -93,10 +91,10 @@@ public abstract class Node implements S
*
* @see Expression#getFunctionName()
*/
- protected static <T> AttributeType<T> createType(final Class<T> type, final Object name) {
+ protected static <T> DefaultAttributeType<T> createType(final Class<T> type, final Object name) {
- // We do not use `Map.of(…)` for letting the attribute type constructor do the null check.
+ // We do not use `Map.of(…)` for better exception message in case of null name.
return new DefaultAttributeType<>(Collections.singletonMap(DefaultAttributeType.NAME_KEY, name),
- type, 1, 1, null, (AttributeType<?>[]) null);
+ type, 1, 1, null, (DefaultAttributeType<?>[]) null);
}
/**
@@@ -167,16 -169,16 +167,16 @@@
/**
* Returns an expression whose results is a geometry wrapper.
+ * Note that the {@code apply(R)} method of the returned expression may throw {@link BackingStoreException}.
*
- * @param <R> the type of resources (e.g. {@link org.opengis.feature.Feature}) used as inputs.
+ * @param <R> the type of resources (e.g. {@code Feature}) used as inputs.
* @param <G> the geometry implementation type.
* @param library the geometry library to use.
- * @param expression the expression providing source values.
+ * @param expression the expression providing geometry instances of the given library.
* @return an expression whose results is a geometry wrapper.
- * @throws InvalidFilterValueException if the given expression is already a wrapper
+ * @throws IllegalArgumentException if the given expression is already a wrapper
* but for another geometry implementation.
*/
- @SuppressWarnings("unchecked")
protected static <R,G> Expression<R, GeometryWrapper> toGeometryWrapper(
final Geometries<G> library, final Expression<R,?> expression)
{
@@@ -193,9 -187,9 +185,9 @@@
/**
* If the given exception was wrapped by {@link #toGeometryWrapper(Geometries, Expression)},
- * returns the original expression. Otherwise returns the given expression.
+ * returns the original expression. Otherwise, returns the given expression as-is.
*
- * @param <R> the type of resources (e.g. {@link org.opengis.feature.Feature}) used as inputs.
+ * @param <R> the type of resources (e.g. {@code Feature}) used as inputs.
* @param expression the expression to unwrap.
* @return the unwrapped expression.
*/
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/sqlmm/GeometryParser.java
index a5f3580da6,c9fe68215e..ebc7fb9b7d
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/sqlmm/GeometryParser.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/filter/sqlmm/GeometryParser.java
@@@ -20,10 -20,12 +20,11 @@@ import org.opengis.referencing.crs.Coor
import org.apache.sis.geometry.wrapper.Geometries;
import org.apache.sis.geometry.wrapper.GeometryWrapper;
import org.apache.sis.util.Classes;
+ import org.apache.sis.util.Exceptions;
import org.apache.sis.util.resources.Errors;
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.filter.Expression;
-import org.opengis.filter.InvalidFilterValueException;
+// Specific to the main branch:
+import org.apache.sis.filter.Expression;
/**
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/Geometries.java
index fae0cd3aee,d65ca53799..640dc3b8fd
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/Geometries.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/Geometries.java
@@@ -38,6 -39,10 +39,10 @@@ import org.apache.sis.system.Loggers
import org.apache.sis.math.Vector;
import org.apache.sis.setup.GeometryLibrary;
import org.apache.sis.util.resources.Errors;
+ import org.apache.sis.util.collection.BackingStoreException;
+
-// Specific to the geoapi-3.1 and 4.0 branches:
-import org.opengis.feature.Feature;
++// Specific to the main branch:
++import org.apache.sis.feature.AbstractFeature;
// Specific to the main and geoapi-3.1 branches:
import org.opengis.geometry.MismatchedDimensionException;
@@@ -227,13 -233,56 +233,56 @@@ public abstract class Geometries<G> imp
return wrapper.implementation();
}
+ /**
+ * Wraps the geometry stored in a property of the given feature. This method should be used
+ * instead of {@link #wrap(Object)} when the value come from a feature instance in order to
+ * allow <abbr>SIS</abbr> to fetch a default <abbr>CRS</abbr> when the geometry object does
+ * not specify the <abbr>CRS</abbr> itself.
+ *
+ * @param feature the feature from which wrap a geometry, or {@code null} if none.
+ * @param property the name of the property from which to get the default <abbr>CRS</abbr>.
+ * @return a wrapper for the geometry implementation of the given feature, or empty value.
+ * @throws BackingStoreException if the operation failed because of a checked exception.
+ */
- public static Optional<GeometryWrapper> wrap(final Feature feature, final String property) {
++ public static Optional<GeometryWrapper> wrap(final AbstractFeature feature, final String property) {
+ if (feature == null) {
+ return Optional.empty();
+ }
+ final Optional<GeometryWrapper> value = wrap(feature.getPropertyValue(property));
+ value.ifPresent((wrapper) -> {
+ if (wrapper.crs == null) {
+ wrapper.crs = AttributeConvention.getCRSCharacteristic(feature, property);
+ }
+ });
+ return value;
+ }
+
+ /**
+ * Wraps the default geometry of the given feature. This method should be used instead of {@link #wrap(Object)}
+ * when possible because it allows <abbr>SIS</abbr> to fetch a default <abbr>CRS</abbr> when the geometry object
+ * does not specify the <abbr>CRS</abbr> itself.
+ *
+ * @param feature the feature from which wrap the default geometry, or {@code null} if none.
+ * @return a wrapper for the geometry implementation of the given feature, or empty value.
+ * @throws BackingStoreException if the operation failed because of a checked exception.
+ */
- public static Optional<GeometryWrapper> wrap(final Feature feature) {
++ public static Optional<GeometryWrapper> wrap(final AbstractFeature feature) {
+ return wrap(feature, AttributeConvention.GEOMETRY);
+ }
+
/**
* Wraps the given geometry implementation if recognized.
* If the given object is already an instance of {@link GeometryWrapper}, then it is returned as-is.
* If the given object is not recognized, then this method returns an empty value.
*
+ * <h4>Recommended alternative</h4>
- * Prefers {@link #wrap(Feature)} for wrapping the default geometry of a feature instance.
++ * Prefers {@link #wrap(AbstractFeature)} for wrapping the default geometry of a feature instance.
+ * This is preferred for allowing <abbr>SIS</abbr> to fetch the default <abbr>CRS</abbr>
+ * from the feature type when that information was not present in the geometry object.
+ *
* @param geometry the geometry instance to wrap (can be {@code null}).
* @return a wrapper for the given geometry implementation, or empty value.
+ * @throws BackingStoreException if the operation failed because of a checked exception.
*
* @see #castOrWrap(Object)
* @see #implementation(Object)
diff --cc endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java
index ac52762d6b,3b1c1ac9bc..127f829658
--- a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java
+++ b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/geometry/wrapper/GeometryWrapper.java
@@@ -103,14 -132,17 +125,16 @@@ public abstract class GeometryWrapper e
}
/**
- * Gets the Coordinate Reference System (CRS) of this geometry. In some libraries (for example JTS) the CRS
- * is stored in the {@link Geometries#rootClass} instances of that library. In other libraries (e.g. Java2D)
- * the CRS is stored only in this {@code GeometryWrapper} instance.
+ * Gets the Coordinate Reference System (<abbr>CRS</abbr>) of the geometry.
+ * In some libraries such as <abbr>JTS</abbr>, some <abbr>CRS</abbr> information can be stored in the
+ * geometry object of that library. In other libraries such as Java2D, the <abbr>CRS</abbr> is stored
+ * only in this {@code GeometryWrapper} instance.
*
- * @return the geometry CRS, or {@code null} if unknown.
- * @throws BackingStoreException if the CRS is defined by a SRID code and that code cannot be used.
+ * @return the geometry <abbr>CRS</abbr>, or {@code null} if unknown.
*/
- public abstract CoordinateReferenceSystem getCoordinateReferenceSystem();
- @Override
+ public final CoordinateReferenceSystem getCoordinateReferenceSystem() {
+ return crs;
+ }
/**
* Sets the coordinate reference system.
@@@ -121,7 -154,32 +146,31 @@@
*
* @see #transform(CoordinateReferenceSystem)
*/
- public abstract void setCoordinateReferenceSystem(CoordinateReferenceSystem crs);
+ public void setCoordinateReferenceSystem(final CoordinateReferenceSystem crs) {
+ ArgumentChecks.ensureDimensionMatches("crs", getCoordinateDimension(), crs);
+ this.crs = crs;
+ }
+
+ /**
+ * Returns the dimension of the coordinates that define this geometry.
+ * It must be the same as the dimension of the coordinate reference system for this geometry.
+ *
+ * @return the coordinate dimension.
+ */
- @Override
+ public int getCoordinateDimension() {
+ return Geometries.BIDIMENSIONAL;
+ }
+
+ /**
+ * Creates an initially empty envelope with the <abbr>CRS</abbr> of this geometry.
+ * If this geometry has no <abbr>CRS</abbr>, then a two- or three-dimensional envelope is created.
+ * This is a convenience method for {@link #getEnvelope()} implementations.
+ *
+ * @return an initially empty envelope.
+ */
+ protected final GeneralEnvelope createEnvelope() {
+ return (crs != null) ? new GeneralEnvelope(crs) : new GeneralEnvelope(getCoordinateDimension());
+ }
/**
* Returns the geometry bounding box, together with its coordinate reference system.
@@@ -497,11 -559,20 +548,19 @@@
*
* @see #getCoordinateReferenceSystem()
*/
- @Override
public GeometryWrapper transform(final CoordinateReferenceSystem targetCRS) throws TransformException {
- if (targetCRS == null) {
+ if (targetCRS == null || targetCRS == crs || crs == null) {
return this;
}
- throw new UnsupportedOperationException(Geometries.unsupported("transform"));
+ try {
+ return transform(CRS.findOperation(crs, targetCRS, null), false);
+ } catch (FactoryException e) {
+ /*
+ * We wrap that exception because `Geometry.transform(…)` does not declare `FactoryException`.
+ * We may revisit in a future version if `Geometry.transform(…)` method declaration is updated.
+ */
- throw new TransformException(e);
++ throw new TransformException(e.toString(), e);
+ }
}
/**
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/VerticalInfo.java
index 33ee468d60,89bd846962..9a5828472a
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/VerticalInfo.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/io/wkt/VerticalInfo.java
@@@ -109,7 -109,7 +109,7 @@@ final class VerticalInfo
*/
final VerticalInfo resolve(final VerticalCRS crs) {
if (crs != null) {
- if (PseudoDatum.of(crs).getVerticalDatumType() == VerticalDatumType.GEOIDAL) {
- if (DatumOrEnsemble.asDatum(crs).getRealizationMethod().orElse(null) == RealizationMethod.GEOID) {
++ if (DatumOrEnsemble.asDatum(crs).getVerticalDatumType() == VerticalDatumType.GEOIDAL) {
return resolve(crs, crs.getCoordinateSystem().getAxis(0));
}
}
@@@ -183,7 -183,8 +183,7 @@@
*/
final VerticalCS cs = csFactory.createVerticalCS (properties(axis.getName()), axis);
extent.setVerticalCRS(crsFactory.createVerticalCRS(properties((isUP ? compatibleCRS : axis).getName()),
- PseudoDatum.of(compatibleCRS),
- compatibleCRS.getDatum(),
- compatibleCRS.getDatumEnsemble(),
++ DatumOrEnsemble.asDatum(compatibleCRS),
cs));
return next;
}
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/EllipsoidalHeightSeparator.java
index 0dc7d6e7f0,366257c40e..bc11f13a12
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/EllipsoidalHeightSeparator.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/EllipsoidalHeightSeparator.java
@@@ -42,10 -42,8 +42,10 @@@ import static org.apache.sis.referencin
// Specific to the main and geoapi-3.1 branches:
import org.opengis.referencing.crs.GeographicCRS;
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.referencing.datum.DatumEnsemble;
+// Specific to the main branch:
- import org.apache.sis.referencing.datum.PseudoDatum;
++import org.apache.sis.referencing.datum.DatumOrEnsemble;
+import org.apache.sis.referencing.datum.DefaultDatumEnsemble;
+import static org.apache.sis.pending.geoapi.referencing.MissingMethods.getDatumEnsemble;
/**
@@@ -85,8 -78,7 +85,8 @@@ final class EllipsoidalHeightSeparator
*/
EllipsoidalHeightSeparator(final GeodeticCRS baseCRS, final boolean vertical) {
this.datum = baseCRS.getDatum();
- this.ensemble = baseCRS.getDatumEnsemble();
+ this.ensemble = getDatumEnsemble(baseCRS);
- this.pseudo = PseudoDatum.of(baseCRS);
++ this.pseudo = DatumOrEnsemble.asDatum(baseCRS);
this.vertical = vertical;
}
@@@ -121,7 -113,8 +121,7 @@@
VerticalCRS component = CommonCRS.Vertical.ELLIPSOIDAL.crs();
if (!Utilities.equalsIgnoreMetadata(component.getCoordinateSystem(), cs)) {
component = factory().createVerticalCRS(getPropertiesForModifiedCRS(component),
- PseudoDatum.of(component),
- component.getDatum(),
- component.getDatumEnsemble(),
++ DatumOrEnsemble.asDatum(component),
(VerticalCS) cs);
}
return component;
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/MultiRegisterOperations.java
index 59974c214f,75d861363b..be5d3e4f91
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/MultiRegisterOperations.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/MultiRegisterOperations.java
@@@ -57,7 -62,7 +57,7 @@@ import org.apache.sis.util.iso.Abstract
* <p>This class delegates its work to {@linkplain CRS#forCode(String) static methods} or to
* {@link MultiAuthoritiesFactory}. It does not provide new services compared to the above,
* but provides a more high-level <abbr>API</abbr> with the most important registry-based
-- * services in a single place. {@link RegisterOperations} can also be used as en entry point,
++ * services in a single place. {@code RegisterOperations} can also be used as en entry point,
* with accesses to the low-level <abbr>API</abbr> granted by {@link #getFactory(Class)}.</p>
*
* <h2>User-defined geodetic registries</h2>
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/crs/AbstractSingleCRS.java
index 11ea3720f3,686ef5b11a..e6d0cea5cf
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/crs/AbstractSingleCRS.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/crs/AbstractSingleCRS.java
@@@ -104,33 -102,13 +103,13 @@@ class AbstractSingleCRS<D extends Datum
final CoordinateSystem cs)
{
super(properties, cs);
- /*
- * If the given datum is actually a wrapper for a datum ensemble, unwrap the datum ensemble
- * and verify the consistency. This class should never store `PseudoDatum` instances.
- */
- if (datum instanceof PseudoDatum<?>) {
- @SuppressWarnings("unchecked") // Type is verified below.
- final var pseudo = (PseudoDatum<D>) datum;
- final var member = pseudo.getInterface();
- if (member != datumType) {
- throw new IllegalArgumentException(Errors.forProperties(properties)
- .getString(Errors.Keys.IllegalArgumentClass_2, "datum",
- PseudoDatum.class.getSimpleName() + '<' + member.getSimpleName() + '>'));
- }
- if (ensemble == null) {
- this.ensemble = pseudo.ensemble;
- } else if (Utilities.equalsIgnoreMetadata(ensemble, pseudo.ensemble)) {
- this.ensemble = ensemble;
- } else {
- throw new IllegalArgumentException(Errors.forProperties(properties)
- .getString(Errors.Keys.IncompatiblePropertyValue_1, "pseudo-datum"));
- }
- ArgumentChecks.ensureNonEmpty((ensemble != null) ? "ensemble" : "pseudo-datum", this.ensemble.getMembers());
- } else {
- this.datum = datum;
- this.ensemble = ensemble;
- checkDatum(properties);
- if (datum instanceof DatumEnsemble<?>) {
++ if (datum instanceof DefaultDatumEnsemble<?>) {
+ throw new IllegalArgumentException(Errors.forProperties(properties)
- .getString(Errors.Keys.IllegalArgumentClass_2, "datum", DatumEnsemble.class.getSimpleName()));
++ .getString(Errors.Keys.IllegalArgumentClass_2, "datum", DefaultDatumEnsemble.class.getSimpleName()));
}
+ this.datum = datum;
+ this.ensemble = ensemble;
+ checkDatum(properties);
}
/**
@@@ -190,11 -168,11 +169,11 @@@
AbstractSingleCRS(final SingleCRS crs) {
super(crs);
datum = (D) crs.getDatum();
- if (datum instanceof PseudoDatum<?>) {
- if (datum instanceof DatumEnsemble<?>) {
++ if (datum instanceof DefaultDatumEnsemble<?>) {
throw new IllegalArgumentException(
- Errors.format(Errors.Keys.IllegalPropertyValueClass_2, "datum", PseudoDatum.class));
- Errors.format(Errors.Keys.IllegalPropertyValueClass_2, "datum", DatumEnsemble.class));
++ Errors.format(Errors.Keys.IllegalPropertyValueClass_2, "datum", DefaultDatumEnsemble.class));
}
- ensemble = (DatumEnsemble<D>) crs.getDatumEnsemble();
+ ensemble = (DefaultDatumEnsemble<D>) MissingMethods.getDatumEnsemble(crs);
checkDatum(null);
}
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/DatumOrEnsemble.java
index 0000000000,7cf521849a..9823622305
mode 000000,100644..100644
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/DatumOrEnsemble.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/DatumOrEnsemble.java
@@@ -1,0 -1,456 +1,447 @@@
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ package org.apache.sis.referencing.datum;
+
+ import java.util.ArrayDeque;
+ import java.util.Collection;
+ import java.util.Iterator;
+ import java.util.Optional;
+ import java.util.function.Function;
+ import org.opengis.referencing.IdentifiedObject;
+ import org.opengis.referencing.crs.CoordinateReferenceSystem;
+ import org.opengis.referencing.crs.EngineeringCRS;
+ import org.opengis.referencing.crs.GeodeticCRS;
+ import org.opengis.referencing.crs.SingleCRS;
+ import org.opengis.referencing.crs.TemporalCRS;
+ import org.opengis.referencing.crs.VerticalCRS;
+ import org.opengis.referencing.crs.CompoundCRS;
+ import org.opengis.referencing.datum.Datum;
+ import org.opengis.referencing.datum.EngineeringDatum;
+ import org.opengis.referencing.datum.GeodeticDatum;
+ import org.opengis.referencing.datum.TemporalDatum;
+ import org.opengis.referencing.datum.VerticalDatum;
+ import org.opengis.referencing.datum.PrimeMeridian;
+ import org.opengis.referencing.datum.Ellipsoid;
+ import org.opengis.metadata.quality.PositionalAccuracy;
+ import org.apache.sis.util.Static;
+ import org.apache.sis.util.Utilities;
+ import org.apache.sis.referencing.IdentifiedObjects;
+ import org.apache.sis.referencing.GeodeticException;
+
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.referencing.crs.ParametricCRS;
-import org.opengis.referencing.datum.DatumEnsemble;
-import org.opengis.referencing.datum.ParametricDatum;
++// Specific to the main branch:
++import java.util.logging.Logger;
++import org.apache.sis.system.Modules;
++import org.apache.sis.util.logging.Logging;
+
+
+ /**
+ * Utility methods for working on objects that may be {@code Datum} or {@code DatumEnsemble}.
+ * The methods in this class view an ensemble as if it was a datum for the sake of simplicity.
+ * For example, {@code DatumOrEnsemble.of(crs)} allows to
+ * {@linkplain IdentifiedObjects#isHeuristicMatchForName compare the datum name}
+ * without the need to check which one of the {@code getDatum()} or {@code getDatumEnsemble()}
+ * methods returns a non-null value.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @version 1.5
+ * @since 1.5
+ */
++@SuppressWarnings("unchecked") // See `getDatumEnsemble(…)`
+ public final class DatumOrEnsemble extends Static {
+ /**
+ * Do not allow instantiation of this class.
+ */
+ private DatumOrEnsemble() {
+ }
+
+ /**
+ * Returns the datum of the given <abbr>CRS</abbr> if presents, or the datum ensemble otherwise.
+ * This is an alternative to the {@code asDatum(…)} methods when the caller does not need to view
+ * the returned object as a datum.
+ *
+ * @param crs the <abbr>CRS</abbr> from which to get the datum or ensemble, or {@code null}.
+ * @return the datum if present, or the datum ensemble otherwise, or {@code null}.
+ */
+ public static IdentifiedObject of(final SingleCRS crs) {
+ if (crs == null) return null;
+ final Datum datum = crs.getDatum();
- return (datum != null) ? datum : crs.getDatumEnsemble();
++ return (datum != null) ? datum : getDatumEnsemble(crs);
++ }
++
++ /**
++ * Returns the datum ensemble of the given <abbr>CRS</abbr>. This method uses reflection
++ * because the {@code SingleCRS.getDatumEnsemble()} method was not available in GeoAPI 3.0.
++ *
++ * <p>The {@code <?>} parameterized type is intentionally omitted. It makes this method unsafe,
++ * but it should be okay for datum ensembles created by {@link DefaultDatumEnsemble} static methods.
++ * The safety problem is resolved on the GeoAP 3.1 branch.</p>
++ */
++ @SuppressWarnings("rawtypes")
++ private static DefaultDatumEnsemble getDatumEnsemble(final CoordinateReferenceSystem crs) {
++ try {
++ final Object ensemble = crs.getClass().getMethod("getDatumEnsemble", (Class<?>[]) null).invoke(crs, (Object[]) null);
++ if (ensemble instanceof DefaultDatumEnsemble<?>) {
++ return (DefaultDatumEnsemble<?>) ensemble;
++ }
++ } catch (ReflectiveOperationException e) {
++ Logging.ignorableException(Logger.getLogger(Modules.REFERENCING), DatumOrEnsemble.class, "getDatumEnsemble", e);
++ }
++ return null;
+ }
+
+ /**
+ * Returns the datum or ensemble of a coordinate operation from <var>source</var> to <var>target</var>.
+ * If the two given coordinate reference systems are associated to the same datum, then this method returns
+ * the <var>target</var> datum. Otherwise, this method returns the largest ensemble which fully contains the
+ * datum or datum ensemble of the other <abbr>CRS</abbr>.
+ * That largest common ensemble is interpreted as the new target of the operation result.
+ * If none of the <var>source</var> or <var>target</var> datum ensembles met the above criteria,
+ * then this method returns an empty value.
+ * A non-empty value means that it is okay, for low accuracy requirements, to ignore the datum shift.
+ *
+ * <p>This is an alternative to the {@code asTargetDatum(…)} methods
+ * when the caller does not need to view the returned object as a datum.</p>
+ *
+ * @param source the source <abbr>CRS</abbr> of a coordinate operation.
+ * @param target the target <abbr>CRS</abbr> of a coordinate operation.
+ * @return datum or datum ensemble of the coordinate operation result if it is okay to ignore datum shift.
+ * @throws NullPointerException if any argument is null.
+ */
+ public static Optional<IdentifiedObject> ofTarget(final SingleCRS source, final SingleCRS target) {
+ return asTargetDatum(source, source.getDatum(),
+ target, target.getDatum(),
+ (ensemble) -> ensemble);
+ }
+
+ /**
+ * Returns the datum (preferred) or ensemble (fallback) of the given geodetic <abbr>CRS</abbr>.
+ * If the given <abbr>CRS</abbr> is associated to a non-null datum, then this method returns that datum.
+ * Otherwise, this method returns the <abbr>CRS</abbr> datum ensemble as a pseudo-datum.
+ *
+ * <h4>Common properties</h4>
+ * If an ensemble is viewed as a pseudo-datum, then the implementation of the {@link GeodeticDatum#getEllipsoid()}
+ * and {@link GeodeticDatum#getPrimeMeridian()} methods will verify that all members have the same ellipsoid or
+ * prime meridian respectively. If this condition does not hold, then a {@link GeodeticException} will be thrown.
+ * Note that this verification is done when the above-cited methods are invoked, not when this {@code asDatum(…)}
+ * method is invoked.
+ *
+ * @param crs the coordinate reference system for which to get the datum or datum ensemble, or {@code null}.
+ * @return the datum or pseudo-datum of the given <abbr>CRS</abbr>, or {@code null}.
+ */
+ public static GeodeticDatum asDatum(final GeodeticCRS crs) {
+ if (crs == null) return null;
+ final GeodeticDatum datum = crs.getDatum();
- return (datum != null) ? datum : DefaultDatumEnsemble.Geodetic.datum(crs.getDatumEnsemble());
++ return (datum != null) ? datum : DefaultDatumEnsemble.Geodetic.datum(getDatumEnsemble(crs));
+ }
+
+ /**
+ * Returns the datum (preferred) or ensemble (fallback) of the given vertical <abbr>CRS</abbr>.
+ * If the given <abbr>CRS</abbr> is associated to a non-null datum, then this method returns that datum.
+ * Otherwise, this method returns the <abbr>CRS</abbr> datum ensemble as a pseudo-datum.
+ *
+ * @param crs the coordinate reference system for which to get the datum or datum ensemble, or {@code null}.
+ * @return the datum or pseudo-datum of the given <abbr>CRS</abbr>, or {@code null}.
+ */
+ public static VerticalDatum asDatum(final VerticalCRS crs) {
+ if (crs == null) return null;
+ final VerticalDatum datum = crs.getDatum();
- return (datum != null) ? datum : DefaultDatumEnsemble.Vertical.datum(crs.getDatumEnsemble());
++ return (datum != null) ? datum : DefaultDatumEnsemble.Vertical.datum(getDatumEnsemble(crs));
+ }
+
+ /**
+ * Returns the datum (preferred) or ensemble (fallback) of the given temporal <abbr>CRS</abbr>.
+ * If the given <abbr>CRS</abbr> is associated to a non-null datum, then this method returns that datum.
+ * Otherwise, this method returns the <abbr>CRS</abbr> datum ensemble as a pseudo-datum.
+ *
+ * <h4>Common property</h4>
+ * If an ensemble is viewed as a pseudo-datum, then the implementation of the {@link TemporalDatum#getOrigin()}
+ * method will verify that all members have the same origin. If this condition does not hold,
+ * then a {@link GeodeticException} will be thrown. Note that this verification is done when
+ * the above-cited method is invoked, not when this {@code asDatum(…)} method is invoked.
+ *
+ * @param crs the coordinate reference system for which to get the datum or datum ensemble, or {@code null}.
+ * @return the datum or pseudo-datum of the given <abbr>CRS</abbr>, or {@code null}.
+ */
+ public static TemporalDatum asDatum(final TemporalCRS crs) {
+ if (crs == null) return null;
+ final TemporalDatum datum = crs.getDatum();
- return (datum != null) ? datum : DefaultDatumEnsemble.Time.datum(crs.getDatumEnsemble());
- }
-
- /**
- * Returns the datum (preferred) or ensemble (fallback) of the given parametric <abbr>CRS</abbr>.
- * If the given <abbr>CRS</abbr> is associated to a non-null datum, then this method returns that datum.
- * Otherwise, this method returns the <abbr>CRS</abbr> datum ensemble as a pseudo-datum.
- *
- * @param crs the coordinate reference system for which to get the datum or datum ensemble, or {@code null}.
- * @return the datum or pseudo-datum of the given <abbr>CRS</abbr>, or {@code null}.
- *
- * @since 2.0 (temporary version number until this branch is released)
- */
- public static ParametricDatum asDatum(final ParametricCRS crs) {
- if (crs == null) return null;
- final ParametricDatum datum = crs.getDatum();
- return (datum != null) ? datum : DefaultDatumEnsemble.Parametric.datum(crs.getDatumEnsemble());
++ return (datum != null) ? datum : DefaultDatumEnsemble.Time.datum(getDatumEnsemble(crs));
+ }
+
+ /**
+ * Returns the datum (preferred) or ensemble (fallback) of the given engineering <abbr>CRS</abbr>.
+ * If the given <abbr>CRS</abbr> is associated to a non-null datum, then this method returns that datum.
+ * Otherwise, this method returns the <abbr>CRS</abbr> datum ensemble as a pseudo-datum.
+ *
+ * @param crs the coordinate reference system for which to get the datum or datum ensemble, or {@code null}.
+ * @return the datum or pseudo-datum of the given <abbr>CRS</abbr>, or {@code null}.
+ */
+ public static EngineeringDatum asDatum(final EngineeringCRS crs) {
+ if (crs == null) return null;
+ final EngineeringDatum datum = crs.getDatum();
- return (datum != null) ? datum : DefaultDatumEnsemble.Engineering.datum(crs.getDatumEnsemble());
++ return (datum != null) ? datum : DefaultDatumEnsemble.Engineering.datum(getDatumEnsemble(crs));
+ }
+
+ /**
+ * Returns the datum or pseudo-datum of the result of an operation between the given geodetic <abbr>CRS</abbr>s.
+ * If the two given coordinate reference systems are associated to the same datum, then this method returns
+ * the <var>target</var> datum. Otherwise, this method returns a pseudo-datum for the largest ensemble which
+ * fully contains the datum or datum ensemble of the other <abbr>CRS</abbr>.
+ * That largest common ensemble is interpreted as the new target of the operation result.
+ * If none of the <var>source</var> or <var>target</var> datum ensembles met the above criteria,
+ * then this method returns an empty value.
+ * A non-empty value means that it is okay, for low accuracy requirements, to ignore the datum shift.
+ *
+ * @param source the source <abbr>CRS</abbr> of a coordinate operation.
+ * @param target the target <abbr>CRS</abbr> of a coordinate operation.
+ * @return datum or pseudo-datum of the coordinate operation result if it is okay to ignore datum shift.
+ * @throws NullPointerException if any argument is null.
+ */
+ public static Optional<GeodeticDatum> asTargetDatum(final GeodeticCRS source, final GeodeticCRS target) {
+ return asTargetDatum(source, source.getDatum(),
+ target, target.getDatum(),
+ DefaultDatumEnsemble.Geodetic::datum);
+ }
+
+ /**
+ * Returns the datum or pseudo-datum of the result of an operation between the given vertical <abbr>CRS</abbr>s.
+ * See {@link #asTargetDatum(GeodeticCRS, GeodeticCRS)} for more information.
+ *
+ * @param source the source <abbr>CRS</abbr> of a coordinate operation.
+ * @param target the target <abbr>CRS</abbr> of a coordinate operation.
+ * @return datum or pseudo-datum of the coordinate operation result if it is okay to ignore datum shift.
+ * @throws NullPointerException if any argument is null.
+ */
+ public static Optional<VerticalDatum> asTargetDatum(final VerticalCRS source, final VerticalCRS target) {
+ return asTargetDatum(source, source.getDatum(),
+ target, target.getDatum(),
+ DefaultDatumEnsemble.Vertical::datum);
+ }
+
+ /**
+ * Returns the datum or pseudo-datum of the result of an operation between the given temporal <abbr>CRS</abbr>s.
+ * See {@link #asTargetDatum(GeodeticCRS, GeodeticCRS)} for more information.
+ *
+ * @param source the source <abbr>CRS</abbr> of a coordinate operation.
+ * @param target the target <abbr>CRS</abbr> of a coordinate operation.
+ * @return datum or pseudo-datum of the coordinate operation result if it is okay to ignore datum shift.
+ * @throws NullPointerException if any argument is null.
+ */
+ public static Optional<TemporalDatum> asTargetDatum(final TemporalCRS source, final TemporalCRS target) {
+ return asTargetDatum(source, source.getDatum(),
+ target, target.getDatum(),
+ DefaultDatumEnsemble.Time::datum);
+ }
+
- /**
- * Returns the datum or pseudo-datum of the result of an operation between the given parametric <abbr>CRS</abbr>s.
- * See {@link #asTargetDatum(GeodeticCRS, GeodeticCRS)} for more information.
- *
- * @param source the source <abbr>CRS</abbr> of a coordinate operation.
- * @param target the target <abbr>CRS</abbr> of a coordinate operation.
- * @return datum or pseudo-datum of the coordinate operation result if it is okay to ignore datum shift.
- * @throws NullPointerException if any argument is null.
- */
- public static Optional<ParametricDatum> asTargetDatum(final ParametricCRS source, final ParametricCRS target) {
- return asTargetDatum(source, source.getDatum(),
- target, target.getDatum(),
- DefaultDatumEnsemble.Parametric::datum);
- }
-
+ /**
+ * Returns the datum or pseudo-datum of the result of an operation between the given engineering <abbr>CRS</abbr>s.
+ * See {@link #asTargetDatum(GeodeticCRS, GeodeticCRS)} for more information.
+ *
+ * @param source the source <abbr>CRS</abbr> of a coordinate operation.
+ * @param target the target <abbr>CRS</abbr> of a coordinate operation.
+ * @return datum or pseudo-datum of the coordinate operation result if it is okay to ignore datum shift.
+ * @throws NullPointerException if any argument is null.
+ */
+ public static Optional<EngineeringDatum> asTargetDatum(final EngineeringCRS source, final EngineeringCRS target) {
+ return asTargetDatum(source, source.getDatum(),
+ target, target.getDatum(),
+ DefaultDatumEnsemble.Engineering::datum);
+ }
+
+ /**
+ * Returns the datum or pseudo-datum of a coordinate operation from <var>source</var> to <var>target</var>.
+ * If the two given coordinate reference systems are associated to the same datum, then this method returns
+ * the <var>target</var> datum. Otherwise, this method returns a pseudo-datum for the largest ensemble which
+ * fully contains the datum or datum ensemble of the other <abbr>CRS</abbr>. If none of the <var>source</var>
+ * or <var>target</var> datum ensembles met that criterion, then this method returns an empty value.
+ * A non-empty value means that it is okay, for low accuracy requirements, to ignore the datum shift.
+ *
+ * @param source the source <abbr>CRS</abbr> of a coordinate operation.
+ * @param sourceDatum the datum of the source <abbr>CRS</abbr>.
+ * @param target the target <abbr>CRS</abbr> of a coordinate operation.
+ * @param targetDatum the datum of the target <abbr>CRS</abbr>.
+ * @param constructor function to invoke for wrapping a datum ensemble in a pseudo-datum.
+ * @return datum or pseudo-datum of the coordinate operation result if it is okay to ignore datum shift.
+ */
+ @SuppressWarnings("unchecked") // Casts are safe because callers know the method signature of <D>.
+ private static <C extends SingleCRS, D extends Datum, R extends IdentifiedObject> Optional<R> asTargetDatum(
+ final C source, final R sourceDatum,
+ final C target, final R targetDatum,
- final Function<DatumEnsemble<D>, R> constructor)
++ final Function<DefaultDatumEnsemble<D>, R> constructor)
+ {
+ if (sourceDatum != null && Utilities.equalsIgnoreMetadata(sourceDatum, targetDatum)) {
+ return Optional.of(targetDatum);
+ }
- DatumEnsemble<D> sourceEnsemble;
- DatumEnsemble<D> targetEnsemble;
- DatumEnsemble<D> selected;
- if ((isMember(selected = targetEnsemble = (DatumEnsemble<D>) target.getDatumEnsemble(), sourceDatum)) ||
- (isMember(selected = sourceEnsemble = (DatumEnsemble<D>) source.getDatumEnsemble(), targetDatum)))
++ DefaultDatumEnsemble<D> sourceEnsemble;
++ DefaultDatumEnsemble<D> targetEnsemble;
++ DefaultDatumEnsemble<D> selected;
++ if ((isMember(selected = targetEnsemble = (DefaultDatumEnsemble<D>) getDatumEnsemble(target), sourceDatum)) ||
++ (isMember(selected = sourceEnsemble = (DefaultDatumEnsemble<D>) getDatumEnsemble(source), targetDatum)))
+ {
+ return Optional.of(constructor.apply(selected));
+ }
+ if (sourceEnsemble != null && targetEnsemble != null) {
+ selected = targetEnsemble;
+ Collection<D> large = targetEnsemble.getMembers();
+ Collection<D> small = sourceEnsemble.getMembers();
+ if (small.size() > large.size()) {
+ selected = sourceEnsemble;
+ var t = large;
+ large = small;
+ small = t;
+ }
+ small = new ArrayDeque<>(small);
+ for (final Datum member : large) {
+ final Iterator<D> it = small.iterator();
+ while (it.hasNext()) {
+ if (Utilities.equalsIgnoreMetadata(member, it.next())) {
+ it.remove();
+ if (small.isEmpty()) {
+ /*
+ * Found all members of the smaller ensemble. Take the larger ensemble,
+ * as it contains both ensembles and should have conservative accuracy.
+ */
+ return Optional.of(constructor.apply(selected));
+ }
+ break; // For removing only the first match.
+ }
+ }
+ }
+ }
+ return Optional.empty();
+ }
+
+ /**
+ * Returns whether the given datum is a member of the given ensemble.
+ *
+ * @param datum the datum to test, or {@code null}.
+ * @param ensemble the ensemble to test, or {@code null}.
+ * @return whether the ensemble contains the given datum.
+ */
- private static boolean isMember(final DatumEnsemble<?> ensemble, final IdentifiedObject datum) {
++ private static boolean isMember(final DefaultDatumEnsemble<?> ensemble, final IdentifiedObject datum) {
+ if (ensemble != null) {
+ for (final Datum member : ensemble.getMembers()) {
+ if (Utilities.equalsIgnoreMetadata(datum, member)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns the ellipsoid used by the given coordinate reference system.
+ * More specifically:
+ *
+ * <ul>
+ * <li>If the given <abbr>CRS</abbr> is an instance of {@link SingleCRS} and its datum
+ * is a {@link GeodeticDatum}, then this method returns the datum ellipsoid.</li>
- * <li>Otherwise, if the given <abbr>CRS</abbr> is associated to a {@link DatumEnsemble} and all members
++ * <li>Otherwise, if the given <abbr>CRS</abbr> is associated to a {@code DatumEnsemble} and all members
+ * of the ensemble have equal (ignoring metadata) ellipsoid, then returns that ellipsoid.</li>
+ * <li>Otherwise, if the given <abbr>CRS</abbr> is an instance of {@link CompoundCRS}, then this method
+ * searches recursively in each component until a geodetic reference frame is found.</li>
+ * <li>Otherwise, this method returns an empty value.</li>
+ * </ul>
+ *
+ * Note that this method does not check if a compound <abbr>CRS</abbr> contains more than one ellipsoid
+ * (it should never be the case). Note also that this method may return an empty value even
+ * if the <abbr>CRS</abbr> is geodetic.
+ *
+ * @param crs the coordinate reference system for which to get the ellipsoid.
+ * @return the ellipsoid, or an empty value if none or inconsistent.
+ */
+ public static Optional<Ellipsoid> getEllipsoid(final CoordinateReferenceSystem crs) {
+ return getGeodeticProperty(crs, GeodeticDatum::getEllipsoid);
+ }
+
+ /**
+ * Returns the prime meridian used by the given coordinate reference system.
+ * This method applies the same rules as {@link #getEllipsoid(CoordinateReferenceSystem)}.
+ *
+ * @param crs the coordinate reference system for which to get the prime meridian.
+ * @return the prime meridian, or an empty value if none or inconsistent.
+ *
+ * @see org.apache.sis.referencing.CRS#getGreenwichLongitude(GeodeticCRS)
+ */
+ public static Optional<PrimeMeridian> getPrimeMeridian(final CoordinateReferenceSystem crs) {
+ return getGeodeticProperty(crs, GeodeticDatum::getPrimeMeridian);
+ }
+
+ /**
+ * Implementation of {@code getEllipsoid(CRS)} and {@code getPrimeMeridian(CRS)}.
+ *
+ * @param <P> the type of object to get.
+ * @param crs the coordinate reference system for which to get the ellipsoid or prime meridian.
+ * @param getter the method to invoke on {@link GeodeticDatum} instances.
+ * @return the ellipsoid or prime meridian, or an empty value if none of inconsistent.
+ */
+ private static <P> Optional<P> getGeodeticProperty(final CoordinateReferenceSystem crs, final Function<GeodeticDatum, P> getter) {
+ single: if (crs instanceof SingleCRS) {
+ final var scrs = (SingleCRS) crs;
+ final Datum datum = scrs.getDatum();
+ if (datum instanceof GeodeticDatum) {
+ P property = getter.apply((GeodeticDatum) datum);
+ if (property != null) {
+ return Optional.of(property);
+ }
+ }
- final DatumEnsemble<?> ensemble = scrs.getDatumEnsemble();
++ final DefaultDatumEnsemble<?> ensemble = getDatumEnsemble(crs);
+ if (ensemble != null) {
+ P common = null;
+ for (Datum member : ensemble.getMembers()) {
+ if (member instanceof GeodeticDatum) {
+ final P property = getter.apply((GeodeticDatum) member);
+ if (property != null) {
+ if (common == null) {
+ common = property;
+ } else if (!Utilities.equalsIgnoreMetadata(property, common)) {
+ break single;
+ }
+ }
+ }
+ }
+ return Optional.ofNullable(common);
+ }
+ }
+ if (crs instanceof CompoundCRS) {
+ for (final CoordinateReferenceSystem c : ((CompoundCRS) crs).getComponents()) {
+ final Optional<P> property = getGeodeticProperty(c, getter);
+ if (property.isPresent()) {
+ return property;
+ }
+ }
+ }
+ return Optional.empty();
+ }
+
+ /**
+ * If the given object is a datum ensemble, returns its accuracy.
+ *
+ * @param object the object from which to get the ensemble accuracy, or {@code null}.
+ * @return the datum ensemble accuracy if the given object is a datum ensemble.
+ * @throws NullPointerException if the given object should provide an accuracy but didn't.
+ */
+ public static Optional<PositionalAccuracy> getAccuracy(final IdentifiedObject object) {
- final DatumEnsemble<?> ensemble;
- if (object instanceof DatumEnsemble<?>) {
- ensemble = (DatumEnsemble<?>) object;
++ final DefaultDatumEnsemble<?> ensemble;
++ if (object instanceof DefaultDatumEnsemble<?>) {
++ ensemble = (DefaultDatumEnsemble<?>) object;
+ } else {
+ return Optional.empty();
+ }
+ return Optional.of(ensemble.getEnsembleAccuracy()); // Intentional NullPointerException if this property is null.
+ }
+ }
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/DefaultDatumEnsemble.java
index 10c416cf6e,182baae5e0..8e5a6c77ff
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/DefaultDatumEnsemble.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/datum/DefaultDatumEnsemble.java
@@@ -19,9 -19,25 +19,23 @@@ package org.apache.sis.referencing.datu
import java.util.Map;
import java.util.List;
import java.util.Collection;
+ import java.util.Iterator;
+ import java.util.Objects;
-import java.util.Optional;
+ import java.util.function.Function;
-import java.time.temporal.Temporal;
import org.opengis.referencing.IdentifiedObject;
+ import org.opengis.referencing.crs.EngineeringCRS;
+ import org.opengis.referencing.crs.GeodeticCRS;
+ import org.opengis.referencing.crs.TemporalCRS;
+ import org.opengis.referencing.crs.VerticalCRS;
import org.opengis.referencing.datum.Datum;
+ import org.opengis.referencing.datum.Ellipsoid;
+ import org.opengis.referencing.datum.EngineeringDatum;
+ import org.opengis.referencing.datum.GeodeticDatum;
+ import org.opengis.referencing.datum.PrimeMeridian;
+ import org.opengis.referencing.datum.TemporalDatum;
+ import org.opengis.referencing.datum.VerticalDatum;
import org.opengis.metadata.quality.PositionalAccuracy;
+ import org.opengis.util.InternationalString;
import org.apache.sis.io.wkt.Formatter;
import org.apache.sis.io.wkt.Convention;
import org.apache.sis.referencing.AbstractIdentifiedObject;
@@@ -32,10 -51,34 +49,29 @@@ import org.apache.sis.util.ComparisonMo
import org.apache.sis.util.Utilities;
import org.apache.sis.util.resources.Errors;
+ // Specific to the main and geoapi-3.1 branches:
+ import java.util.Date;
++import org.opengis.metadata.extent.Extent;
+ import org.opengis.referencing.datum.VerticalDatumType;
+
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.referencing.crs.ParametricCRS;
-import org.opengis.referencing.datum.DatumEnsemble;
-import org.opengis.referencing.datum.ParametricDatum;
-import org.opengis.referencing.datum.RealizationMethod;
-
/**
* Collection of datums which for low accuracy requirements may be considered
* to be insignificantly different from each other.
+ * Coordinate transformations between different {@linkplain #getMembers() members} of an ensemble
+ * can be omitted if the {@linkplain #getEnsembleAccuracy() ensemble accuracy} is sufficient.
+ *
+ * <h2>Ensemble viewed as a datum</h2>
+ * While a {@code DatumEnsemble} is theoretically <em>not</em> a {@code Datum},
+ * it is sometime convenient to handle the ensemble <em>as if</em> it was a datum.
- * Therefore, Apache <abbr>SIS</abbr> implementation of {@link DatumEnsemble} implements also the {@link Datum} interface.
++ * Therefore, Apache <abbr>SIS</abbr> implementation of {@code DatumEnsemble} implements also the {@link Datum} interface.
+ * This is a non-standard approach for making easier to handle {@code Datum} and {@code DatumEnsemble} with the same code.
+ * A similar approach is used in the <abbr>EPSG</abbr> database, which stores ensembles in the same table as the datums.
+ *
+ * <p>It is illegal to use this double inheritance for returning a {@code DatumEnsemble} from
+ * {@link org.opengis.referencing.crs.SingleCRS#getDatum()}, or for creating a {@code DatumEnsemble}
+ * containing a nested {@code DatumEnsemble}. The Apache <abbr>SIS</abbr> constructors verify these constraints.
+ * For getting a single object which may be a datum or an ensemble, see the {@link DatumOrEnsemble} static methods.</p>
*
* @author Martin Desruisseaux (Geomatys)
* @version 1.5
@@@ -44,7 -87,8 +80,8 @@@
*
* @since 1.5
*/
- public class DefaultDatumEnsemble<D extends Datum> extends AbstractIdentifiedObject {
+ @SecondaryTrait(Datum.class)
-public class DefaultDatumEnsemble<D extends Datum> extends AbstractIdentifiedObject implements DatumEnsemble<D>, Datum {
++public class DefaultDatumEnsemble<D extends Datum> extends AbstractIdentifiedObject implements Datum {
/**
* Serial number for inter-operability with different versions.
*/
@@@ -100,30 -148,68 +141,67 @@@
* @param properties the properties to be given to the identified object.
* @param members datum or reference frames which are members of this ensemble.
* @param accuracy inaccuracy introduced through use of this ensemble (mandatory).
- * @throws IllegalArgumentException if at least two different
- * {@linkplain AbstractDatum#getConventionalRS() conventional reference systems} are found.
+ * @param type the base type of datum members contained in this ensemble.
+ * @throws ClassCastException if a member is not an instance of {@code type}.
- * @throws IllegalArgumentException if a member is an instance of {@link DatumEnsemble}, of if at least two
++ * @throws IllegalArgumentException if a member is an instance of {@code DatumEnsemble}, of if at least two
+ * different {@linkplain AbstractDatum#getConventionalRS() conventional reference systems} are found.
+ *
+ * @see #create(Map, Collection, PositionalAccuracy)
*/
- public DefaultDatumEnsemble(Map<String,?> properties, Collection<? extends D> members, PositionalAccuracy accuracy) {
+ protected DefaultDatumEnsemble(final Map<String,?> properties,
+ final Collection<? extends D> members,
+ final PositionalAccuracy accuracy,
+ final Class<? super D> type)
+ {
super(properties);
ArgumentChecks.ensureNonNull("accuracy", accuracy);
ensembleAccuracy = accuracy;
this.members = List.copyOf(members);
- validate();
+ validate(type);
+ }
+
+ /**
+ * Creates a new ensemble with the same values as the specified one.
+ * This copy constructor provides a way to convert an arbitrary implementation into a SIS one
+ * or a user-defined one (as a subclass), usually in order to leverage some implementation-specific API.
+ *
+ * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p>
+ *
+ * @param ensemble the ensemble to copy.
+ * @param type the base type of datum members contained in this ensemble.
+ * @throws ClassCastException if a member is not an instance of {@code type}.
- * @throws IllegalArgumentException if a member is an instance of {@link DatumEnsemble}, of if at least two
++ * @throws IllegalArgumentException if a member is an instance of {@code DatumEnsemble}, of if at least two
+ * different {@linkplain AbstractDatum#getConventionalRS() conventional reference systems} are found.
- *
- * @see #castOrCopy(DatumEnsemble)
+ */
- protected DefaultDatumEnsemble(final DatumEnsemble<? extends D> ensemble, final Class<? super D> type) {
++ protected DefaultDatumEnsemble(final DefaultDatumEnsemble<? extends D> ensemble, final Class<? super D> type) {
+ super(ensemble);
+ members = List.copyOf(ensemble.getMembers());
+ ensembleAccuracy = Objects.requireNonNull(ensemble.getEnsembleAccuracy());
+ validate(type);
}
/**
- * Verifies this ensemble. All members shall have the same conventional reference system.
- * No member can be an instance of {@link PseudoDatum}.
+ * Verifies this ensemble. All members shall be instances of the specified type and shall have
- * the same conventional reference system. No member can be an instance of {@link DatumEnsemble}.
++ * the same conventional reference system. No member can be an instance of {@code DatumEnsemble}.
+ *
+ * @param type the base type of datum members contained in this ensemble.
+ * @throws ClassCastException if a member is not an instance of {@code type}.
- * @throws IllegalArgumentException if a member is an instance of {@link DatumEnsemble}, of if at least two
++ * @throws IllegalArgumentException if a member is an instance of {@code DatumEnsemble}, of if at least two
+ * different {@linkplain AbstractDatum#getConventionalRS() conventional reference systems} are found.
*/
- private void validate() {
+ private void validate(final Class<? super D> type) {
IdentifiedObject rs = null;
for (final D datum : members) {
- if (datum instanceof PseudoDatum<?>) {
- if (datum instanceof DatumEnsemble<?>) {
++ if (datum instanceof DefaultDatumEnsemble<?>) {
throw new IllegalArgumentException(
- Errors.format(Errors.Keys.IllegalPropertyValueClass_2, "members", PseudoDatum.class));
- Errors.format(Errors.Keys.IllegalPropertyValueClass_2, "members", DatumEnsemble.class));
++ Errors.format(Errors.Keys.IllegalPropertyValueClass_2, "members", DefaultDatumEnsemble.class));
+ }
+ if (!type.isInstance(datum)) {
+ throw new ClassCastException(
+ Errors.format(Errors.Keys.IllegalClass_2, type, datum.getClass()));
}
- final IdentifiedObject dr = datum.getConventionalRS().orElse(null);
+ if (!(datum instanceof AbstractDatum)) continue;
+ final IdentifiedObject dr = ((AbstractDatum) datum).getConventionalRS().orElse(null);
if (dr != null) {
if (rs == null) {
rs = dr;
@@@ -134,6 -220,85 +212,39 @@@
}
}
+ /**
+ * Creates a datum ensemble from the given properties. The content of the {@code properties} map is described
+ * {@linkplain #DefaultDatumEnsemble(Map, Collection, PositionalAccuracy, Class) in the constructor}.
+ * The returned ensemble may implement the {@link GeodeticDatum}, {@link VerticalDatum}, {@link TemporalDatum},
+ * {@link ParametricDatum} or {@link EngineeringDatum} interface if all members are instances of the same interface.
+ *
+ * @param <D> the type of datum members contained in this ensemble.
+ * @param properties the properties to be given to the identified object.
+ * @param members datum or reference frames which are members of this ensemble.
+ * @param accuracy inaccuracy introduced through use of this ensemble (mandatory).
+ * @return the datum ensemble.
- * @throws IllegalArgumentException if a member is an instance of {@link DatumEnsemble}, of if at least two
++ * @throws IllegalArgumentException if a member is an instance of {@code DatumEnsemble}, of if at least two
+ * different {@linkplain AbstractDatum#getConventionalRS() conventional reference systems} are found.
+ */
+ public static <D extends Datum> DefaultDatumEnsemble<D> create(
+ final Map<String,?> properties,
+ final Collection<? extends D> members,
+ final PositionalAccuracy accuracy)
+ {
+ return Factory.forMemberType(null, properties, List.copyOf(members), accuracy);
+ }
+
- /**
- * Returns a SIS ensemble implementation with the values of the given arbitrary implementation.
- * This method performs the first applicable action in the following choices:
- *
- * <ul>
- * <li>If the given object is {@code null}, then this method returns {@code null}.</li>
- * <li>Otherwise, if the given object is already an instance of
- * {@code DefaultDatumEnsemble}, then it is returned unchanged.</li>
- * <li>Otherwise, a new {@code DefaultDatumEnsemble} instance is created using the
- * {@linkplain #DefaultDatumEnsemble(DatumEnsemble, Class) copy constructor} and returned.
- * Note that this is a <em>shallow</em> copy operation,
- * because the other properties contained in the given object are not recursively copied.</li>
- * </ul>
- *
- * The returned ensemble may implement the {@link GeodeticDatum}, {@link VerticalDatum}, {@link TemporalDatum},
- * {@link ParametricDatum} or {@link EngineeringDatum} interface if all members are instances of the same interface.
- *
- * @param <D> the type of datum members contained in the ensemble.
- * @param object the object to get as a SIS implementation, or {@code null} if none.
- * @return a SIS implementation containing the values of the given object (may be the
- * given object itself), or {@code null} if the argument was null.
- */
- public static <D extends Datum> DefaultDatumEnsemble<D> castOrCopy(final DatumEnsemble<D> object) {
- if (object == null || object instanceof DefaultDatumEnsemble<?>) {
- return (DefaultDatumEnsemble<D>) object;
- }
- return Factory.forMemberType(object, null, List.copyOf(object.getMembers()), null);
- }
-
- /**
- * Returns the GeoAPI interface implemented by this class.
- * The SIS implementation returns {@code DatumEnsemble.class}.
- *
- * <h4>Note for implementers</h4>
- * Subclasses usually do not need to override this method since GeoAPI does not define {@code DatumEnsemble}
- * sub-interface. Overriding possibility is left mostly for implementers who wish to extend GeoAPI with their
- * own set of interfaces.
- *
- * @return the datum interface implemented by this class.
- */
- @Override
- @SuppressWarnings("unchecked")
- public Class<? extends DatumEnsemble<D>> getInterface() {
- return (Class) DatumEnsemble.class;
- }
-
+ /*
+ * NOTE: a previous version provided the following method:
+ *
+ * public Class<? super D> getMemberInterface() {
+ * return Datum.class;
+ * }
+ *
+ * It has been removed because, to be safe, it would require a `Class<D>` argument in the static methods.
+ * Even `? super D` is unsafe. See the comment in `Factory.forMemberType(…)` method for more discussion.
+ */
+
/**
* Returns the datum or reference frames which are members of this ensemble.
*
@@@ -153,11 -320,166 +264,103 @@@
return ensembleAccuracy;
}
- /**
- * Returns an anchor definition which is common to all members of the datum ensemble.
- * If the value is not the same for all members, or if at least one member returned
- * an empty value, then this method returns an empty value.
- *
- * @return the common anchor definition, or empty if there is no common value.
- */
- @Override
- public Optional<InternationalString> getAnchorDefinition() {
- return getCommonOptionalValue(Datum::getAnchorDefinition);
- }
-
+ /**
+ * Returns an anchor point which is common to all members of the datum ensemble.
+ * If the value is not the same for all members, or if at least one member returned
+ * null, then this method returns null.
+ *
+ * @return the common anchor point, or null if there is no common value.
- *
- * @deprecated Renamed {@link #getAnchorDefinition()} for conformance with ISO 19111:2019 revision.
+ */
+ @Override
- @Deprecated
+ public InternationalString getAnchorPoint() {
+ return getCommonValue(Datum::getAnchorPoint);
+ }
+
- /**
- * Returns an anchor epoch which is common to all members of the datum ensemble.
- * If the value is not the same for all members, or if at least one member returned
- * an empty value, then this method returns an empty value.
- *
- * @return the common anchor epoch, or empty if there is no common value.
- */
- @Override
- public Optional<Temporal> getAnchorEpoch() {
- return getCommonOptionalValue(Datum::getAnchorEpoch);
- }
-
+ /**
+ * Returns a realization epoch which is common to all members of the datum ensemble.
+ * If the value is not the same for all members, or if at least one member returned
+ * null, then this method returns null.
+ *
+ * @return the common realization epoch, null if there is no common value.
- *
- * @deprecated Renamed {@link #getAnchorEpoch()} for conformance with ISO 19111:2019 revision.
+ */
+ @Override
- @Deprecated
+ public Date getRealizationEpoch() {
+ return getCommonValue(Datum::getRealizationEpoch);
+ }
+
+ /**
- * Returns a publication date which is common to all members of the datum ensemble.
++ * Returns a domain of validity which is common to all members of the datum ensemble.
+ * If the value is not the same for all members, or if at least one member returned
- * an empty value, then this method returns an empty value.
++ * null, then this method returns null.
+ *
- * @return the common publication date, or empty if there is no common value.
++ * @return the common domain of validity, or null if there is no common value.
+ */
+ @Override
- public Optional<Temporal> getPublicationDate() {
- return getCommonOptionalValue(Datum::getPublicationDate);
++ public Extent getDomainOfValidity() {
++ return getCommonValue(Datum::getDomainOfValidity);
+ }
+
+ /**
- * Returns a conventional reference system which is common to all members of the datum ensemble.
- * The returned value should never be empty, because it is illegal for a datum ensemble to have
- * members with different conventional reference system. If this case nevertheless happens,
- * then this method returns an empty value.
++ * Returns a scope which is common to all members of the datum ensemble.
++ * If the value is not the same for all members, or if at least one member returned
++ * null, then this method returns null.
+ *
- * @return the common conventional reference system, or empty if there is no common value.
++ * @return the common scope, or null if there is no common value.
+ */
+ @Override
- public Optional<IdentifiedObject> getConventionalRS() {
- return getCommonOptionalValue(Datum::getConventionalRS);
++ public InternationalString getScope() {
++ return getCommonValue(Datum::getScope);
+ }
+
- /*
- * Do not override `getScope()` and other methods from `IdentifiedObject`.
- * Inherit the properties specified to `AbstractIdentifiedObject` instead.
- */
-
+ /**
+ * Returns a value which is common to all ensemble members.
+ * If all members do not have the same value, returns null.
+ *
+ * @param <V> type of value.
+ * @param getter method to invoke on each member for getting the value.
+ * @return a value common to all members, or null if there is no common value.
- *
- * @deprecated For implementation of deprecated methods only.
+ */
- @Deprecated
+ final <V> V getCommonValue(final Function<D,V> getter) {
+ final Iterator<D> it = members.iterator();
+ check: if (it.hasNext()) {
+ final V value = getter.apply(it.next());
+ if (value != null) {
+ while (it.hasNext()) {
+ if (!value.equals(getter.apply(it.next()))) {
+ break check;
+ }
+ }
+ return value;
+ }
+ }
+ return null;
+ }
+
- /**
- * Returns an optional value which is common to all ensemble members.
- * If all members do not have the same value, returns an empty value.
- *
- * @param <V> type of value.
- * @param getter method to invoke on each member for getting the value.
- * @return a value common to all members, or empty if there is no common value.
- */
- final <V> Optional<V> getCommonOptionalValue(final Function<D, Optional<V>> getter) {
- final Iterator<D> it = members.iterator();
-check: if (it.hasNext()) {
- final Optional<V> value = getter.apply(it.next());
- if (value.isPresent()) {
- while (it.hasNext()) {
- if (!value.equals(getter.apply(it.next()))) {
- break check;
- }
- }
- return value;
- }
- }
- return Optional.empty();
- }
-
+ /**
+ * Returns a mandatory value which is common to all ensemble members.
+ *
+ * @param <V> type of value.
+ * @param getter method to invoke on each member for getting the value.
+ * @return a value common to all members.
+ * @throws NoSuchElementException if the ensemble does not contain at least one member.
+ * @throws GeodeticException if the value is not the same for all members of the datum ensemble.
+ */
+ final <V> V getCommonMandatoryValue(final Function<D, V> getter) {
+ final Iterator<D> it = members.iterator();
+ final V value = getter.apply(it.next()); // Mandatory.
+ if (it.hasNext()) {
+ final V other = getter.apply(it.next());
+ if (!Objects.equals(value, other)) {
+ throw new GeodeticException(Errors.format(Errors.Keys.NonUniformValue_2,
+ (value instanceof IdentifiedObject) ? IdentifiedObjects.getDisplayName((IdentifiedObject) value) : value,
+ (other instanceof IdentifiedObject) ? IdentifiedObjects.getDisplayName((IdentifiedObject) other) : other));
+ }
+ }
+ return value;
+ }
+
/**
* Compares the specified object with this ensemble for equality.
- * If the {@code mode} argument value is {@link ComparisonMode#STRICT STRICT} or
- * {@link ComparisonMode#BY_CONTRACT BY_CONTRACT}, then all available properties are compared including the
- * {@linkplain #getDomains() domains}.
*
* @param object the object to compare to {@code this}.
* @param mode {@link ComparisonMode#STRICT STRICT} for performing a strict comparison, or
@@@ -221,4 -539,412 +423,347 @@@
}
return WKTKeywords.Ensemble;
}
+
+ /**
+ * An ensemble viewed as a low-accuracy geodetic datum.
+ *
+ * @see #create(Map, Collection, PositionalAccuracy)
- * @see #castOrCopy(DatumEnsemble)
+ * @see DatumOrEnsemble#of(GeodeticCRS)
+ * @see DatumOrEnsemble#asTargetDatum(GeodeticCRS, GeodeticCRS)
+ */
+ static final class Geodetic extends DefaultDatumEnsemble<GeodeticDatum> implements GeodeticDatum {
+ /** For cross-versions compatibility. */
+ private static final long serialVersionUID = 7669230365507661290L;
+
+ /** Returns the given ensemble as a pseudo-datum. */
- static GeodeticDatum datum(DatumEnsemble<GeodeticDatum> ensemble) {
++ static GeodeticDatum datum(DefaultDatumEnsemble<GeodeticDatum> ensemble) {
+ return (ensemble == null || ensemble instanceof GeodeticDatum)
+ ? (GeodeticDatum) ensemble : new Geodetic(ensemble);
+ }
+
+ /** Creates a new ensemble as a copy of the given ensemble. */
- Geodetic(DatumEnsemble<? extends GeodeticDatum> ensemble) {
++ Geodetic(DefaultDatumEnsemble<? extends GeodeticDatum> ensemble) {
+ super(ensemble, GeodeticDatum.class);
+ }
+
+ /** Creates a new ensemble from the given properties. */
+ Geodetic(Map<String,?> properties, List<? extends GeodeticDatum> members, PositionalAccuracy accuracy) {
+ super(properties, members, accuracy, GeodeticDatum.class);
+ }
+
+ /**
+ * Returns the ellipsoid which is indirectly (through a datum) associated to this datum ensemble.
+ * If all members of the ensemble use the same ellipsoid, then this method returns that ellipsoid.
+ *
+ * @return the ellipsoid indirectly associated to this datum ensemble.
+ * @throws NoSuchElementException if the ensemble does not contain at least one member.
+ * @throws GeodeticException if the ellipsoid is not the same for all members of the datum ensemble.
+ */
+ @Override
+ public Ellipsoid getEllipsoid() {
+ return getCommonMandatoryValue(GeodeticDatum::getEllipsoid);
+ }
+
+ /**
+ * Returns the prime meridian which is indirectly (through a datum) associated to this datum ensemble.
+ * If all members of the ensemble use the same prime meridian, then this method returns that meridian.
+ *
+ * @return the prime meridian indirectly associated to this datum ensemble.
+ * @throws NoSuchElementException if the ensemble does not contain at least one member.
+ * @throws GeodeticException if the prime meridian is not the same for all members of the datum ensemble.
+ */
+ @Override
+ public PrimeMeridian getPrimeMeridian() {
+ return getCommonMandatoryValue(GeodeticDatum::getPrimeMeridian);
+ }
+ }
+
+ /**
+ * An ensemble viewed as a low-accuracy vertical datum.
+ *
+ * @see #create(Map, Collection, PositionalAccuracy)
- * @see #castOrCopy(DatumEnsemble)
+ * @see DatumOrEnsemble#of(VerticalCRS)
+ * @see DatumOrEnsemble#asTargetDatum(VerticalCRS, VerticalCRS)
+ */
+ static final class Vertical extends DefaultDatumEnsemble<VerticalDatum> implements VerticalDatum {
+ /** For cross-versions compatibility. */
+ private static final long serialVersionUID = 7242417944400289818L;
+
+ /** Returns the given ensemble as a pseudo-datum. */
- static VerticalDatum datum(DatumEnsemble<VerticalDatum> ensemble) {
++ static VerticalDatum datum(DefaultDatumEnsemble<VerticalDatum> ensemble) {
+ return (ensemble == null || ensemble instanceof VerticalDatum)
+ ? (VerticalDatum) ensemble : new Vertical(ensemble);
+ }
+
+ /** Creates a new ensemble as a copy of the given ensemble. */
- Vertical(DatumEnsemble<? extends VerticalDatum> ensemble) {
++ Vertical(DefaultDatumEnsemble<? extends VerticalDatum> ensemble) {
+ super(ensemble, VerticalDatum.class);
+ }
+
+ /** Creates a new ensemble from the given properties. */
+ Vertical(Map<String,?> properties, List<? extends VerticalDatum> members, PositionalAccuracy accuracy) {
+ super(properties, members, accuracy, VerticalDatum.class);
+ }
+
- /**
- * Returns a realization method which is common to all members of the datum ensemble.
- * If the value is not the same for all members, or if at least one member has an empty value,
- * then this method returns an empty value.
- *
- * @return the common realization method, or empty if there is no common value.
- */
- @Override
- public Optional<RealizationMethod> getRealizationMethod() {
- return getCommonOptionalValue(VerticalDatum::getRealizationMethod);
- }
-
+ /**
+ * Returns a vertical datum type which is common to all members of the datum ensemble.
+ * If the value is not the same for all members, or if at least one member has a null value,
+ * then this method returns null.
+ *
+ * @return the common realization method, or null if there is no common value.
- *
- * @deprecated Replaced by {@link #getRealizationMethod()}.
+ */
+ @Override
- @Deprecated
+ public VerticalDatumType getVerticalDatumType() {
+ return getCommonValue(VerticalDatum::getVerticalDatumType);
+ }
+ }
+
+ /**
+ * An ensemble viewed as a low-accuracy temporal datum.
+ *
+ * @see #create(Map, Collection, PositionalAccuracy)
- * @see #castOrCopy(DatumEnsemble)
+ * @see DatumOrEnsemble#of(TemporalCRS)
+ * @see DatumOrEnsemble#asTargetDatum(TemporalCRS, TemporalCRS)
+ */
+ static final class Time extends DefaultDatumEnsemble<TemporalDatum> implements TemporalDatum {
+ /** For cross-versions compatibility. */
+ private static final long serialVersionUID = -4208563828181087035L;
+
+ /** Returns the given ensemble as a pseudo-datum. */
- static TemporalDatum datum(DatumEnsemble<TemporalDatum> ensemble) {
++ static TemporalDatum datum(DefaultDatumEnsemble<TemporalDatum> ensemble) {
+ return (ensemble == null || ensemble instanceof TemporalDatum)
+ ? (TemporalDatum) ensemble : new Time(ensemble);
+ }
+
+ /** Creates a new ensemble as a copy of the given ensemble. */
- Time(DatumEnsemble<? extends TemporalDatum> ensemble) {
++ Time(DefaultDatumEnsemble<? extends TemporalDatum> ensemble) {
+ super(ensemble, TemporalDatum.class);
+ }
+
+ /** Creates a new ensemble from the given properties. */
+ Time(Map<String,?> properties, List<? extends TemporalDatum> members, PositionalAccuracy accuracy) {
+ super(properties, members, accuracy, TemporalDatum.class);
+ }
+
+ /**
+ * Returns the temporal origin which is indirectly (through a datum) associated to this datum ensemble.
+ * If all members of the ensemble use the same temporal origin, then this method returns that origin.
+ *
+ * @return the temporal origin indirectly associated to this datum ensemble.
+ * @throws NoSuchElementException if the ensemble does not contain at least one member.
+ * @throws GeodeticException if the temporal origin is not the same for all members of the datum ensemble.
+ */
+ @Override
+ public Date getOrigin() {
+ return getCommonMandatoryValue(TemporalDatum::getOrigin);
+ }
+ }
+
- /**
- * An ensemble viewed as a low-accuracy parametric datum.
- *
- * @see #create(Map, Collection, PositionalAccuracy)
- * @see #castOrCopy(DatumEnsemble)
- * @see DatumOrEnsemble#of(ParametricCRS)
- * @see DatumOrEnsemble#asTargetDatum(ParametricCRS, ParametricCRS)
- */
- static final class Parametric extends DefaultDatumEnsemble<ParametricDatum> implements ParametricDatum {
- /** For cross-versions compatibility. */
- private static final long serialVersionUID = -8277774591738789437L;
-
- /** Returns the given ensemble as a pseudo-datum. */
- static ParametricDatum datum(DatumEnsemble<ParametricDatum> ensemble) {
- return (ensemble == null || ensemble instanceof ParametricDatum)
- ? (ParametricDatum) ensemble : new Parametric(ensemble);
- }
-
- /** Creates a new ensemble as a copy of the given ensemble. */
- Parametric(DatumEnsemble<? extends ParametricDatum> ensemble) {
- super(ensemble, ParametricDatum.class);
- }
-
- /** Creates a new ensemble from the given properties. */
- Parametric(Map<String,?> properties, List<? extends ParametricDatum> members, PositionalAccuracy accuracy) {
- super(properties, members, accuracy, ParametricDatum.class);
- }
- }
-
+ /**
+ * An ensemble viewed as a low-accuracy engineering datum.
+ *
+ * @see #create(Map, Collection, PositionalAccuracy)
- * @see #castOrCopy(DatumEnsemble)
+ * @see DatumOrEnsemble#of(EngineeringCRS)
+ * @see DatumOrEnsemble#asTargetDatum(EngineeringCRS, EngineeringCRS)
+ */
+ static final class Engineering extends DefaultDatumEnsemble<EngineeringDatum> implements EngineeringDatum {
+ /** For cross-versions compatibility. */
+ private static final long serialVersionUID = -8978468990963666861L;
+
+ /** Returns the given ensemble as a pseudo-datum. */
- static EngineeringDatum datum(DatumEnsemble<EngineeringDatum> ensemble) {
++ static EngineeringDatum datum(DefaultDatumEnsemble<EngineeringDatum> ensemble) {
+ return (ensemble == null || ensemble instanceof EngineeringDatum)
+ ? (EngineeringDatum) ensemble : new Engineering(ensemble);
+ }
+
+ /** Creates a new ensemble as a copy of the given ensemble. */
- Engineering(DatumEnsemble<? extends EngineeringDatum> ensemble) {
++ Engineering(DefaultDatumEnsemble<? extends EngineeringDatum> ensemble) {
+ super(ensemble, EngineeringDatum.class);
+ }
+
+ /** Creates a new ensemble from the given properties. */
+ Engineering(Map<String,?> properties, List<? extends EngineeringDatum> members, PositionalAccuracy accuracy) {
+ super(properties, members, accuracy, EngineeringDatum.class);
+ }
+ }
+
+ /**
+ * Factory methods for finding the base type of all members of a list and instantiate
+ * the {@link DefaultDatumEnsemble} subclass corresponding to the type of all members.
+ * Each instance of {@code Factory} is immutable and thread-safe.
+ * There is one instance for each supported type.
+ *
+ * @param <D> base type of all members in the ensembles constructed by this factory instance.
+ *
+ * @see #create(Map, Collection, PositionalAccuracy)
- * @see #castOrCopy(DatumEnsemble)
+ */
+ private static abstract class Factory<D extends Datum> {
+ /**
+ * Base type of all members in the ensembles constructed by this factory instance.
+ */
+ private final Class<D> type;
+
+ /**
+ * Creates a new factory for ensembles in which all members are instances of the given type.
+ *
+ * @param type base type of all members in the ensembles constructed by this factory instance.
+ */
+ private Factory(final Class<D> type) {
+ this.type = type;
+ }
+
+ /**
+ * Finds a common type for all members in the given list, then creates a datum ensemble of that type.
+ * In principle, the {@code <D>} type should be restricted to one of the types hard-coded in this class.
+ * However, it is okay if {@code <D>} is a custom subclass because it appears only in the following places:
+ *
+ * <ul>
+ * <li>{@link #getMembers()}, which is a read-only collection (it is safe to cast {@code List<? extends D>}
+ * as {@code List<D>} when no write operation is allowed).</li>
+ * </ul>
+ *
+ * Exactly one of {@code object} and {@code properties} should be non-null.
+ *
+ * @param <D> base type of all members in the ensembles to create.
+ * @param object the source ensemble to copy, or {@code null} if none.
+ * @param properties the properties of the ensemble to create, or {@code null}.
+ * @param members members of the ensemble to copy or create.
+ * @param accuracy inaccuracy of the ensemble. Mandatory if {@code properties} is non-null.
+ * @return the copied or created ensemble.
+ * @throws ClassCastException if at least one member is not a {@link Datum}.
+ * Should never happen if the parameterized type of {@code members} is respected.
+ */
+ static <D extends Datum> DefaultDatumEnsemble<D> forMemberType(
- final DatumEnsemble<? extends D> object,
++ final DefaultDatumEnsemble<? extends D> object,
+ final Map<String,?> properties,
+ final List<? extends D> members,
+ final PositionalAccuracy accuracy)
+ {
+ nextType: for (final Factory<?> factory : FACTORIES) {
+ for (final Object member : members) {
+ if (!factory.type.isInstance(member)) {
+ continue nextType;
+ }
+ }
+ /*
+ * A more correct type would be `Factory<? super D>` because of the use of `isInstance(member)`
+ * instead of strict class equality. However, even `? super D` is not guaranteed to be correct,
+ * because nothing prevent a member from implementing two interfaces. In such case, the type of
+ * the first matching factory could be unrelated to `D` (e.g., `D` is `ParametricDatum` but all
+ * members also implement `VerticalDatum`). However, despite this uncertainty, the cast is okay
+ * because `D` appears only in `getMembers()` which returns a read-only collection. There is no
+ * method returning `Class<D>` and no guarantees that the returned object will implement `D`.
+ */
+ @SuppressWarnings("unchecked")
+ final var selected = (Factory<D>) factory; // See above comment.
+ if (object != null) {
+ return selected.copy(object);
+ } else {
+ return selected.create(properties, members, accuracy);
+ }
+ }
+ throw new ClassCastException();
+ }
+
+ /**
+ * Creates a new ensemble of the type associated with this factory instance.
+ *
+ * @param properties the properties to be given to the identified object.
+ * @param members datum or reference frames which are members of this ensemble.
+ * @param accuracy inaccuracy introduced through use of this ensemble (mandatory).
+ * @return the datum ensemble.
- * @throws IllegalArgumentException if a member is an instance of {@link DatumEnsemble}, of if at least two
++ * @throws IllegalArgumentException if a member is an instance of {@code DatumEnsemble}, of if at least two
+ * different {@linkplain AbstractDatum#getConventionalRS() conventional reference systems} are found.
+ *
+ * @see #create(Map, Collection, PositionalAccuracy)
+ */
+ abstract DefaultDatumEnsemble<D> create(Map<String,?> properties, List<? extends D> members, PositionalAccuracy accuracy);
+
+ /**
+ * Creates a new ensemble with the same values as the specified one.
+ *
+ * @param ensemble the ensemble to copy.
- * @throws IllegalArgumentException if a member is an instance of {@link DatumEnsemble}, of if at least two
++ * @throws IllegalArgumentException if a member is an instance of {@code DatumEnsemble}, of if at least two
+ * different {@linkplain AbstractDatum#getConventionalRS() conventional reference systems} are found.
- *
- * @see #castOrCopy(DatumEnsemble)
+ */
- abstract DefaultDatumEnsemble<D> copy(DatumEnsemble<? extends D> object);
++ abstract DefaultDatumEnsemble<D> copy(DefaultDatumEnsemble<? extends D> object);
+
+ /**
+ * Factories for all datum types supported by this class. The types are (in order) {@link GeodeticDatum},
+ * {@link VerticalDatum}, {@link TemporalDatum}, {@link ParametricDatum} and {@link EngineeringDatum}.
+ * The types are tested in iteration order. For example, if a member implements both {@code VerticalDatum}
+ * {@code ParametricDatum} interface, then {@code VerticalDatum} has precedence.
+ */
+ private static final Factory<?>[] FACTORIES = {
+ new Factory<GeodeticDatum>(GeodeticDatum.class) {
+ @Override
- DefaultDatumEnsemble<GeodeticDatum> copy(DatumEnsemble<? extends GeodeticDatum> object) {
++ DefaultDatumEnsemble<GeodeticDatum> copy(DefaultDatumEnsemble<? extends GeodeticDatum> object) {
+ return new Geodetic(object);
+ }
+
+ @Override
+ DefaultDatumEnsemble<GeodeticDatum> create(Map<String,?> properties,
+ List<? extends GeodeticDatum> members, PositionalAccuracy accuracy)
+ {
+ return new Geodetic(properties, members, accuracy);
+ }
+ },
+
+ new Factory<VerticalDatum>(VerticalDatum.class) {
+ @Override
- DefaultDatumEnsemble<VerticalDatum> copy(DatumEnsemble<? extends VerticalDatum> object) {
++ DefaultDatumEnsemble<VerticalDatum> copy(DefaultDatumEnsemble<? extends VerticalDatum> object) {
+ return new Vertical(object);
+ }
+
+ @Override
+ DefaultDatumEnsemble<VerticalDatum> create(Map<String,?> properties,
+ List<? extends VerticalDatum> members, PositionalAccuracy accuracy)
+ {
+ return new Vertical(properties, members, accuracy);
+ }
+ },
+
+ new Factory<TemporalDatum>(TemporalDatum.class) {
+ @Override
- DefaultDatumEnsemble<TemporalDatum> copy(DatumEnsemble<? extends TemporalDatum> object) {
++ DefaultDatumEnsemble<TemporalDatum> copy(DefaultDatumEnsemble<? extends TemporalDatum> object) {
+ return new Time(object);
+ }
+
+ @Override
+ DefaultDatumEnsemble<TemporalDatum> create(Map<String,?> properties,
+ List<? extends TemporalDatum> members, PositionalAccuracy accuracy)
+ {
+ return new Time(properties, members, accuracy);
+ }
+ },
+
- new Factory<ParametricDatum>(ParametricDatum.class) {
- @Override
- DefaultDatumEnsemble<ParametricDatum> copy(DatumEnsemble<? extends ParametricDatum> object) {
- return new Parametric(object);
- }
-
- @Override
- DefaultDatumEnsemble<ParametricDatum> create(Map<String,?> properties,
- List<? extends ParametricDatum> members, PositionalAccuracy accuracy)
- {
- return new Parametric(properties, members, accuracy);
- }
- },
-
+ new Factory<EngineeringDatum>(EngineeringDatum.class) {
+ @Override
- DefaultDatumEnsemble<EngineeringDatum> copy(DatumEnsemble<? extends EngineeringDatum> object) {
++ DefaultDatumEnsemble<EngineeringDatum> copy(DefaultDatumEnsemble<? extends EngineeringDatum> object) {
+ return new Engineering(object);
+ }
+
+ @Override
+ DefaultDatumEnsemble<EngineeringDatum> create(Map<String,?> properties,
+ List<? extends EngineeringDatum> members, PositionalAccuracy accuracy)
+ {
+ return new Engineering(properties, members, accuracy);
+ }
+ },
+
+ new Factory<Datum>(Datum.class) {
+ @Override
- DefaultDatumEnsemble<Datum> copy(DatumEnsemble<? extends Datum> object) {
++ DefaultDatumEnsemble<Datum> copy(DefaultDatumEnsemble<? extends Datum> object) {
+ return new DefaultDatumEnsemble<>(object, Datum.class);
+ }
+
+ @Override
+ DefaultDatumEnsemble<Datum> create(Map<String,?> properties,
+ List<? extends Datum> members, PositionalAccuracy accuracy)
+ {
+ return new DefaultDatumEnsemble<>(properties, members, accuracy, Datum.class);
+ }
+ }
+ };
+ }
}
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
index ceddebcfc1,34ca685020..5bdef1b29d
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
@@@ -2596,9 -2600,8 +2603,8 @@@ next: while (r.next()
@SuppressWarnings("LocalVariableHidesMemberVariable")
final Map<String,Object> properties =
createProperties("Coordinate_Operation Parameter", name, epsg, isReversible, deprecated);
- properties.put(Identifier.DESCRIPTION_KEY, description);
+ properties.put(ImmutableIdentifier.DESCRIPTION_KEY, description);
- final ParameterDescriptor<?> descriptor = new DefaultParameterDescriptor<>(properties,
- 1, 1, type, valueDomain, null, null);
+ final var descriptor = new DefaultParameterDescriptor<>(properties, 1, 1, type, valueDomain, null, null);
returnValue = ensureSingleton(descriptor, returnValue, code);
}
} catch (SQLException exception) {
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/TableInfo.java
index 8e922a80eb,e032777c6a..366b8fa587
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/TableInfo.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/TableInfo.java
@@@ -26,15 -26,10 +26,15 @@@ import org.opengis.parameter.ParameterD
import org.apache.sis.referencing.privy.WKTKeywords;
import org.apache.sis.util.CharSequences;
+// Specific to the main branch:
+import org.apache.sis.referencing.crs.DefaultParametricCRS;
+import org.apache.sis.referencing.cs.DefaultParametricCS;
+import org.apache.sis.referencing.datum.DefaultParametricDatum;
+
/**
- * Information about a specific table. The MS-Access dialect of SQL is assumed;
- * it will be translated into ANSI SQL later by {@link SQLTranslator#apply(String)} if needed.
+ * Information about a specific table. This class uses the mixed-case variant of the <abbr>EPSG</abbr> table names.
+ * If needed, those names will be converted by {@link SQLTranslator#apply(String)} to the actual table names.
*
* @author Martin Desruisseaux (IRD, Geomatys)
*/
@@@ -67,9 -62,10 +67,9 @@@ final class TableInfo
*
* The order is significant: it is the key for a {@code switch} statement.
*/
- @SuppressWarnings("deprecation")
static final TableInfo[] EPSG = {
CRS = new TableInfo(CoordinateReferenceSystem.class,
- "[Coordinate Reference System]",
+ "\"Coordinate Reference System\"",
"COORD_REF_SYS_CODE",
"COORD_REF_SYS_NAME",
"COORD_REF_SYS_KIND",
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationFinder.java
index 2d6b734714,2d6ae5666e..b0aacdfee7
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationFinder.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/CoordinateOperationFinder.java
@@@ -623,7 -626,7 +622,7 @@@ public class CoordinateOperationFinder
final EllipsoidalCS cs = CommonCRS.WGS84.geographic3D().getCoordinateSystem();
if (!Utilities.equalsIgnoreMetadata(interpolationCS, cs)) {
final GeographicCRS stepCRS = factorySIS.crsFactory
- .createGeographicCRS(derivedFrom(sourceCRS), PseudoDatum.of(sourceCRS), cs);
- .createGeographicCRS(derivedFrom(sourceCRS), sourceCRS.getDatum(), sourceCRS.getDatumEnsemble(), cs);
++ .createGeographicCRS(derivedFrom(sourceCRS), DatumOrEnsemble.asDatum(sourceCRS), cs);
step1 = createOperation(sourceCRS, toAuthorityDefinition(GeographicCRS.class, stepCRS));
interpolationCRS = step1.getTargetCRS();
interpolationCS = interpolationCRS.getCoordinateSystem();
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java
index f0fd3f5e05,bb3e1b3127..ad25a5eef9
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/operation/DefaultConcatenatedOperation.java
@@@ -175,8 -175,8 +175,8 @@@ final class DefaultConcatenatedOperatio
if (targetCRS == null) {
targetCRS = crs;
} else if (mtFactory != null) {
- var builder = mtFactory.builder(Constants.COORDINATE_SYSTEM_CONVERSION);
+ var builder = CoordinateOperations.builder(mtFactory, Constants.COORDINATE_SYSTEM_CONVERSION);
- builder.setSourceAxes(crs.getCoordinateSystem(), ReferencingUtilities.getEllipsoid(crs));
+ builder.setSourceAxes(crs.getCoordinateSystem(), DatumOrEnsemble.getEllipsoid(crs).orElse(null));
builder.setTargetAxes(targetCRS.getCoordinateSystem(), null);
transform = mtFactory.createConcatenatedTransform(transform, builder.create());
}
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/AffineTransform2D.java
index 9b832ee93d,5610890dbe..7aafb68068
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/AffineTransform2D.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/AffineTransform2D.java
@@@ -277,14 -277,14 +277,14 @@@ public class AffineTransform2D extends
}
} else {
if (ptDst == null) {
- final DirectPosition2D point = new DirectPosition2D(ptSrc.getOrdinate(0), ptSrc.getOrdinate(1));
- final var point = new DirectPosition2D(ptSrc.getCoordinate(0), ptSrc.getCoordinate(1));
++ final var point = new DirectPosition2D(ptSrc.getOrdinate(0), ptSrc.getOrdinate(1));
super.transform(point, point);
return point;
}
ArgumentChecks.ensureDimensionMatches("ptDst", DIMENSION, ptDst);
if (ptDst instanceof Point2D) {
- final Point2D point = (Point2D) ptDst;
+ final var point = (Point2D) ptDst;
- point.setLocation(ptSrc.getCoordinate(0), ptSrc.getCoordinate(1));
+ point.setLocation(ptSrc.getOrdinate(0), ptSrc.getOrdinate(1));
super.transform(point, point);
return ptDst;
}
@@@ -292,10 -292,10 +292,10 @@@
/*
* At this point, we have no choice to create a temporary Point2D.
*/
- final Point2D.Double point = new Point2D.Double(ptSrc.getOrdinate(0), ptSrc.getOrdinate(1));
- final var point = new Point2D.Double(ptSrc.getCoordinate(0), ptSrc.getCoordinate(1));
++ final var point = new Point2D.Double(ptSrc.getOrdinate(0), ptSrc.getOrdinate(1));
super.transform(point, point);
- ptDst.setCoordinate(0, point.x);
- ptDst.setCoordinate(1, point.y);
+ ptDst.setOrdinate(0, point.x);
+ ptDst.setOrdinate(1, point.y);
return ptDst;
}
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/DefinitionVerifier.java
index 84c3a9053f,ae75b10e61..801897b47e
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/DefinitionVerifier.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/DefinitionVerifier.java
@@@ -305,9 -306,10 +306,9 @@@ public final class DefinitionVerifier
/**
* Returns a code indicating in which part the two given CRS differ. The given iterators usually iterate over
* exactly one element, but may iterate over more elements if the CRS were instance of {@code CompoundCRS}.
- * The returned value is one of {@link #METHOD}, {@link #CONVERSION}, {@link #CS}, {@link #DATUM},
- * {@link #PRIME_MERIDIAN}, {@link #ELLIPSOID} or {@link #OTHER} constants.
+ * The returned value is one of {@link #METHOD}, {@link #CONVERSION}, {@link #CS}, {@link #PRIME_MERIDIAN},
+ * {@link #ELLIPSOID}, {@link #DATUM} or {@link #OTHER} constants.
*/
- @SuppressWarnings("deprecation")
private static int diffCode(final Iterator<SingleCRS> authoritative, final Iterator<SingleCRS> given) {
while (authoritative.hasNext() && given.hasNext()) {
final SingleCRS crsA = authoritative.next();
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/EllipsoidalHeightCombiner.java
index dca098812d,d4e81e94fa..b851a188c4
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/EllipsoidalHeightCombiner.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/EllipsoidalHeightCombiner.java
@@@ -144,7 -147,7 +144,7 @@@ public final class EllipsoidalHeightCom
final var geod = (GeodeticCRS) crs;
final EllipsoidalCS cs3D;
cs3D = factories.getCSFactory() .createEllipsoidalCS(csProps, axes[0], axes[1], axes[2]);
- crs = factories.getCRSFactory().createGeographicCRS(crsProps, PseudoDatum.of(geod), cs3D);
- crs = factories.getCRSFactory().createGeographicCRS(crsProps, geod.getDatum(), geod.getDatumEnsemble(), cs3D);
++ crs = factories.getCRSFactory().createGeographicCRS(crsProps, DatumOrEnsemble.asDatum(geod), cs3D);
} else {
final ProjectedCRS proj = (ProjectedCRS) crs;
GeographicCRS base = proj.getBaseCRS();
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/GeodeticObjectBuilder.java
index e772cb085a,df58dc19ca..f67dfd1b31
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/GeodeticObjectBuilder.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/GeodeticObjectBuilder.java
@@@ -61,10 -61,10 +61,10 @@@ import org.apache.sis.referencing.cs.Ax
import org.apache.sis.referencing.internal.Resources;
import org.apache.sis.parameter.Parameters;
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.referencing.ObjectDomain;
-import org.opengis.referencing.datum.DatumEnsemble;
-import org.opengis.referencing.operation.MathTransform;
+// Specific to the main branch:
+import org.apache.sis.temporal.TemporalDate;
- import org.apache.sis.referencing.datum.PseudoDatum;
++import org.apache.sis.referencing.datum.DatumOrEnsemble;
+import org.apache.sis.referencing.operation.transform.MathTransformBuilder;
/**
@@@ -360,7 -367,8 +360,7 @@@ public class GeodeticObjectBuilder exte
conversionName = c.getName().getCode();
method = c.getMethod();
parameters = c.getParameterValues();
- datum = PseudoDatum.of(crs.getBaseCRS());
- datum = crs.getDatum();
- ensemble = crs.getDatumEnsemble();
++ datum = DatumOrEnsemble.asDatum(crs.getBaseCRS());
properties.putAll(IdentifiedObjects.getProperties(crs, ProjectedCRS.IDENTIFIERS_KEY));
return this;
}
diff --cc endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/ReferencingUtilities.java
index d14bc2d6f5,1e2ff61a3d..0815726c62
--- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/ReferencingUtilities.java
+++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/ReferencingUtilities.java
@@@ -55,14 -51,7 +51,13 @@@ import org.apache.sis.referencing.inter
import org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory;
import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
+// Specific to the main branch:
+import java.util.Collection;
+import java.util.NoSuchElementException;
+import org.opengis.referencing.ReferenceIdentifier;
- import org.apache.sis.referencing.datum.DefaultDatumEnsemble;
+import org.apache.sis.pending.geoapi.referencing.MissingMethods;
+import org.apache.sis.metadata.privy.Identifiers;
+import org.apache.sis.xml.NilObject;
/**
diff --cc endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/CRSBuilder.java
index aad92ab657,5f1ce20493..bfcaeb984f
--- a/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/CRSBuilder.java
+++ b/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/CRSBuilder.java
@@@ -61,11 -61,6 +61,11 @@@ import org.apache.sis.util.resources.Er
import org.apache.sis.measure.NumberRange;
import org.apache.sis.measure.Units;
+// Specific to the main branch:
+import org.apache.sis.referencing.factory.GeodeticObjectFactory;
- import org.apache.sis.referencing.datum.PseudoDatum;
++import org.apache.sis.referencing.datum.DatumOrEnsemble;
+import org.apache.sis.temporal.TemporalDate;
+
/**
* Temporary object for building a coordinate reference system from the variables in a netCDF file.
@@@ -628,7 -630,10 +628,7 @@@ previous: for (int i = components.siz
* The predefined CRS is {@link #defaultCRS} or a spherical CRS.
*/
protected final void setDatum(final CommonCRS crs) {
- datum = PseudoDatum.of(crs.geographic());
- datum = crs.datum();
- if (datum == null) {
- datumEnsemble = crs.datumEnsemble();
- }
++ datum = DatumOrEnsemble.asDatum(crs.geographic());
}
/**
@@@ -681,7 -686,8 +681,7 @@@
}
referenceSystem = crs;
coordinateSystem = (SphericalCS) crs.getCoordinateSystem();
- datum = PseudoDatum.of(crs);
- datum = crs.getDatum();
- datumEnsemble = crs.getDatumEnsemble();
++ datum = DatumOrEnsemble.asDatum(crs);
} else {
setDatum(defaultCRS);
}
@@@ -746,7 -750,8 +746,7 @@@
}
referenceSystem = crs;
coordinateSystem = crs.getCoordinateSystem();
- datum = PseudoDatum.of(crs);
- datum = crs.getDatum();
- datumEnsemble = crs.getDatumEnsemble();
++ datum = DatumOrEnsemble.asDatum(crs);
} else {
setDatum(defaultCRS);
final Integer epsg = epsgCandidateCS(Units.DEGREE);
diff --cc endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/GridMapping.java
index b37a8ab5f9,bc1f628017..5618343620
--- a/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/GridMapping.java
+++ b/endorsed/src/org.apache.sis.storage.netcdf/main/org/apache/sis/storage/netcdf/base/GridMapping.java
@@@ -83,8 -83,8 +83,8 @@@ import org.apache.sis.io.wkt.WKTFormat
import org.apache.sis.io.wkt.Warnings;
import org.apache.sis.measure.Units;
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.referencing.datum.DatumEnsemble;
+// Specific to the main branch:
- import org.apache.sis.referencing.datum.PseudoDatum;
++import org.apache.sis.referencing.datum.DatumOrEnsemble;
/**
@@@ -389,7 -390,10 +389,7 @@@ final class GridMapping
}
datum = datumFactory.createGeodeticDatum(properties, ellipsoid, meridian);
} else {
- datum = PseudoDatum.of(defaultDefinitions.geographic());
- datum = defaultDefinitions.datum();
- if (datum == null) {
- ensemble = defaultDefinitions.datumEnsemble();
- }
++ datum = DatumOrEnsemble.asDatum(defaultDefinitions.geographic());
}
/*
* Geographic CRS from all above properties.
diff --cc incubator/src/org.apache.sis.storage.geopackage/test/org/apache/sis/storage/geopackage/GpkgStoreTest.java
index 48237c43aa,6ed52ec5ed..a10d64b211
--- a/incubator/src/org.apache.sis.storage.geopackage/test/org/apache/sis/storage/geopackage/GpkgStoreTest.java
+++ b/incubator/src/org.apache.sis.storage.geopackage/test/org/apache/sis/storage/geopackage/GpkgStoreTest.java
@@@ -277,11 -277,11 +277,11 @@@ public final class GpkgStoreTest
private static void assertGeometryEquals(final FeatureSet resource, final String expectedCRS, final String expectedWKT)
throws DataStoreException
{
- final List<Feature> features = getFeatures(resource);
+ final List<AbstractFeature> features = getFeatures(resource);
assertEquals(1, features.size());
- final Feature feature = features.get(0);
+ final AbstractFeature feature = features.get(0);
- GeometryWrapper geometry = Geometries.wrap(feature.getPropertyValue("sis:geometry")).get();
+ GeometryWrapper geometry = Geometries.wrap(feature).orElseThrow();
assertEquals(expectedCRS, IdentifiedObjects.getIdentifierOrName(geometry.getCoordinateReferenceSystem()));
assertEquals(expectedWKT, geometry.formatWKT(1));
assertEquals(1, feature.getPropertyValue("fid"));
diff --cc incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/ShapefileStore.java
index 8c7da3c66c,5617c12bf9..4cf9d48d05
--- a/incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/ShapefileStore.java
+++ b/incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/ShapefileStore.java
@@@ -112,18 -113,20 +113,19 @@@ import org.apache.sis.util.Classes
import org.apache.sis.util.Utilities;
import org.apache.sis.util.collection.BackingStoreException;
-// Specific to the geoapi-3.1 and geoapi-4.0 branches:
-import org.opengis.util.CodeList;
-import org.opengis.feature.Feature;
-import org.opengis.feature.FeatureType;
-import org.opengis.feature.PropertyType;
-import org.opengis.feature.AttributeType;
-import org.opengis.filter.Expression;
-import org.opengis.filter.Filter;
-import org.opengis.filter.Literal;
-import org.opengis.filter.LogicalOperator;
-import org.opengis.filter.LogicalOperatorName;
-import org.opengis.filter.SpatialOperatorName;
-import org.opengis.filter.ValueReference;
+// Specific to the main branch:
+import org.apache.sis.feature.AbstractFeature;
+import org.apache.sis.feature.DefaultFeatureType;
+import org.apache.sis.feature.AbstractIdentifiedType;
+import org.apache.sis.feature.DefaultAttributeType;
+import org.apache.sis.filter.Expression;
+import org.apache.sis.filter.Filter;
+import org.apache.sis.pending.geoapi.filter.Literal;
+import org.apache.sis.pending.geoapi.filter.LogicalOperator;
+import org.apache.sis.pending.geoapi.filter.LogicalOperatorName;
+import org.apache.sis.pending.geoapi.filter.SpatialOperatorName;
+import org.apache.sis.pending.geoapi.filter.ValueReference;
+ import org.opengis.metadata.Identifier;
/**
@@@ -469,7 -481,11 +480,11 @@@ public final class ShapefileStore exten
long offset = (long)header.headerSize + ((long)(shpRecord.recordNumber-1)) * ((long)header.recordSize);
dbfreader.moveToOffset(offset);
final Object[] dbfRecord = dbfreader.next();
- final Feature next = type.newInstance();
+ final AbstractFeature next = type.newInstance();
+ if (shpRecord.geometry != null) {
+ shpRecord.geometry.setUserData(crs);
+ shpRecord.geometry.setSRID(geomSrid);
+ }
next.setPropertyValue(GEOMETRY_NAME, shpRecord.geometry);
for (int i = 0; i < dbfPropertiesIndex.length; i++) {
next.setPropertyValue(header.fields[dbfPropertiesIndex[i]].fieldName, dbfRecord[i]);
@@@ -489,7 -505,11 +504,11 @@@
try {
final ShapeRecord shpRecord = shpreader.next();
if (shpRecord == null) return false;
- final Feature next = type.newInstance();
+ final AbstractFeature next = type.newInstance();
+ if (shpRecord.geometry != null) {
+ shpRecord.geometry.setUserData(crs);
+ shpRecord.geometry.setSRID(geomSrid);
+ }
next.setPropertyValue(GEOMETRY_NAME, shpRecord.geometry);
action.accept(next);
return true;
diff --cc incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/ShapefileStoreTest.java
index 7c316a4154,509c9ea266..c76ed95b44
--- a/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/ShapefileStoreTest.java
+++ b/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/ShapefileStoreTest.java
@@@ -29,6 -29,6 +29,7 @@@ import java.util.stream.Stream
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.Point;
++import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.apache.sis.feature.builder.FeatureTypeBuilder;
import org.apache.sis.util.Utilities;
import org.apache.sis.filter.DefaultFilterFactory;
@@@ -94,9 -96,10 +95,10 @@@ public class ShapefileStoreTest
assertEquals(20.0, feature1.getPropertyValue("float"));
assertEquals(LocalDate.of(2023, 10, 27), feature1.getPropertyValue("date"));
Point pt1 = (Point) feature1.getPropertyValue("geometry");
+ assertTrue(pt1.getUserData() instanceof CoordinateReferenceSystem);
assertTrue(iterator.hasNext());
- Feature feature2 = iterator.next();
+ AbstractFeature feature2 = iterator.next();
assertEquals(2L, feature2.getPropertyValue("id"));
assertEquals("text2", feature2.getPropertyValue("text"));
assertEquals(40L, feature2.getPropertyValue("integer"));
diff --cc optional/src/org.apache.sis.referencing.epsg/test/org/apache/sis/referencing/factory/sql/epsg/README.md
index 33a33f55a7,8ccd767e75..fc629028d1
--- a/optional/src/org.apache.sis.referencing.epsg/test/org/apache/sis/referencing/factory/sql/epsg/README.md
+++ b/optional/src/org.apache.sis.referencing.epsg/test/org/apache/sis/referencing/factory/sql/epsg/README.md
@@@ -85,25 -83,30 +83,30 @@@ Then open the `FKeys.sql` file for edit
* At the end of all `ALTER TABLE` statement, append `ON UPDATE RESTRICT ON DELETE RESTRICT`.
* Suppress trailing spaces and save.
- In most cases this results in unmodified `FKeys.sql` file compared to the previous version.
-
+ Usually, the above editions result in no change compared to the previous scripts (ignoring white spaces),
+ in which case the maintainer can just revert the changes in order to preserve the formatting.
+ However, if some changes are found in the schema, then hard-coded values in the `DataScriptFormatter` class may need
+ to be modified, in particular the `booleanColumnIndicesForTables` and `doubleColumnIndicesForTables` collections.
- ### Main
Execute the `main` method of the `org.apache.sis.referencing.factory.sql.epsg.DataScriptFormatter` class
- located in the test directory of `sis-referencing` module
- (adjust version numbers as needed; we may provide an easier way after migration to Jigsaw modules):
+ located in the test directory of the `org.apache.sis.non-free:sis-epsg` Maven sub-project.
+ Adjust version numbers as needed in the following commands:
- ```
+ ```bash
cd _<path to SIS project directory>_
- mvn clean install
+ gradle clean test jar
export CLASSPATH=~/.m2/repository/org/apache/derby/derby/10.14.2.0/derby-10.14.2.0.jar
- export CLASSPATH=$PWD/core/sis-metadata/target/test-classes:$CLASSPATH
- export CLASSPATH=$PWD/target/binaries/sis-referencing-1.5-SNAPSHOT.jar:$CLASSPATH
- export CLASSPATH=$PWD/core/sis-metadata/target/test-classes:$CLASSPATH
- export CLASSPATH=$PWD/core/sis-referencing/target/test-classes:$CLASSPATH
- cd <path to local copy of http://svn.apache.org/repos/asf/sis/data/non-free/>
- java org.apache.sis.referencing.factory.sql.epsg.DataScriptFormatter $EPSG_SCRIPTS/PostgreSQL_Data_Script.sql \
- sis-epsg/src/main/resources/org/apache/sis/referencing/factory/sql/epsg/Data.sql
+ export CLASSPATH=~/.m2/repository/javax/measure/unit-api/2.1.3/unit-api-2.1.3.jar:$CLASSPATH
-export CLASSPATH=$PWD/geoapi/snapshot/geoapi/target/geoapi-3.1-SNAPSHOT.jar:$CLASSPATH
++export CLASSPATH=$PWD/geoapi/snapshot/geoapi/target/geoapi-3.0.2.jar:$CLASSPATH
+ export CLASSPATH=$PWD/endorsed/build/libs/org.apache.sis.referencing.jar:$CLASSPATH
+ export CLASSPATH=$PWD/endorsed/build/libs/org.apache.sis.metadata.jar:$CLASSPATH
+ export CLASSPATH=$PWD/endorsed/build/libs/org.apache.sis.util.jar:$CLASSPATH
+ export CLASSPATH=$PWD/endorsed/build/classes/java/test/org.apache.sis.referencing:$CLASSPATH
+ export CLASSPATH=$PWD/endorsed/build/classes/java/test/org.apache.sis.metadata:$CLASSPATH
+ export CLASSPATH=$PWD/optional/build/classes/java/test/org.apache.sis.referencing.epsg:$CLASSPATH
+
+ # From any directory
+ java org.apache.sis.referencing.factory.sql.epsg.DataScriptFormatter $EPSG_SCRIPTS/PostgreSQL_Data_Script.sql $NON_FREE_DIR/Data.sql
```
Run the tests. It it convenient to run `org.apache.sis.referencing.factory.sql.EPSGInstallerTest`