use of org.opengis.referencing.crs.SingleCRS in project sis by apache.
the class MultiAuthoritiesFactoryTest method testCreateFromCombinedURNs.
/**
* Tests {@code MultiAuthoritiesFactory.createFoo(String)} from codes in the
* {@code "urn:ogc:def:type, type₁:authority₁:version₁:code₁, type₂:authority₂:version₂:code₂"} form.
*
* @throws FactoryException if an authority or a code is not recognized.
*
* @since 0.8
*/
@Test
@DependsOnMethod("testCreateFromURNs")
public void testCreateFromCombinedURNs() throws FactoryException {
final Set<AuthorityFactoryMock> mock = Collections.singleton(new AuthorityFactoryMock("MOCK", "2.3"));
final MultiAuthoritiesFactory factory = new MultiAuthoritiesFactory(mock, mock, mock, null);
testCreateFromCombinedURIs(factory, "urn:ogc:def:crs, crs:MOCK::4326, crs:MOCK::5714");
/*
* Following are more unusual combinations described in OGC 07-092r1 (2007)
* "Definition identifier URNs in OGC namespace".
*/
SingleCRS crs = factory.createGeographicCRS("urn:ogc:def:crs, datum:MOCK::6326, cs:MOCK::6424");
assertSame("datum", HardCodedDatum.WGS84, crs.getDatum());
assertSame("cs", HardCodedCS.GEODETIC_2D, crs.getCoordinateSystem());
/*
* Verify that invalid combined URIs are rejected.
*/
try {
factory.createObject("urn:ogc:def:cs, crs:MOCK::4326, crs:MOCK::5714");
fail("Shall not accept to create CoordinateSystem from combined URI.");
} catch (FactoryException e) {
String message = e.getMessage();
assertTrue(message, message.contains("CoordinateSystem"));
}
try {
factory.createObject("urn:ogc:def:crs, datum:MOCK::6326, cs:MOCK::6424, cs:MOCK::6422");
fail("Shall not accept to create combined URI with unexpected objects.");
} catch (FactoryException e) {
assertNotNull(e.getMessage());
}
}
use of org.opengis.referencing.crs.SingleCRS in project sis by apache.
the class ServicesForMetadata method addElements.
/**
* Initializes a horizontal, vertical and temporal extent with the values inferred from the given envelope.
*
* @param envelope the source envelope.
* @param target the target extent where to store envelope information.
* @throws TransformException if a coordinate transformation was required and failed.
*/
@Override
public void addElements(final Envelope envelope, final DefaultExtent target) throws TransformException {
final CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem();
final SingleCRS horizontalCRS = CRS.getHorizontalComponent(crs);
final VerticalCRS verticalCRS = CRS.getVerticalComponent(crs, true);
final TemporalCRS temporalCRS = CRS.getTemporalComponent(crs);
if (horizontalCRS == null && verticalCRS == null && temporalCRS == null) {
throw new TransformException(dimensionNotFound(Resources.Keys.MissingSpatioTemporalDimension_1, crs));
}
if (horizontalCRS != null) {
final DefaultGeographicBoundingBox extent = new DefaultGeographicBoundingBox();
extent.setInclusion(Boolean.TRUE);
setBounds(envelope, extent);
target.getGeographicElements().add(extent);
}
if (verticalCRS != null) {
final DefaultVerticalExtent extent = new DefaultVerticalExtent();
setVerticalExtent(envelope, extent, crs, verticalCRS);
target.getVerticalElements().add(extent);
}
if (temporalCRS != null) {
final DefaultTemporalExtent extent = new DefaultTemporalExtent();
setTemporalExtent(envelope, extent, crs, temporalCRS);
target.getTemporalElements().add(extent);
}
}
use of org.opengis.referencing.crs.SingleCRS in project sis by apache.
the class ServicesForMetadata method setBounds.
/**
* Sets the geographic, vertical and temporal extents with the values inferred from the given envelope.
* If the given {@code target} has more geographic or vertical extents than needed (0 or 1), then the
* extraneous extents are removed.
*
* @param envelope the source envelope.
* @param target the target spatiotemporal extent where to store envelope information.
* @throws TransformException if no temporal component can be extracted from the given envelope.
*/
@Override
public void setBounds(final Envelope envelope, final DefaultSpatialTemporalExtent target) throws TransformException {
final CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem();
final SingleCRS horizontalCRS = CRS.getHorizontalComponent(crs);
final VerticalCRS verticalCRS = CRS.getVerticalComponent(crs, true);
final TemporalCRS temporalCRS = CRS.getTemporalComponent(crs);
if (horizontalCRS == null && verticalCRS == null && temporalCRS == null) {
throw new TransformException(dimensionNotFound(Resources.Keys.MissingSpatioTemporalDimension_1, crs));
}
/*
* Try to set the geographic bounding box first, because this operation may fail with a
* TransformException while the other operations (vertical and temporal) should not fail.
* So doing the geographic part first help us to get a "all or nothing" behavior.
*/
DefaultGeographicBoundingBox box = null;
boolean useExistingBox = (horizontalCRS != null);
final Collection<GeographicExtent> spatialExtents = target.getSpatialExtent();
final Iterator<GeographicExtent> it = spatialExtents.iterator();
while (it.hasNext()) {
final GeographicExtent extent = it.next();
if (extent instanceof GeographicBoundingBox) {
if (useExistingBox && (extent instanceof DefaultGeographicBoundingBox)) {
box = (DefaultGeographicBoundingBox) extent;
useExistingBox = false;
} else {
it.remove();
}
}
}
if (horizontalCRS != null) {
if (box == null) {
box = new DefaultGeographicBoundingBox();
spatialExtents.add(box);
}
GeographicCRS normalizedCRS = ReferencingUtilities.toNormalizedGeographicCRS(crs);
if (normalizedCRS == null) {
normalizedCRS = CommonCRS.defaultGeographic();
}
setGeographicExtent(envelope, box, crs, normalizedCRS);
}
/*
* Other dimensions (vertical and temporal).
*/
if (verticalCRS != null) {
VerticalExtent e = target.getVerticalExtent();
if (!(e instanceof DefaultVerticalExtent)) {
e = new DefaultVerticalExtent();
target.setVerticalExtent(e);
}
setVerticalExtent(envelope, (DefaultVerticalExtent) e, crs, verticalCRS);
} else {
target.setVerticalExtent(null);
}
if (temporalCRS != null) {
setTemporalExtent(envelope, target, crs, temporalCRS);
} else {
target.setExtent(null);
}
}
use of org.opengis.referencing.crs.SingleCRS in project sis by apache.
the class CRS method getDomainOfValidity.
/**
* Returns the domain of validity of the specified coordinate reference system, or {@code null} if unknown.
* If non-null, then the returned envelope will use the same coordinate reference system them the given CRS
* argument.
*
* @param crs the coordinate reference system, or {@code null}.
* @return the envelope with coordinates in the given CRS, or {@code null} if none.
*
* @see #getGeographicBoundingBox(CoordinateReferenceSystem)
*
* @category information
* @since 0.8
*/
public static Envelope getDomainOfValidity(final CoordinateReferenceSystem crs) {
Envelope envelope = null;
GeneralEnvelope merged = null;
/* if (envelope == null) */
{
// Condition needed on other branches but not on trunk.
final GeographicBoundingBox bounds = getGeographicBoundingBox(crs);
if (bounds != null && !Boolean.FALSE.equals(bounds.getInclusion())) {
/*
* We do not assign WGS84 unconditionally to the geographic bounding box, because
* it is not defined to be on a particular datum; it is only approximative bounds.
* We try to get the GeographicCRS from the user-supplied CRS in order to reduce
* the amount of transformation needed.
*/
final SingleCRS targetCRS = getHorizontalComponent(crs);
final GeographicCRS sourceCRS = ReferencingUtilities.toNormalizedGeographicCRS(targetCRS);
if (sourceCRS != null) {
envelope = merged = new GeneralEnvelope(bounds);
merged.translate(-getGreenwichLongitude(sourceCRS), 0);
merged.setCoordinateReferenceSystem(sourceCRS);
try {
envelope = Envelopes.transform(envelope, targetCRS);
} catch (TransformException exception) {
/*
* The envelope is probably outside the range of validity for this CRS.
* It should not occurs, since the envelope is supposed to describe the
* CRS area of validity. Logs a warning and returns null, since it is a
* legal return value according this method contract.
*/
unexpectedException("getEnvelope", exception);
envelope = null;
}
}
}
}
return envelope;
}
use of org.opengis.referencing.crs.SingleCRS in project sis by apache.
the class AbstractDerivedCRS method afterUnmarshal.
/**
* Invoked by JAXB after all elements have been unmarshalled. At this point we should have the
* coordinate system (CS). The CS information is required by {@code createConversionFromBase(…)}
* in order to create a {@link MathTransform} with correct axis swapping and unit conversions.
*/
private void afterUnmarshal(Unmarshaller unmarshaller, Object parent) throws ValidationException {
String property = "conversion";
if (conversionFromBase != null) {
// Clear the temporary value now.
final SingleCRS baseCRS = CC_Conversion.setBaseCRS(conversionFromBase, null);
property = "coordinateSystem";
if (super.getCoordinateSystem() != null) {
property = "baseCRS";
if (baseCRS != null) {
conversionFromBase = createConversionFromBase(null, baseCRS, conversionFromBase);
return;
}
}
}
/*
* If we reach this point, we failed to update the conversion. The 'baseCRS' information will be lost
* and call to 'getConversionFromBase()' will throw a ClassCastException if this instance is actually
* a ProjectedCRS (because of the method overriding with return type covariance).
*/
throw new ValidationException(Errors.format(Errors.Keys.MissingValueForProperty_1, property));
}
Aggregations