Search in sources :

Example 6 with VerticalCRS

use of org.opengis.referencing.crs.VerticalCRS in project sis by apache.

the class MetadataTest method testMetadataWithVerticalCRS.

/**
 * Tests the (un)marshalling of a metadata with a vertical CRS.
 *
 * @throws JAXBException if the (un)marshalling process fails.
 */
@Test
public void testMetadataWithVerticalCRS() throws JAXBException {
    final Metadata metadata = unmarshalFile(Metadata.class, VERTICAL_CRS_XML);
    if (REGRESSION) {
        ((DefaultMetadata) metadata).setCharacterSet(CharacterSet.UTF_8);
    }
    assertEquals("fileIdentifier", "20090901", metadata.getFileIdentifier());
    assertEquals("language", Locale.ENGLISH, metadata.getLanguage());
    assertEquals("characterSet", CharacterSet.UTF_8, metadata.getCharacterSet());
    assertEquals("dateStamp", xmlDate("2014-01-04 00:00:00"), metadata.getDateStamp());
    /*
         * <gmd:contact>
         *   <gmd:CI_ResponsibleParty>
         *     …
         *   </gmd:CI_ResponsibleParty>
         * </gmd:contact>
         */
    final ResponsibleParty contact = getSingleton(metadata.getContacts());
    final OnlineResource onlineResource = contact.getContactInfo().getOnlineResource();
    assertNotNull("onlineResource", onlineResource);
    assertEquals("organisationName", "Apache SIS", contact.getOrganisationName().toString());
    assertEquals("linkage", URI.create("http://sis.apache.org"), onlineResource.getLinkage());
    assertEquals("function", OnLineFunction.INFORMATION, onlineResource.getFunction());
    assertEquals("role", Role.PRINCIPAL_INVESTIGATOR, contact.getRole());
    /*
         * <gmd:spatialRepresentationInfo>
         *   <gmd:MD_VectorSpatialRepresentation>
         *     …
         *   </gmd:MD_VectorSpatialRepresentation>
         * </gmd:spatialRepresentationInfo>
         */
    final SpatialRepresentation spatial = getSingleton(metadata.getSpatialRepresentationInfo());
    assertInstanceOf("spatialRepresentationInfo", VectorSpatialRepresentation.class, spatial);
    assertEquals("geometricObjectType", GeometricObjectType.POINT, getSingleton(((VectorSpatialRepresentation) spatial).getGeometricObjects()).getGeometricObjectType());
    /*
         * <gmd:referenceSystemInfo>
         *   <gmd:MD_ReferenceSystem>
         *     …
         *   </gmd:MD_ReferenceSystem>
         * </gmd:referenceSystemInfo>
         */
    assertIdentifierEquals("referenceSystemInfo", null, "EPSG", null, "World Geodetic System 84", getSingleton(metadata.getReferenceSystemInfo()).getName());
    /*
         * <gmd:identificationInfo>
         *   <gmd:MD_DataIdentification>
         *     …
         */
    final DataIdentification identification = (DataIdentification) getSingleton(metadata.getIdentificationInfo());
    final Citation citation = identification.getCitation();
    assertInstanceOf("citation", NilObject.class, citation);
    assertEquals("nilReason", NilReason.MISSING, ((NilObject) citation).getNilReason());
    assertEquals("abstract", "SIS test", identification.getAbstract().toString());
    assertEquals("language", Locale.ENGLISH, getSingleton(identification.getLanguages()));
    /*
         * <gmd:geographicElement>
         *   <gmd:EX_GeographicBoundingBox>
         *     …
         *   </gmd:EX_GeographicBoundingBox>
         * </gmd:geographicElement>
         */
    final Extent extent = getSingleton(identification.getExtents());
    final GeographicBoundingBox bbox = (GeographicBoundingBox) getSingleton(extent.getGeographicElements());
    assertEquals("extentTypeCode", Boolean.TRUE, bbox.getInclusion());
    assertEquals("westBoundLongitude", 4.55, bbox.getWestBoundLongitude(), STRICT);
    assertEquals("eastBoundLongitude", 4.55, bbox.getEastBoundLongitude(), STRICT);
    assertEquals("southBoundLatitude", 44.22, bbox.getSouthBoundLatitude(), STRICT);
    assertEquals("northBoundLatitude", 44.22, bbox.getNorthBoundLatitude(), STRICT);
    /*
         * <gmd:verticalElement>
         *   <gmd:EX_VerticalExtent>
         *     …
         *   </gmd:EX_VerticalExtent>
         * </gmd:verticalElement>
         */
    final VerticalExtent ve = getSingleton(extent.getVerticalElements());
    assertEquals("minimumValue", 0.1, ve.getMinimumValue(), STRICT);
    assertEquals("maximumValue", 10000, ve.getMaximumValue(), STRICT);
    final VerticalCRS crs = ve.getVerticalCRS();
    verifyIdentifiers("test1", crs);
    assertEquals("scope", "World", crs.getScope().toString());
    final VerticalDatum datum = crs.getDatum();
    verifyIdentifiers("test2", datum);
    assertEquals("scope", "World", datum.getScope().toString());
    // Inferred from the name.
    assertEquals("vertDatumType", VerticalDatumType.DEPTH, datum.getVerticalDatumType());
    final VerticalCS cs = crs.getCoordinateSystem();
    verifyIdentifiers("test3", cs);
    final CoordinateSystemAxis axis = cs.getAxis(0);
    verifyIdentifiers("test4", axis);
    assertEquals("axisAbbrev", "d", axis.getAbbreviation());
    assertEquals("axisDirection", AxisDirection.DOWN, axis.getDirection());
    /*
         *     …
         *   </gmd:MD_DataIdentification>
         * </gmd:identificationInfo>
         *
         * Now marshal the object and compare with the original file.
         */
    assertMarshalEqualsFile(VERTICAL_CRS_XML, metadata, VERSION_2007, "xmlns:*", "xsi:schemaLocation");
}
Also used : DataIdentification(org.opengis.metadata.identification.DataIdentification) VerticalExtent(org.opengis.metadata.extent.VerticalExtent) Extent(org.opengis.metadata.extent.Extent) SpatialRepresentation(org.opengis.metadata.spatial.SpatialRepresentation) VectorSpatialRepresentation(org.opengis.metadata.spatial.VectorSpatialRepresentation) ReferenceSystemMetadata(org.apache.sis.internal.jaxb.metadata.replace.ReferenceSystemMetadata) VerticalExtent(org.opengis.metadata.extent.VerticalExtent) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis) DefaultCoordinateSystemAxis(org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis) VerticalDatum(org.opengis.referencing.datum.VerticalDatum) DefaultVerticalDatum(org.apache.sis.referencing.datum.DefaultVerticalDatum) GeographicBoundingBox(org.opengis.metadata.extent.GeographicBoundingBox) VerticalCS(org.opengis.referencing.cs.VerticalCS) DefaultVerticalCS(org.apache.sis.referencing.cs.DefaultVerticalCS) DefaultVerticalCRS(org.apache.sis.referencing.crs.DefaultVerticalCRS) VerticalCRS(org.opengis.referencing.crs.VerticalCRS) Test(org.junit.Test)

