Search in sources :

Example 11 with DefaultGeographicBoundingBox

use of org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox in project sis by apache.

the class FormatterTest method testAppendGeographicBoundingBox.

/**
 * Tests (indirectly) {@link Formatter#append(GeographicBoundingBox, int)}.
 */
@Test
public void testAppendGeographicBoundingBox() {
    assertWktEquals(Convention.WKT2_SIMPLIFIED, "BBox[51.43, 2.54, 55.77, 6.40]", new DefaultGeographicBoundingBox(2.54, 6.40, 51.43, 55.77));
    assertWktEquals(Convention.WKT1, "BBOX[51.43, 2.54, 55.77, 6.40]", new DefaultGeographicBoundingBox(2.54, 6.40, 51.43, 55.77));
}
Also used : DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) Test(org.junit.Test)

Example 12 with DefaultGeographicBoundingBox

use of org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox in project sis by apache.

the class CoordinateOperationMethods method getDomainOfValidity.

/**
 * Returns the domain of validity for the given operation method.
 * If no domain of validity is found, returns {@code null}.
 */
private DefaultGeographicBoundingBox getDomainOfValidity(final OperationMethod method) {
    DefaultGeographicBoundingBox validity = null;
    for (final GenericName name : method.getAlias()) {
        final String tip = name.tip().toString();
        final DefaultGeographicBoundingBox candidate = domainOfValidity.get(tip);
        if (candidate != null) {
            if (validity == null) {
                validity = new DefaultGeographicBoundingBox(candidate);
            } else {
                validity.add(candidate);
            }
        }
    }
    return validity;
}
Also used : GenericName(org.opengis.util.GenericName) DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox)

Example 13 with DefaultGeographicBoundingBox

use of org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox in project sis by apache.

the class GeodeticObjectParser method parseMetadataAndClose.

/**
 * Parses an <strong>optional</strong> metadata elements and close.
 * This include elements like {@code "SCOPE"}, {@code "ID"} (WKT 2) or {@code "AUTHORITY"} (WKT 1).
 * This WKT 1 element has the following pattern:
 *
 * {@preformat wkt
 *     AUTHORITY["<name>", "<code>"]
 * }
 *
 * <div class="section">Fallback</div>
 * The name is a mandatory property, but some invalid WKT with an empty string exist. In such case,
 * we will use the name of the enclosed datum. Indeed, it is not uncommon to have the same name for
 * a geographic CRS and its geodetic datum.
 *
 * @param  parent    the parent element.
 * @param  name      the name of the parent object being parsed.
 * @param  fallback  the fallback to use if {@code name} is empty.
 * @return a properties map with the parent name and the optional authority code.
 * @throws ParseException if an element can not be parsed.
 */
