Search in sources :

Example 1 with DefaultExtent

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

the class AbstractReferenceSystemTest method testWKT.

/**
 * Tests WKT formatting with a name that contains the quote character and optional information.
 * We test that the closing quote character is doubled and the optional information properly formatted.
 */
@Test
@DependsOnMethod("testCreateFromMap")
public void testWKT() {
    final Map<String, Object> properties = new HashMap<>(8);
    assertNull(properties.put(NAME_KEY, "My “object”."));
    assertNull(properties.put(SCOPE_KEY, "Large scale topographic mapping and cadastre."));
    assertNull(properties.put(REMARKS_KEY, "注です。"));
    assertNull(properties.put(IDENTIFIERS_KEY, new ImmutableIdentifier(Citations.EPSG, "EPSG", "4326", "8.2", null)));
    assertNull(properties.put(DOMAIN_OF_VALIDITY_KEY, new DefaultExtent("Netherlands offshore.", new DefaultGeographicBoundingBox(2.54, 6.40, 51.43, 55.77), new DefaultVerticalExtent(10, 1000, VerticalCRSMock.DEPTH), // TODO: needs sis-temporal module for testing that one.
    new DefaultTemporalExtent())));
    final AbstractReferenceSystem object = new AbstractReferenceSystem(properties);
    assertTrue(object.toString(Convention.WKT1).startsWith("ReferenceSystem[\"My “object”.\", AUTHORITY[\"EPSG\", \"4326\"]]"));
    assertWktEquals(Convention.WKT1, "ReferenceSystem[“My \"object\".”, AUTHORITY[“EPSG”, “4326”]]", object);
    assertWktEquals(Convention.WKT2, // Quotes replaced
    "ReferenceSystem[“My \"object\".”,\n" + "  SCOPE[“Large scale topographic mapping and cadastre.”],\n" + "  AREA[“Netherlands offshore.”],\n" + "  BBOX[51.43, 2.54, 55.77, 6.40],\n" + "  VERTICALEXTENT[-1000, -10, LENGTHUNIT[“metre”, 1]],\n" + "  ID[“EPSG”, 4326, “8.2”, URI[“urn:ogc:def:referenceSystem:EPSG:8.2:4326”]],\n" + "  REMARK[“注です。”]]", object);
    assertWktEquals(Convention.WKT2_SIMPLIFIED, "ReferenceSystem[“My \"object\".”,\n" + "  Scope[“Large scale topographic mapping and cadastre.”],\n" + "  Area[“Netherlands offshore.”],\n" + "  BBox[51.43, 2.54, 55.77, 6.40],\n" + "  VerticalExtent[-1000, -10],\n" + "  Id[“EPSG”, 4326, “8.2”, URI[“urn:ogc:def:referenceSystem:EPSG:8.2:4326”]],\n" + "  Remark[“注です。”]]", object);
    assertWktEquals(Convention.INTERNAL, // Quote doubled
    "ReferenceSystem[“My “object””.”,\n" + "  Scope[“Large scale topographic mapping and cadastre.”],\n" + "  Area[“Netherlands offshore.”],\n" + "  BBox[51.43, 2.54, 55.77, 6.40],\n" + "  VerticalExtent[-1000, -10],\n" + "  Id[“EPSG”, 4326, “8.2”],\n" + "  Remark[“注です。”]]", object);
}
Also used : DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) DefaultExtent(org.apache.sis.metadata.iso.extent.DefaultExtent) DefaultVerticalExtent(org.apache.sis.metadata.iso.extent.DefaultVerticalExtent) HashMap(java.util.HashMap) DefaultTemporalExtent(org.apache.sis.metadata.iso.extent.DefaultTemporalExtent) ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 2 with DefaultExtent

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

the class DefaultGeodeticDatumTest method testGetPositionVectorTransformation.

/**
 * Tests {@link DefaultGeodeticDatum#getPositionVectorTransformation(GeodeticDatum, Extent)}.
 */
