Search in sources :

Example 1 with GeographicBoundingBox

use of org.opengis.metadata.extent.GeographicBoundingBox in project sis by apache.

the class DefaultGeographicBoundingBoxTest method testToString.

/**
 * Tests the {@code toString()} implementation of a custom geographic bounding box inside a {@link DefaultExtent}.
 * In a previous Apache SIS version, those properties were not properly sorted.
 *
 * @since 0.8
 */
@Test
public void testToString() {
    final GeographicBoundingBox bbox = new GeographicBoundingBox() {

        @Override
        public double getWestBoundLongitude() {
            return -40;
        }

        @Override
        public double getEastBoundLongitude() {
            return 50;
        }

        @Override
        public double getSouthBoundLatitude() {
            return -20;
        }

        @Override
        public double getNorthBoundLatitude() {
            return 45;
        }

        @Override
        public Boolean getInclusion() {
            return Boolean.TRUE;
        }
    };
    final DefaultExtent extent = new DefaultExtent(null, bbox, null, null);
    assertSame(bbox, TestUtilities.getSingleton(extent.getGeographicElements()));
    assertMultilinesEquals("Extent\n" + "  └─Geographic element\n" + "      ├─West bound longitude…… 40°W\n" + "      ├─East bound longitude…… 50°E\n" + "      ├─South bound latitude…… 20°S\n" + "      ├─North bound latitude…… 45°N\n" + "      └─Extent type code……………… true\n", extent.toString());
}
Also used : GeographicBoundingBox(org.opengis.metadata.extent.GeographicBoundingBox) Test(org.junit.Test)

Example 2 with GeographicBoundingBox

use of org.opengis.metadata.extent.GeographicBoundingBox in project sis by apache.

the class ExtentsTest method testGeographicIntersection.

/**
 * Tests {@link Extents#intersection(GeographicBoundingBox, GeographicBoundingBox)}.
 */
@Test
public void testGeographicIntersection() {
    final GeographicBoundingBox b1 = new DefaultGeographicBoundingBox(10, 20, 30, 40);
    final GeographicBoundingBox b2 = new DefaultGeographicBoundingBox(15, 25, 26, 32);
    assertEquals("intersect", new DefaultGeographicBoundingBox(15, 20, 30, 32), Extents.intersection(b1, b2));
    assertSame(b1, Extents.intersection(b1, null));
    assertSame(b2, Extents.intersection(null, b2));
    assertNull(Extents.intersection((GeographicBoundingBox) null, (GeographicBoundingBox) null));
}
Also used : GeographicBoundingBox(org.opengis.metadata.extent.GeographicBoundingBox) Test(org.junit.Test)

Example 3 with GeographicBoundingBox

use of org.opengis.metadata.extent.GeographicBoundingBox in project sis by apache.

the class EPSGFactoryTest method testCompound.

/**
 * Tests the "NTF (Paris) + NGF IGN69 height" compound CRS (EPSG:7400).
 * This method tests also the domain of validity.
 *
 * @throws FactoryException if an error occurred while querying the factory.
 */
@Test
@DependsOnMethod({ "testGeographic2D", "testVertical" })
public void testCompound() throws FactoryException {
    final EPSGFactory factory = TestFactorySource.factory;
    assumeNotNull(factory);
    final CompoundCRS crs = factory.createCompoundCRS("EPSG:7400");
    assertEpsgNameAndIdentifierEqual("NTF (Paris) + NGF IGN69 height", 7400, crs);
    final List<CoordinateReferenceSystem> components = crs.getComponents();
    assertEquals("components.size()", 2, components.size());
    assertEpsgNameAndIdentifierEqual("NTF (Paris)", 4807, components.get(0));
    assertEpsgNameAndIdentifierEqual("NGF-IGN69 height", 5720, components.get(1));
    assertAxisDirectionsEqual("(no EPSG code)", crs.getCoordinateSystem(), AxisDirection.NORTH, AxisDirection.EAST, AxisDirection.UP);
    final GeographicBoundingBox bbox = CRS.getGeographicBoundingBox(crs);
    assertNotNull("No bounding box. Maybe an older EPSG database is used?", bbox);
    assertEquals("southBoundLatitude", 42.33, bbox.getSouthBoundLatitude(), STRICT);
    assertEquals("northBoundLatitude", 51.14, bbox.getNorthBoundLatitude(), STRICT);
    assertEquals("westBoundLongitude", -4.87, bbox.getWestBoundLongitude(), STRICT);
    assertEquals("eastBoundLongitude", 8.23, bbox.getEastBoundLongitude(), STRICT);
    assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("7400"));
}
Also used : GeographicBoundingBox(org.opengis.metadata.extent.GeographicBoundingBox) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 4 with GeographicBoundingBox