Example 7 with VerticalCRS

use of org.opengis.referencing.crs.VerticalCRS 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);
    }
}
Also used : SingleCRS(org.opengis.referencing.crs.SingleCRS) DefaultTemporalCRS(org.apache.sis.referencing.crs.DefaultTemporalCRS) TemporalCRS(org.opengis.referencing.crs.TemporalCRS) DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) DefaultVerticalExtent(org.apache.sis.metadata.iso.extent.DefaultVerticalExtent) DefaultTemporalExtent(org.apache.sis.metadata.iso.extent.DefaultTemporalExtent) VerticalCRS(org.opengis.referencing.crs.VerticalCRS) TransformException(org.opengis.referencing.operation.TransformException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 8 with VerticalCRS

use of org.opengis.referencing.crs.VerticalCRS 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);
    }
}
Also used : SingleCRS(org.opengis.referencing.crs.SingleCRS) DefaultVerticalExtent(org.apache.sis.metadata.iso.extent.DefaultVerticalExtent) TransformException(org.opengis.referencing.operation.TransformException) DefaultVerticalExtent(org.apache.sis.metadata.iso.extent.DefaultVerticalExtent) VerticalExtent(org.opengis.metadata.extent.VerticalExtent) GeographicBoundingBox(org.opengis.metadata.extent.GeographicBoundingBox) DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) GeographicExtent(org.opengis.metadata.extent.GeographicExtent) DefaultTemporalCRS(org.apache.sis.referencing.crs.DefaultTemporalCRS) TemporalCRS(org.opengis.referencing.crs.TemporalCRS) DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) VerticalCRS(org.opengis.referencing.crs.VerticalCRS) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeographicCRS(org.opengis.referencing.crs.GeographicCRS)

Example 9 with VerticalCRS

use of org.opengis.referencing.crs.VerticalCRS in project sis by apache.

the class CRS method getVerticalComponent.