@Test
@DependsOnMethod("testCreateAndSerialize")
public void testGetPositionVectorTransformation() {
    final Map<String, Object> properties = new HashMap<>();
    assertNull(properties.put(DefaultGeodeticDatum.NAME_KEY, "Invalid dummy datum"));
    /*
         * Associate two BursaWolfParameters, one valid only in a local area and the other one
         * valid globaly.  Note that we are building an invalid set of parameters, because the
         * source datum are not the same in both case. But for this test we are not interrested
         * in datum consistency - we only want any Bursa-Wolf parameters having different area
         * of validity.
         */
    // Local area (North Sea)
    final BursaWolfParameters local = BursaWolfParametersTest.createED87_to_WGS84();
    // Global area (World)
    final BursaWolfParameters global = BursaWolfParametersTest.createWGS72_to_WGS84();
    assertNull(properties.put(DefaultGeodeticDatum.BURSA_WOLF_KEY, new BursaWolfParameters[] { local, global }));
    /*
         * Build the datum using WGS 72 ellipsoid (so at least one of the BursaWolfParameters is real).
         */
    final DefaultGeodeticDatum datum = new DefaultGeodeticDatum(properties, GeodeticDatumMock.WGS72.getEllipsoid(), GeodeticDatumMock.WGS72.getPrimeMeridian());
    /*
         * Search for BursaWolfParameters around the North Sea area.
         */
    final DefaultGeographicBoundingBox areaOfInterest = new DefaultGeographicBoundingBox(-2, 8, 55, 60);
    final DefaultExtent extent = new DefaultExtent("Around the North Sea", areaOfInterest, null, null);
    Matrix matrix = datum.getPositionVectorTransformation(GeodeticDatumMock.NAD83, extent);
    assertNull("No BursaWolfParameters for NAD83", matrix);
    matrix = datum.getPositionVectorTransformation(GeodeticDatumMock.WGS84, extent);
    assertNotNull("BursaWolfParameters for WGS84", matrix);
    checkTransformationSignature(local, matrix, 0);
    /*
         * Expand the area of interest to something greater than North Sea, and test again.
         */
    areaOfInterest.setWestBoundLongitude(-8);
    matrix = datum.getPositionVectorTransformation(GeodeticDatumMock.WGS84, extent);
    assertNotNull("BursaWolfParameters for WGS84", matrix);
    checkTransformationSignature(global, matrix, 0);
    /*
         * Search in the reverse direction.
         */
    final DefaultGeodeticDatum targetDatum = new DefaultGeodeticDatum(GeodeticDatumMock.WGS84);
    matrix = targetDatum.getPositionVectorTransformation(datum, extent);
    // Expected result is the inverse.
    global.invert();
    checkTransformationSignature(global, matrix, 1E-6);
}
Also used : DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) Matrix(org.opengis.referencing.operation.Matrix) DefaultExtent(org.apache.sis.metadata.iso.extent.DefaultExtent) HashMap(java.util.HashMap) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 3 with DefaultExtent

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

the class EPSGDataAccess method createExtent.

/**
 * Creates information about spatial, vertical, and temporal extent (usually a domain of validity) from a code.
 *
 * <div class="note"><b>Example:</b>
 * some EPSG codes for extents are:
 *
 * <table class="sis" summary="EPSG codes examples">
 *   <tr><th>Code</th> <th>Description</th></tr>
 *   <tr><td>1262</td> <td>World</td></tr>
 *   <tr><td>3391</td> <td>World - between 80°S and 84°N</td></tr>
 * </table></div>
 *
 * @param  code  value allocated by EPSG.
 * @return the extent for the given code.
 * @throws NoSuchAuthorityCodeException if the specified {@code code} was not found.
 * @throws FactoryException if the object creation failed for some other reason.
 *
 * @see #createCoordinateReferenceSystem(String)
 * @see #createDatum(String)
 * @see org.apache.sis.metadata.iso.extent.DefaultExtent
 */