@SuppressWarnings("ReturnOfCollectionOrArrayField")
private Map<String, Object> parseMetadataAndClose(final Element parent, final String name, final IdentifiedObject fallback) throws ParseException {
    properties.clear();
    properties.put(IdentifiedObject.NAME_KEY, (name.isEmpty() && fallback != null) ? fallback.getName() : name);
    Element element;
    while ((element = parent.pullElement(OPTIONAL, ID_KEYWORDS)) != null) {
        final String codeSpace = element.pullString("codeSpace");
        // Accepts Integer as well as String.
        final String code = element.pullObject("code").toString();
        // Accepts Number as well as String.
        final Object version = element.pullOptional(Object.class);
        final Element citation = element.pullElement(OPTIONAL, WKTKeywords.Citation);
        final String authority;
        if (citation != null) {
            authority = citation.pullString("authority");
            citation.close(ignoredElements);
        } else {
            authority = codeSpace;
        }
        final Element uri = element.pullElement(OPTIONAL, WKTKeywords.URI);
        if (uri != null) {
            // TODO: not yet stored, since often redundant with other informations.
            uri.pullString("URI");
            uri.close(ignoredElements);
        }
        element.close(ignoredElements);
        /*
             * Note: we could be tempted to assign the authority to the name as well, like below:
             *
             *     if (name instanceof String) {
             *         name = new NamedIdentifier(authority, (String) name);
             *     }
             *     properties.put(IdentifiedObject.NAME_KEY, name);
             *
             * However experience shows that it is often wrong in practice, because peoples often
             * declare EPSG codes but still use WKT names much shorter than the EPSG names
             * (for example "WGS84" for the datum instead than "World Geodetic System 1984"),
             * so the name in WKT is often not compliant with the name actually defined by the authority.
             */
        final ImmutableIdentifier id = new ImmutableIdentifier(Citations.fromName(authority), codeSpace, code, (version != null) ? version.toString() : null, null);
        final Object previous = properties.put(IdentifiedObject.IDENTIFIERS_KEY, id);
        if (previous != null) {
            Identifier[] identifiers;
            if (previous instanceof Identifier) {
                identifiers = new Identifier[] { (Identifier) previous, id };
            } else {
                identifiers = (Identifier[]) previous;
                final int n = identifiers.length;
                identifiers = Arrays.copyOf(identifiers, n + 1);
                identifiers[n] = id;
            }
            properties.put(IdentifiedObject.IDENTIFIERS_KEY, identifiers);
        // REMINDER: values associated to IDENTIFIERS_KEY shall be recognized by 'toIdentifier(Object)'.
        }
    }
    /*
         * Other metadata (SCOPE, AREA, etc.).  ISO 19162 said that at most one of each type shall be present,
         * but our parser accepts an arbitrary amount of some kinds of metadata. They can be recognized by the
         * 'while' loop.
         *
         * Most WKT do not contain any of those metadata, so we perform an 'isEmpty()' check as an optimization
         * for those common cases.
         */
    if (!parent.isEmpty()) {
        /*
             * Example: SCOPE["Large scale topographic mapping and cadastre."]
             */
        element = parent.pullElement(OPTIONAL, WKTKeywords.Scope);
        if (element != null) {
            // Other types like Datum use the same key.
            properties.put(ReferenceSystem.SCOPE_KEY, element.pullString("scope"));
            element.close(ignoredElements);
        }
        /*
             * Example: AREA["Netherlands offshore."]
             */
        DefaultExtent extent = null;
        while ((element = parent.pullElement(OPTIONAL, WKTKeywords.Area)) != null) {
            final String area = element.pullString("area");
            element.close(ignoredElements);
            if (extent == null) {
                extent = new DefaultExtent(area, null, null, null);
            } else {
                extent.getGeographicElements().add(new DefaultGeographicDescription(area));
            }
        }
        /*
             * Example: BBOX[51.43, 2.54, 55.77, 6.40]
             */
        while ((element = parent.pullElement(OPTIONAL, WKTKeywords.BBox)) != null) {
            final double southBoundLatitude = element.pullDouble("southBoundLatitude");
            final double westBoundLongitude = element.pullDouble("westBoundLongitude");
            final double northBoundLatitude = element.pullDouble("northBoundLatitude");
            final double eastBoundLongitude = element.pullDouble("eastBoundLongitude");
            element.close(ignoredElements);
            if (extent == null)
                extent = new DefaultExtent();
            extent.getGeographicElements().add(new DefaultGeographicBoundingBox(westBoundLongitude, eastBoundLongitude, southBoundLatitude, northBoundLatitude));
        }
        /*
             * Example: VERTICALEXTENT[-1000, 0, LENGTHUNIT[“metre”, 1]]
             *
             * Units are optional, default to metres (no "contextual units" here).
             */
        while ((element = parent.pullElement(OPTIONAL, WKTKeywords.VerticalExtent)) != null) {
            final double minimum = element.pullDouble("minimum");
            final double maximum = element.pullDouble("maximum");
            Unit<Length> unit = parseScaledUnit(element, WKTKeywords.LengthUnit, Units.METRE);
            element.close(ignoredElements);
            if (unit == null)
                unit = Units.METRE;
            if (extent == null)
                extent = new DefaultExtent();
            verticalElements = new VerticalInfo(verticalElements, extent, minimum, maximum, unit).resolve(verticalCRS);
        }
        /*
             * Example: TIMEEXTENT[2013-01-01, 2013-12-31]
             *
             * TODO: syntax like TIMEEXTENT[“Jurassic”, “Quaternary”] is not yet supported.
             * See https://issues.apache.org/jira/browse/SIS-163
             *
             * This operation requires the the sis-temporal module. If not available,
             * we will report a warning and leave the temporal extent missing.
             */
        while ((element = parent.pullElement(OPTIONAL, WKTKeywords.TimeExtent)) != null) {
            if (element.peekValue() instanceof String) {
                element.pullString("startTime");
                element.pullString("endTime");
                element.close(ignoredElements);
                warning(parent, element, Errors.formatInternational(Errors.Keys.UnsupportedType_1, "TimeExtent[String,String]"), null);
            } else {
                final Date startTime = element.pullDate("startTime");
                final Date endTime = element.pullDate("endTime");
                element.close(ignoredElements);
                try {
                    final DefaultTemporalExtent t = new DefaultTemporalExtent();
                    t.setBounds(startTime, endTime);
                    if (extent == null)
                        extent = new DefaultExtent();
                    extent.getTemporalElements().add(t);
                } catch (UnsupportedOperationException e) {
                    warning(parent, element, null, e);
                }
            }
        }
        if (extent != null) {
            properties.put(ReferenceSystem.DOMAIN_OF_VALIDITY_KEY, extent);
        }
        /*
             * Example: REMARK["Замечание на русском языке"]
             */
        element = parent.pullElement(OPTIONAL, WKTKeywords.Remark);
        if (element != null) {
            properties.put(IdentifiedObject.REMARKS_KEY, element.pullString("remarks"));
            element.close(ignoredElements);
        }
    }
    parent.close(ignoredElements);
    return properties;
}
Also used : Date(java.util.Date) DefaultGeographicDescription(org.apache.sis.metadata.iso.extent.DefaultGeographicDescription) ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier) ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) Identifier(org.opengis.metadata.Identifier) DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) DefaultExtent(org.apache.sis.metadata.iso.extent.DefaultExtent) Length(javax.measure.quantity.Length) DefaultTemporalExtent(org.apache.sis.metadata.iso.extent.DefaultTemporalExtent) IdentifiedObject(org.opengis.referencing.IdentifiedObject) ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier)