/**
 * Returns the first vertical coordinate reference system found in the given CRS, or {@code null} if there is none.
 * If the given CRS is already an instance of {@code VerticalCRS}, then this method returns it as-is.
 * Otherwise if the given CRS is compound, then this method searches for the first vertical component
 * in the order of the {@linkplain #getSingleComponents(CoordinateReferenceSystem) single components list}.
 *
 * <div class="section">Height in a three-dimensional geographic CRS</div>
 * In ISO 19111 model, ellipsoidal heights are indissociable from geographic CRS because such heights
 * without their (<var>latitude</var>, <var>longitude</var>) locations make little sense. Consequently
 * a standard-conformant library should return {@code null} when asked for the {@code VerticalCRS}
 * component of a geographic CRS. This is what {@code getVerticalComponent(…)} does when the
 * {@code allowCreateEllipsoidal} argument is {@code false}.
 *
 * <p>However in some exceptional cases, handling ellipsoidal heights like any other kind of heights
 * may simplify the task. For example when computing <em>difference</em> between heights above the
 * same datum, the impact of ignoring locations may be smaller (but not necessarily canceled).
 * Orphan {@code VerticalCRS} may also be useful for information purpose like labeling a plot axis.
 * If the caller feels confident that ellipsoidal heights are safe for his task, he can set the
 * {@code allowCreateEllipsoidal} argument to {@code true}. In such case, this {@code getVerticalComponent(…)}
 * method will create a temporary {@code VerticalCRS} from the first three-dimensional {@code GeographicCRS}
 * <em>in last resort</em>, only if it can not find an existing {@code VerticalCRS} instance.
 * <strong>Note that this is not a valid CRS according ISO 19111</strong> — use with care.</p>
 *
 * @param  crs  the coordinate reference system, or {@code null}.
 * @param  allowCreateEllipsoidal {@code true} for allowing the creation of orphan CRS for ellipsoidal heights.
 *         The recommended value is {@code false}.
 * @return the first vertical CRS, or {@code null} if none.
 *
 * @see #compound(CoordinateReferenceSystem...)
 *
 * @category information
 */
public static VerticalCRS getVerticalComponent(final CoordinateReferenceSystem crs, final boolean allowCreateEllipsoidal) {
    if (crs instanceof VerticalCRS) {
        return (VerticalCRS) crs;
    }
    if (crs instanceof CompoundCRS) {
        final CompoundCRS cp = (CompoundCRS) crs;
        boolean a = false;
        do {
            // Executed at most twice.
            for (final CoordinateReferenceSystem c : cp.getComponents()) {
                final VerticalCRS candidate = getVerticalComponent(c, a);
                if (candidate != null) {
                    return candidate;
                }
            }
        } while ((a = !a) == allowCreateEllipsoidal);
    }
    if (allowCreateEllipsoidal && horizontalCode(crs) == 3) {
        final CoordinateSystem cs = crs.getCoordinateSystem();
        final int i = AxisDirections.indexOfColinear(cs, AxisDirection.UP);
        if (i >= 0) {
            final CoordinateSystemAxis axis = cs.getAxis(i);
            VerticalCRS c = CommonCRS.Vertical.ELLIPSOIDAL.crs();
            if (!c.getCoordinateSystem().getAxis(0).equals(axis)) {
                final Map<String, ?> properties = IdentifiedObjects.getProperties(c);
                c = new DefaultVerticalCRS(properties, c.getDatum(), new DefaultVerticalCS(properties, axis));
            }
            return c;
        }
    }
    return null;
}
Also used : DefaultVerticalCRS(org.apache.sis.referencing.crs.DefaultVerticalCRS) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) DefaultVerticalCRS(org.apache.sis.referencing.crs.DefaultVerticalCRS) VerticalCRS(org.opengis.referencing.crs.VerticalCRS) CompoundCRS(org.opengis.referencing.crs.CompoundCRS) DefaultCompoundCRS(org.apache.sis.referencing.crs.DefaultCompoundCRS) CoordinateSystemAxis(org.opengis.referencing.cs.CoordinateSystemAxis) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) DefaultVerticalCS(org.apache.sis.referencing.cs.DefaultVerticalCS)

Example 10 with VerticalCRS

use of org.opengis.referencing.crs.VerticalCRS in project sis by apache.

the class SubTypes method castOrCopy.

/**
 * Returns a SIS implementation for the given coordinate reference system.
 *
 * @see AbstractCRS#castOrCopy(CoordinateReferenceSystem)
 */