@Override
public synchronized Extent createExtent(final String code) throws NoSuchAuthorityCodeException, FactoryException {
    ArgumentChecks.ensureNonNull("code", code);
    Extent returnValue = null;
    try (ResultSet result = executeQuery("Area", "AREA_CODE", "AREA_NAME", "SELECT AREA_OF_USE," + " AREA_SOUTH_BOUND_LAT," + " AREA_NORTH_BOUND_LAT," + " AREA_WEST_BOUND_LON," + " AREA_EAST_BOUND_LON" + " FROM [Area]" + " WHERE AREA_CODE = ?", code)) {
        while (result.next()) {
            final String description = getOptionalString(result, 1);
            double ymin = getOptionalDouble(result, 2);
            double ymax = getOptionalDouble(result, 3);
            double xmin = getOptionalDouble(result, 4);
            double xmax = getOptionalDouble(result, 5);
            DefaultGeographicBoundingBox bbox = null;
            if (!Double.isNaN(ymin) || !Double.isNaN(ymax) || !Double.isNaN(xmin) || !Double.isNaN(xmax)) {
                /*
                     * Fix an error found in EPSG:3790 New Zealand - South Island - Mount Pleasant mc
                     * for older database (this error is fixed in EPSG database 8.2).
                     *
                     * Do NOT apply anything similar for the x axis, because xmin > xmax is not error:
                     * it describes a bounding box spanning the anti-meridian (±180° of longitude).
                     */
                if (ymin > ymax) {
                    final double t = ymin;
                    ymin = ymax;
                    ymax = t;
                }
                bbox = new DefaultGeographicBoundingBox(xmin, xmax, ymin, ymax);
            }
            if (description != null || bbox != null) {
                DefaultExtent extent = new DefaultExtent(description, bbox, null, null);
                extent.freeze();
                returnValue = ensureSingleton(extent, returnValue, code);
            }
        }
    } catch (SQLException exception) {
        throw databaseFailure(Extent.class, code, exception);
    }
    if (returnValue == null) {
        throw noSuchAuthorityCode(Extent.class, code);
    }
    return returnValue;
}
Also used : DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) DefaultExtent(org.apache.sis.metadata.iso.extent.DefaultExtent) DefaultExtent(org.apache.sis.metadata.iso.extent.DefaultExtent) Extent(org.opengis.metadata.extent.Extent) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString)

Example 4 with DefaultExtent

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

the class CoordinateOperationContext method setGeographicBoundingBox.

/**
 * Sets the given geographic bounding box in the given extent.
 */
static Extent setGeographicBoundingBox(Extent areaOfInterest, final GeographicBoundingBox bbox) {
    if (areaOfInterest != null) {
        final DefaultExtent ex = DefaultExtent.castOrCopy(areaOfInterest);
        ex.setGeographicElements(CollectionsExt.singletonOrEmpty(bbox));
        areaOfInterest = ex;
    } else if (bbox != null) {
        areaOfInterest = new DefaultExtent(null, bbox, null, null);
    }
    return areaOfInterest;
}
Also used : DefaultExtent(org.apache.sis.metadata.iso.extent.DefaultExtent)

Example 5 with DefaultExtent

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

the class LocationFormat method format.

/**
 * Writes a textual representation of the given location in the given stream or buffer.
 *
 * <div class="warning"><b>Upcoming API change — generalization</b><br>
 * in a future SIS version, the type of {@code location} parameter may be generalized
 * to the {@code org.opengis.referencing.gazetteer.Location} interface.
 * This change is pending GeoAPI revision.</div>
 *
 * @param  location    the location to format.
 * @param  toAppendTo  where to format the location.
 * @throws IOException if an error occurred while writing to the given appendable.
 */