Example 14 with DefaultGeographicBoundingBox

use of org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox in project sis by apache.

the class CRSTest method testSuggestCommonTarget.

/**
 * Tests {@link CRS#suggestCommonTarget(GeographicBoundingBox, CoordinateReferenceSystem...)}.
 *
 * @since 0.8
 */
@Test
public void testSuggestCommonTarget() {
    /*
         * Prepare 4 CRS with different datum (so we can more easily differentiate them in the assertions) and
         * different domain of validity. CRS[1] is given a domain large enough for all CRS except the last one.
         */
    final Map<String, Object> properties = new HashMap<>(4);
    final CartesianCS cs = (CartesianCS) StandardDefinitions.createCoordinateSystem(Constants.EPSG_PROJECTED_CS);
    final ProjectedCRS[] crs = new ProjectedCRS[4];
    for (int i = 0; i < crs.length; i++) {
        final CommonCRS baseCRS;
        final double ymin, ymax;
        switch(i) {
            case 0:
                baseCRS = CommonCRS.WGS84;
                ymin = 2;
                ymax = 4;
                break;
            case 1:
                baseCRS = CommonCRS.WGS72;
                ymin = 1;
                ymax = 4;
                break;
            case 2:
                baseCRS = CommonCRS.SPHERE;
                ymin = 2;
                ymax = 3;
                break;
            case 3:
                baseCRS = CommonCRS.NAD27;
                ymin = 3;
                ymax = 5;
                break;
            default:
                throw new AssertionError(i);
        }
        properties.put(DefaultProjectedCRS.NAME_KEY, "CRS #" + i);
        properties.put(DefaultProjectedCRS.DOMAIN_OF_VALIDITY_KEY, new DefaultExtent(null, new DefaultGeographicBoundingBox(-1, +1, ymin, ymax), null, null));
        crs[i] = new DefaultProjectedCRS(properties, baseCRS.geographic(), HardCodedConversions.MERCATOR, cs);
    }
    // Exclude the last CRS only.
    final ProjectedCRS[] overlappingCRS = Arrays.copyOf(crs, 3);
    /*
         * Test between the 3 overlapping CRS without region of interest. We expect the CRS having a domain
         * of validity large enough for all CRS; this is the second CRS created in above 'switch' statement.
         */
    assertSame("Expected CRS with widest domain of validity.", crs[1], CRS.suggestCommonTarget(null, overlappingCRS));
    /*
         * If we specify a smaller region of interest, we should get the CRS having the smallest domain of validity that
         * cover the ROI. Following lines gradually increase the ROI size and verify that we get CRS for larger domain.
         */
    final DefaultGeographicBoundingBox regionOfInterest = new DefaultGeographicBoundingBox(-1, +1, 2.1, 2.9);
    assertSame("Expected best fit for [2.1 … 2.9]°N", crs[2], CRS.suggestCommonTarget(regionOfInterest, overlappingCRS));
    regionOfInterest.setNorthBoundLatitude(3.1);
    assertSame("Expected best fit for [2.1 … 3.1]°N", crs[0], CRS.suggestCommonTarget(regionOfInterest, overlappingCRS));
    regionOfInterest.setSouthBoundLatitude(1.9);
    assertSame("Expected best fit for [1.9 … 3.1]°N", crs[1], CRS.suggestCommonTarget(regionOfInterest, overlappingCRS));
    /*
         * All above tests returned one of the CRS in the given array. Test now a case where none of those CRS
         * have a domain of validity wide enough, so suggestCommonTarget(…) need to search among the base CRS.
         */
    assertSame("Expected a GeodeticCRS since none of the ProjectedCRS have a domain of validity wide enough.", crs[0].getBaseCRS(), CRS.suggestCommonTarget(null, crs));
    /*
         * With the same domain of validity than above, suggestCommonTarget(…) should not need to fallback on the
         * base CRS anymore.
         */
    assertSame("Expected best fit for [1.9 … 3.1]°N", crs[1], CRS.suggestCommonTarget(regionOfInterest, crs));
}
Also used : CartesianCS(org.opengis.referencing.cs.CartesianCS) HashMap(java.util.HashMap) DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) DefaultProjectedCRS(org.apache.sis.referencing.crs.DefaultProjectedCRS) DefaultExtent(org.apache.sis.metadata.iso.extent.DefaultExtent) DefaultProjectedCRS(org.apache.sis.referencing.crs.DefaultProjectedCRS) Test(org.junit.Test)