static AbstractCRS castOrCopy(final CoordinateReferenceSystem object) {
    if (object instanceof DerivedCRS) {
        return DefaultDerivedCRS.castOrCopy((DerivedCRS) object);
    }
    if (object instanceof ProjectedCRS) {
        return DefaultProjectedCRS.castOrCopy((ProjectedCRS) object);
    }
    if (object instanceof GeodeticCRS) {
        if (object instanceof GeographicCRS) {
            return DefaultGeographicCRS.castOrCopy((GeographicCRS) object);
        }
        if (object instanceof GeocentricCRS) {
            return DefaultGeocentricCRS.castOrCopy((GeocentricCRS) object);
        }
        /*
             * The GeographicCRS and GeocentricCRS types are not part of ISO 19111.
             * ISO uses a single type, GeodeticCRS, for both of them and infer the
             * geographic or geocentric type from the coordinate system. We do this
             * check here for instantiating the most appropriate SIS type, but only
             * if we need to create a new object anyway (see below for rational).
             */
        if (object instanceof DefaultGeodeticCRS) {
            /*
                 * Result of XML unmarshalling — keep as-is. We avoid creating a new object because it
                 * would break object identities specified in GML document by the xlink:href attribute.
                 * However we may revisit this policy in the future. See SC_CRS.setElement(AbstractCRS).
                 */
            return (DefaultGeodeticCRS) object;
        }
        final Map<String, ?> properties = IdentifiedObjects.getProperties(object);
        final GeodeticDatum datum = ((GeodeticCRS) object).getDatum();
        final CoordinateSystem cs = object.getCoordinateSystem();
        if (cs instanceof EllipsoidalCS) {
            return new DefaultGeographicCRS(properties, datum, (EllipsoidalCS) cs);
        }
        if (cs instanceof SphericalCS) {
            return new DefaultGeocentricCRS(properties, datum, (SphericalCS) cs);
        }
        if (cs instanceof CartesianCS) {
            return new DefaultGeocentricCRS(properties, datum, (CartesianCS) cs);
        }
    }
    if (object instanceof VerticalCRS) {
        return DefaultVerticalCRS.castOrCopy((VerticalCRS) object);
    }
    if (object instanceof TemporalCRS) {
        return DefaultTemporalCRS.castOrCopy((TemporalCRS) object);
    }
    if (object instanceof EngineeringCRS) {
        return DefaultEngineeringCRS.castOrCopy((EngineeringCRS) object);
    }
    if (object instanceof ImageCRS) {
        return DefaultImageCRS.castOrCopy((ImageCRS) object);
    }
    if (object instanceof CompoundCRS) {
        return DefaultCompoundCRS.castOrCopy((CompoundCRS) object);
    }
    /*
         * Intentionally check for AbstractCRS after the interfaces because user may have defined his own
         * subclass implementing the interface. If we were checking for AbstractCRS before the interfaces,
         * the returned instance could have been a user subclass without the JAXB annotations required
         * for XML marshalling.
         */
    if (object == null || object instanceof AbstractCRS) {
        return (AbstractCRS) object;
    }
    return new AbstractCRS(object);
}
Also used : CartesianCS(org.opengis.referencing.cs.CartesianCS) EngineeringCRS(org.opengis.referencing.crs.EngineeringCRS) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) DerivedCRS(org.opengis.referencing.crs.DerivedCRS) CompoundCRS(org.opengis.referencing.crs.CompoundCRS) GeodeticDatum(org.opengis.referencing.datum.GeodeticDatum) GeodeticCRS(org.opengis.referencing.crs.GeodeticCRS) SphericalCS(org.opengis.referencing.cs.SphericalCS) TemporalCRS(org.opengis.referencing.crs.TemporalCRS) ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) ImageCRS(org.opengis.referencing.crs.ImageCRS) VerticalCRS(org.opengis.referencing.crs.VerticalCRS) EllipsoidalCS(org.opengis.referencing.cs.EllipsoidalCS) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) GeocentricCRS(org.opengis.referencing.crs.GeocentricCRS)

Aggregations

VerticalCRS (org.opengis.referencing.crs.VerticalCRS)18 Test (org.junit.Test)9 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)9 TemporalCRS (org.opengis.referencing.crs.TemporalCRS)5 VerticalDatum (org.opengis.referencing.datum.VerticalDatum)5 DependsOnMethod (org.apache.sis.test.DependsOnMethod)4 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)4 ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)4 CoordinateSystemAxis (org.opengis.referencing.cs.CoordinateSystemAxis)4 VerticalExtent (org.opengis.metadata.extent.VerticalExtent)3 CompoundCRS (org.opengis.referencing.crs.CompoundCRS)3 GeodeticCRS (org.opengis.referencing.crs.GeodeticCRS)3 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)3 TransformException (org.opengis.referencing.operation.TransformException)3 DefaultGeographicBoundingBox (org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox)2 DefaultVerticalExtent (org.apache.sis.metadata.iso.extent.DefaultVerticalExtent)2 DefaultCompoundCRS (org.apache.sis.referencing.crs.DefaultCompoundCRS)2 DefaultTemporalCRS (org.apache.sis.referencing.crs.DefaultTemporalCRS)2 DefaultVerticalCRS (org.apache.sis.referencing.crs.DefaultVerticalCRS)2 DefaultVerticalCS (org.apache.sis.referencing.cs.DefaultVerticalCS)2