@Override
@SuppressWarnings({ "fallthrough", "null" })
public void format(final AbstractLocation location, final Appendable toAppendTo) throws IOException {
    ArgumentChecks.ensureNonNull("location", location);
    final Locale locale = getLocale(Locale.Category.DISPLAY);
    final Vocabulary vocabulary = Vocabulary.getResources(locale);
    final TableAppender table = new TableAppender(toAppendTo, "│ ", columnSeparator, " │");
    table.setMultiLinesCells(true);
    /*
         * Location type.
         */
    table.appendHorizontalSeparator();
    final AbstractLocationType type = location.type();
    if (type != null) {
        append(table, vocabulary, Vocabulary.Keys.LocationType, toString(type.getName(), locale));
    }
    /*
         * Geographic identifier and alternative identifiers, if any.
         */
    append(table, vocabulary, Vocabulary.Keys.GeographicIdentifier, toString(location.getGeographicIdentifier(), locale));
    final Collection<? extends InternationalString> alt = location.getAlternativeGeographicIdentifiers();
    if (alt != null && !alt.isEmpty()) {
        boolean isFirst = true;
        vocabulary.appendLabel(Vocabulary.Keys.AlternativeIdentifiers, table);
        nextColumn(table);
        for (final InternationalString id : alt) {
            if (!isFirst) {
                isFirst = false;
                table.append(lineSeparator);
            }
            table.append(id);
        }
        table.nextLine();
    }
    /*
         * Extents (temporal and geographic). If an envelope exists and the CRS is not geographic,
         * then the envelope bounds will be appended on the same lines than the geographic bounds.
         * But before writing the bounding box and/or the envelope, check if they are redundant.
         * We may also need to change axis order (but not unit) of the envelope in order to match
         * the axis order of the geographic bounding box.
         */
    final Extent extent = new DefaultExtent(null, location.getGeographicExtent(), null, location.getTemporalExtent());
    final Range<Date> time = Extents.getTimeRange(extent);
    if (time != null) {
        append(table, vocabulary, Vocabulary.Keys.StartDate, toString(time.getMinValue()));
        append(table, vocabulary, Vocabulary.Keys.EndDate, toString(time.getMaxValue()));
    }
    GeographicBoundingBox bbox = Extents.getGeographicBoundingBox(extent);
    Envelope envelope = location.getEnvelope();
    DirectPosition position = position(location.getPosition());
    // Position in geographic CRS.
    DirectPosition geopos = null;
    // Envelope Coordinate Reference System.
    CoordinateReferenceSystem crs = null;
    // CRS in conventional (x,y) axis order.
    CoordinateReferenceSystem normCRS = null;
    // If failed to transform envelope.
    Exception warning = null;
    try {
        if (envelope != null) {
            normCRS = normalize(crs = envelope.getCoordinateReferenceSystem());
            if (normCRS != crs) {
                // Should only change order and sign.
                envelope = Envelopes.transform(envelope, normCRS);
            }
        }
        if (position != null) {
            /*
                 * If only one of the envelope or the position objects specify a CRS, assume that the other object
                 * use the same CRS. If both the envelope and the position objects specify a CRS, the envelope CRS
                 * will have precedence and the "representative position" will be projected to that CRS.
                 */
            final CoordinateReferenceSystem posCRS = position.getCoordinateReferenceSystem();
            if (normCRS == null) {
                normCRS = normalize(crs = posCRS);
                if (normCRS != crs) {
                    // Should only change order and sign.
                    envelope = Envelopes.transform(envelope, normCRS);
                }
            }
            if (bbox != null) {
                // Compute geographic position only if there is a geographic bounding box.
                GeographicCRS geogCRS = ReferencingUtilities.toNormalizedGeographicCRS(posCRS);
                if (geogCRS != null) {
                    geopos = transform(position, posCRS, geogCRS);
                }
            }
            position = transform(position, posCRS, normCRS);
        }
    } catch (FactoryException | TransformException e) {
        envelope = null;
        position = null;
        warning = e;
    }
    /*
         * At this point we got the final geographic bounding box and/or envelope to write.
         * Since we will write the projected and geographic coordinates side-by-side in the same cells,
         * we need to format them in advance so we can compute their width for internal right-alignment.
         * We do the alignment ourselves instead than using TableAppender.setCellAlignment(ALIGN_RIGHT)
         * because we do not want (projected geographic) tuple to appear far on the right side if other
         * cells have long texts.
         */
    if (bbox != null || envelope != null) {
        final CoordinateSystem cs = (crs != null) ? crs.getCoordinateSystem() : null;
        String[] geographic = null;
        String[] projected = null;
        String[] unitSymbol = null;
        AngleFormat geogFormat = null;
        NumberFormat projFormat = null;
        UnitFormat unitFormat = null;
        int maxGeogLength = 0;
        int maxProjLength = 0;
        int maxUnitLength = 0;
        boolean showProj = false;
        if (bbox != null || geopos != null) {
            geogFormat = (AngleFormat) getFormat(Angle.class);
            geographic = new String[BOUND_KEY.length];
            Arrays.fill(geographic, "");
        }
        if (envelope != null || position != null) {
            projFormat = (NumberFormat) getFormat(Number.class);
            unitFormat = (UnitFormat) getFormat(Unit.class);
            projected = new String[BOUND_KEY.length];
            unitSymbol = new String[BOUND_KEY.length];
            Arrays.fill(projected, "");
            Arrays.fill(unitSymbol, "");
        }
        for (int i = 0; i < BOUND_KEY.length; i++) {
            RoundingMode rounding = RoundingMode.FLOOR;
            double g = Double.NaN;
            double p = Double.NaN;
            int dimension = 0;
            switch(i) {
                case 0:
                    if (bbox != null)
                        g = bbox.getWestBoundLongitude();
                    if (envelope != null)
                        p = envelope.getMinimum(0);
                    break;
                case 2:
                    if (bbox != null)
                        g = bbox.getEastBoundLongitude();
                    if (envelope != null)
                        p = envelope.getMaximum(0);
                    rounding = RoundingMode.CEILING;
                    break;
                case 3:
                    if (bbox != null)
                        g = bbox.getSouthBoundLatitude();
                    if (envelope != null)
                        p = envelope.getMinimum(1);
                    dimension = 1;
                    break;
                case 5:
                    if (bbox != null)
                        g = bbox.getNorthBoundLatitude();
                    if (envelope != null)
                        p = envelope.getMaximum(1);
                    rounding = RoundingMode.CEILING;
                    dimension = 1;
                    break;
                // Fall through
                case 4:
                    dimension = 1;
                case 1:
                    if (geopos != null)
                        g = geopos.getOrdinate(dimension);
                    if (position != null)
                        p = position.getOrdinate(dimension);
                    rounding = RoundingMode.HALF_EVEN;
                    break;
            }
            if (!Double.isNaN(p)) {
                showProj |= (g != p);
                if (cs != null) {
                    final Unit<?> unit = cs.getAxis(dimension).getUnit();
                    if (unit != null) {
                        final int length = (unitSymbol[i] = unitFormat.format(unit)).length();
                        if (length > maxUnitLength) {
                            maxUnitLength = length;
                        }
                    }
                }
                try {
                    projFormat.setRoundingMode(rounding);
                } catch (UnsupportedOperationException e) {
                // Ignore.
                }
                final int length = (projected[i] = projFormat.format(p)).length();
                if (length > maxProjLength) {
                    maxProjLength = length;
                }
            }
            if (!Double.isNaN(g)) {
                geogFormat.setRoundingMode(rounding);
                final Angle angle = (dimension == 0) ? new Longitude(g) : new Latitude(g);
                final int length = (geographic[i] = geogFormat.format(angle)).length();
                if (length > maxGeogLength) {
                    maxGeogLength = length;
                }
            }
        }
        if (!showProj) {
            // All projected coordinates are identical to geographic ones.
            projected = null;
            unitSymbol = null;
            maxProjLength = 0;
            maxUnitLength = 0;
        } else if (maxProjLength != 0) {
            if (maxUnitLength != 0) {
                maxUnitLength++;
            }
            // Arbitrary space between projected and geographic coordinates.
            maxGeogLength += 4;
        }
        /*
             * At this point all coordinates have been formatted in advance.
             */
        final String separator = (projected != null && geographic != null) ? "    —" : "";
        for (int i = 0; i < BOUND_KEY.length; i++) {
            final String p = (projected != null) ? projected[i] : "";
            final String u = (unitSymbol != null) ? unitSymbol[i] : "";
            final String g = (geographic != null) ? geographic[i] : "";
            if (!p.isEmpty() || !g.isEmpty()) {
                vocabulary.appendLabel(BOUND_KEY[i], table);
                nextColumn(table);
                table.append(CharSequences.spaces(maxProjLength - p.length())).append(p);
                table.append(CharSequences.spaces(maxUnitLength - u.length())).append(u).append(separator);
                table.append(CharSequences.spaces(maxGeogLength - g.length())).append(g);
                table.nextLine();
            }
        }
    }
    if (crs != null) {
        append(table, vocabulary, Vocabulary.Keys.CoordinateRefSys, IdentifiedObjects.getName(crs, null));
    }
    /*
         * Organization responsible for defining the characteristics of the location instance.
         */
    final AbstractParty administrator = location.getAdministrator();
    if (administrator != null) {
        append(table, vocabulary, Vocabulary.Keys.Administrator, toString(administrator.getName(), locale));
    }
    table.appendHorizontalSeparator();
    table.flush();
    if (warning != null) {
        vocabulary.appendLabel(Vocabulary.Keys.Warnings, toAppendTo);
        toAppendTo.append(warning.toString()).append(lineSeparator);
    }
}
Also used : Locale(java.util.Locale) Vocabulary(org.apache.sis.util.resources.Vocabulary) DirectPosition(org.opengis.geometry.DirectPosition) DefaultExtent(org.apache.sis.metadata.iso.extent.DefaultExtent) Extent(org.opengis.metadata.extent.Extent) FactoryException(org.opengis.util.FactoryException) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) UnitFormat(org.apache.sis.measure.UnitFormat) RoundingMode(java.math.RoundingMode) TableAppender(org.apache.sis.io.TableAppender) Latitude(org.apache.sis.measure.Latitude) GeographicBoundingBox(org.opengis.metadata.extent.GeographicBoundingBox) InternationalString(org.opengis.util.InternationalString) AngleFormat(org.apache.sis.measure.AngleFormat) Envelope(org.opengis.geometry.Envelope) DefaultExtent(org.apache.sis.metadata.iso.extent.DefaultExtent) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) AbstractParty(org.apache.sis.metadata.iso.citation.AbstractParty) TransformException(org.opengis.referencing.operation.TransformException) Longitude(org.apache.sis.measure.Longitude) Date(java.util.Date) ParseException(java.text.ParseException) TransformException(org.opengis.referencing.operation.TransformException) IOException(java.io.IOException) FactoryException(org.opengis.util.FactoryException) Angle(org.apache.sis.measure.Angle) InternationalString(org.opengis.util.InternationalString) NumberFormat(java.text.NumberFormat)

Aggregations

DefaultExtent (org.apache.sis.metadata.iso.extent.DefaultExtent)8 DefaultGeographicBoundingBox (org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox)6 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 Date (java.util.Date)2 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)2 DefaultTemporalExtent (org.apache.sis.metadata.iso.extent.DefaultTemporalExtent)2 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 Extent (org.opengis.metadata.extent.Extent)2 InternationalString (org.opengis.util.InternationalString)2 IOException (java.io.IOException)1 RoundingMode (java.math.RoundingMode)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 NumberFormat (java.text.NumberFormat)1 ParseException (java.text.ParseException)1 Locale (java.util.Locale)1 Length (javax.measure.quantity.Length)1 TableAppender (org.apache.sis.io.TableAppender)1 Angle (org.apache.sis.measure.Angle)1