Example 15 with DefaultGeographicBoundingBox

use of org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox in project sis by apache.

the class ServicesForMetadataTest method testSetGeographicBoundsFrom4D.

/**
 * Tests (indirectly) {@link ServicesForMetadata#setBounds(Envelope, DefaultGeographicBoundingBox)}
 * from a for-dimensional envelope.
 *
 * @throws TransformException should never happen.
 */
@Test
public void testSetGeographicBoundsFrom4D() throws TransformException {
    final DefaultGeographicBoundingBox box = new DefaultGeographicBoundingBox();
    box.setBounds(createEnvelope(HardCodedCRS.GEOID_4D));
    verifySpatialExtent(box);
}
Also used : DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) Test(org.junit.Test)

Aggregations

DefaultGeographicBoundingBox (org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox)16 DefaultExtent (org.apache.sis.metadata.iso.extent.DefaultExtent)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)4 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)4 DefaultTemporalExtent (org.apache.sis.metadata.iso.extent.DefaultTemporalExtent)3 DefaultVerticalExtent (org.apache.sis.metadata.iso.extent.DefaultVerticalExtent)3 GeographicBoundingBox (org.opengis.metadata.extent.GeographicBoundingBox)3 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)2 DefaultTemporalCRS (org.apache.sis.referencing.crs.DefaultTemporalCRS)2 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 Extent (org.opengis.metadata.extent.Extent)2 GeographicExtent (org.opengis.metadata.extent.GeographicExtent)2 ReferenceIdentifier (org.opengis.referencing.ReferenceIdentifier)2 GeneralDerivedCRS (org.opengis.referencing.crs.GeneralDerivedCRS)2 SingleCRS (org.opengis.referencing.crs.SingleCRS)2 TemporalCRS (org.opengis.referencing.crs.TemporalCRS)2 VerticalCRS (org.opengis.referencing.crs.VerticalCRS)2 TransformException (org.opengis.referencing.operation.TransformException)2 GenericName (org.opengis.util.GenericName)2