use of org.opengis.metadata.extent.GeographicBoundingBox in project sis by apache.

the class CoordinateOperationMethods method computeUnionOfAllDomainOfValidity.

/**
 * For each {@link OperationMethod} (identified by their name), computes the union of the domain of validity
 * of all CRS using that operation method. The result is a map where keys are {@link OperationMethod} names,
 * and values are the union of the domain of validity of all CRS using that {@code OperationMethod}.
 *
 * <p>This is a costly operation.</p>
 *
 * @todo This method is not yet used. This is pending the implementation of {@code CRSAuthorityFactory} is SIS.
 *
 * @param  factory  the factory to use for getting CRS.
 * @return the union of domain of validity of all map projections using a method of the given name.
 * @throws FactoryException if an error occurred while fetching the list of CRS.
 */
public static Map<String, DefaultGeographicBoundingBox> computeUnionOfAllDomainOfValidity(final CRSAuthorityFactory factory) throws FactoryException {
    final Map<String, DefaultGeographicBoundingBox> domainOfValidity = new HashMap<>();
    for (final String code : factory.getAuthorityCodes(GeneralDerivedCRS.class)) {
        final CoordinateReferenceSystem crs;
        try {
            crs = factory.createCoordinateReferenceSystem(code);
        } catch (FactoryException e) {
            // Ignore and inspect the next element.
            continue;
        }
        if (crs instanceof GeneralDerivedCRS) {
            final GeographicBoundingBox candidate = CRS.getGeographicBoundingBox(crs);
            if (candidate != null) {
                final String name = ((GeneralDerivedCRS) crs).getConversionFromBase().getMethod().getName().getCode();
                DefaultGeographicBoundingBox validity = domainOfValidity.get(name);
                if (validity == null) {
                    validity = new DefaultGeographicBoundingBox(candidate);
                    domainOfValidity.put(name, validity);
                } else {
                    validity.add(candidate);
                }
            }
        }
    }
    return domainOfValidity;
}
Also used : DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FactoryException(org.opengis.util.FactoryException) GeneralDerivedCRS(org.opengis.referencing.crs.GeneralDerivedCRS) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeographicBoundingBox(org.opengis.metadata.extent.GeographicBoundingBox) DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox)

Example 5 with GeographicBoundingBox

use of org.opengis.metadata.extent.GeographicBoundingBox 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)

Aggregations

GeographicBoundingBox (org.opengis.metadata.extent.GeographicBoundingBox)19 Test (org.junit.Test)8 DefaultGeographicBoundingBox (org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox)6 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)5 TransformException (org.opengis.referencing.operation.TransformException)5 FactoryException (org.opengis.util.FactoryException)5 Extent (org.opengis.metadata.extent.Extent)4 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)4 DependsOnMethod (org.apache.sis.test.DependsOnMethod)3 Envelope (org.opengis.geometry.Envelope)3 GeographicExtent (org.opengis.metadata.extent.GeographicExtent)3 ArrayList (java.util.ArrayList)2 TableAppender (org.apache.sis.io.TableAppender)2 VerticalExtent (org.opengis.metadata.extent.VerticalExtent)2 GeneralDerivedCRS (org.opengis.referencing.crs.GeneralDerivedCRS)2 SingleCRS (org.opengis.referencing.crs.SingleCRS)2 VerticalCRS (org.opengis.referencing.crs.VerticalCRS)2 InternationalString (org.opengis.util.InternationalString)2 IllegalArgumentException (com.sun.star.lang.IllegalArgumentException)1 FileInputStream (java.io.FileInputStream)1