Search in sources :

Example 11 with AbstractFeature

use of org.apache.sis.feature.AbstractFeature in project sis by apache.

the class Reader method parseTrackSegment.

/**
 * Parses a {@code <trkseg>} element. The STAX reader {@linkplain XMLStreamReader#getEventType() current event}
 * must be a {@link #START_ELEMENT} and the name of that start element must be {@link Tags#TRACK_SEGMENTS}.
 *
 * @throws Exception see the list of exceptions documented in {@link #parse(Consumer, boolean)}.
 */
private AbstractFeature parseTrackSegment(final int index) throws Exception {
    assert reader.isStartElement() && Tags.TRACK_SEGMENTS.equals(reader.getLocalName());
    final AbstractFeature feature = ((Store) owner).types.trackSegment.newInstance();
    feature.setPropertyValue("sis:identifier", index);
    List<AbstractFeature> wayPoints = null;
    while (true) {
        /*
             * We do not need to check 'reader.hasNext()' in above loop
             * since this check is done by the END_DOCUMENT case below.
             */
        switch(reader.next()) {
            case START_ELEMENT:
                {
                    final String name = reader.getLocalName();
                    switch(isGPX() ? name : "") {
                        default:
                            continue;
                        case Tags.TRACK_POINTS:
                            {
                                if (wayPoints == null)
                                    wayPoints = new ArrayList<>(8);
                                wayPoints.add(parseWayPoint(wayPoints.size() + 1));
                                continue;
                            }
                        case Tags.TRACK_SEGMENTS:
                            throw new DataStoreContentException(nestedElement(name));
                    }
                }
            case END_ELEMENT:
                {
                    if (Tags.TRACK_SEGMENTS.equals(reader.getLocalName()) && isGPX()) {
                        if (wayPoints != null)
                            feature.setPropertyValue(Tags.TRACK_POINTS, wayPoints);
                        return feature;
                    }
                    break;
                }
            case END_DOCUMENT:
                {
                    throw new EOFException(endOfFile());
                }
        }
    }
}
Also used : DataStoreContentException(org.apache.sis.storage.DataStoreContentException) ArrayList(java.util.ArrayList) EOFException(java.io.EOFException) AbstractFeature(org.apache.sis.feature.AbstractFeature)

Example 12 with AbstractFeature

use of org.apache.sis.feature.AbstractFeature in project sis by apache.

the class ReaderTest method verifyTrack.

/**
 * Verifies property values for the given track.
 *
 * @param  f         the track to verify.
 * @param  v11       {@code true} for GPX 1.1, or {@code false} for GPX 1.0.
 * @param  numLinks  expected number of links.
 */
@SuppressWarnings("fallthrough")
private static void verifyTrack(final AbstractFeature f, final boolean v11, final int numLinks) {
    assertEquals("name", "Track name", f.getPropertyValue("name"));
    assertEquals("cmt", "Track comment", f.getPropertyValue("cmt"));
    assertEquals("desc", "Track description", f.getPropertyValue("desc"));
    assertEquals("src", "Track source", f.getPropertyValue("src"));
    assertEquals("type", v11 ? "Track type" : null, f.getPropertyValue("type"));
    assertEquals("number", 7, f.getPropertyValue("number"));
    final List<?> links = (List<?>) f.getPropertyValue("link");
    assertEquals("links.size()", numLinks, links.size());
    switch(numLinks) {
        // Fallthrough everywhere.
        default:
        case 3:
            assertStringEquals("http://track-address3.org", links.get(2));
        case 2:
            assertStringEquals("http://track-address2.org", links.get(1));
        case 1:
            assertStringEquals("http://track-address1.org", links.get(0));
        case 0:
            break;
    }
    final List<?> segments = (List<?>) f.getPropertyValue("trkseg");
    assertEquals("segments.size()", 2, segments.size());
    final AbstractFeature seg1 = (AbstractFeature) segments.get(0);
    final AbstractFeature seg2 = (AbstractFeature) segments.get(1);
    final List<?> points = (List<?>) seg1.getPropertyValue("trkpt");
    assertEquals("points.size()", 3, points.size());
    verifyPoint((AbstractFeature) points.get(0), 0, v11);
    verifyPoint((AbstractFeature) points.get(1), 1, v11);
    verifyPoint((AbstractFeature) points.get(2), 2, v11);
    assertTrue(((Collection<?>) seg2.getPropertyValue("trkpt")).isEmpty());
    final Polyline p = (Polyline) f.getPropertyValue("sis:geometry");
    assertEquals("pointCount", 3, p.getPointCount());
    assertEquals("point(0)", new Point(15, 10), p.getPoint(0));
    assertEquals("point(1)", new Point(25, 20), p.getPoint(1));
    assertEquals("point(2)", new Point(35, 30), p.getPoint(2));
    assertEnvelopeEquals(15, 35, 10, 30, (Envelope) f.getPropertyValue("sis:envelope"));
}
Also used : Polyline(com.esri.core.geometry.Polyline) AbstractFeature(org.apache.sis.feature.AbstractFeature) List(java.util.List) Point(com.esri.core.geometry.Point)

Aggregations

AbstractFeature (org.apache.sis.feature.AbstractFeature)12 EOFException (java.io.EOFException)4 DataStoreContentException (org.apache.sis.storage.DataStoreContentException)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Point (com.esri.core.geometry.Point)2 Polyline (com.esri.core.geometry.Polyline)1 URI (java.net.URI)1 DecimalFormat (java.text.DecimalFormat)1 MessageFormat (java.text.MessageFormat)1 List (java.util.List)1 Logger (java.util.logging.Logger)1 AbstractAttribute (org.apache.sis.feature.AbstractAttribute)1 DBFDatabaseMetaData (org.apache.sis.internal.shapefile.jdbc.metadata.DBFDatabaseMetaData)1 StorageConnector (org.apache.sis.storage.StorageConnector)1 Ignore (org.junit.Ignore)1