Search in sources :

Example 1 with GxReader

use of org.geotoolkit.data.gx.xml.GxReader in project geotoolkit by Geomatys.

the class SoundCueTest method soundCueReadTest.

@Test
public void soundCueReadTest() throws IOException, XMLStreamException, URISyntaxException, KmlException {
    final Feature document;
    {
        final KmlReader reader = new KmlReader();
        final GxReader gxReader = new GxReader(reader);
        reader.setInput(new File(pathToTestFile));
        reader.addExtensionReader(gxReader);
        final Kml kmlObjects = reader.read();
        reader.dispose();
        document = kmlObjects.getAbstractFeature();
    }
    assertEquals(KmlModelConstants.TYPE_DOCUMENT, document.getType());
    assertEquals("gx:SoundCue example", document.getPropertyValue(KmlConstants.TAG_NAME));
    assertEquals(Boolean.TRUE, document.getPropertyValue(KmlConstants.TAG_OPEN));
    final Feature tour = (Feature) document.getProperty(KmlConstants.TAG_FEATURES).getValue();
    assertEquals(GxModelConstants.TYPE_TOUR, tour.getType());
    assertEquals("example", tour.getPropertyValue(KmlConstants.TAG_NAME));
    Iterator<?> i = ((Iterable<?>) tour.getPropertyValue(KmlConstants.ATT_PLAYLIST)).iterator();
    assertTrue("Expected at least one element.", i.hasNext());
    final PlayList playList = (PlayList) i.next();
    assertEquals(1, playList.getTourPrimitives().size());
    final SoundCue soundCue = (SoundCue) playList.getTourPrimitives().get(0);
    assertEquals("http://monsite.com/maressource", soundCue.getHref());
    assertFalse("Expected exactly one element.", i.hasNext());
}
Also used : PlayList(org.geotoolkit.data.gx.model.PlayList) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) Kml(org.geotoolkit.data.kml.model.Kml) SoundCue(org.geotoolkit.data.gx.model.SoundCue) Feature(org.opengis.feature.Feature) GxReader(org.geotoolkit.data.gx.xml.GxReader) File(java.io.File) Test(org.junit.Test)

Example 2 with GxReader

use of org.geotoolkit.data.gx.xml.GxReader in project geotoolkit by Geomatys.

the class TimePrimitivesTest method timePrimitivesReadTest.

@Test
public void timePrimitivesReadTest() throws IOException, XMLStreamException, URISyntaxException, KmlException {
    final Feature document;
    {
        final KmlReader reader = new KmlReader();
        final GxReader gxReader = new GxReader(reader);
        reader.setInput(new File(pathToTestFile));
        reader.addExtensionReader(gxReader);
        final Kml kmlObjects = reader.read();
        reader.dispose();
        document = kmlObjects.getAbstractFeature();
    }
    assertEquals(KmlModelConstants.TYPE_DOCUMENT, document.getType());
    assertEquals("Views with Time", document.getPropertyValue(KmlConstants.TAG_NAME));
    assertEquals(Boolean.TRUE, document.getPropertyValue(KmlConstants.TAG_OPEN));
    assertEquals("\n" + "      In Google Earth, enable historical imagery and sunlight,\n" + "      then click on each placemark to fly to that point in time.\n" + "    ", document.getPropertyValue(KmlConstants.TAG_DESCRIPTION));
    Iterator<?> i = ((Iterable<?>) document.getPropertyValue(KmlConstants.TAG_FEATURES)).iterator();
    assertTrue("Expected at least one element.", i.hasNext());
    {
        final Feature placemark = (Feature) i.next();
        assertEquals("Sutro Baths in 1946", placemark.getPropertyValue(KmlConstants.TAG_NAME));
        final Camera camera0 = (Camera) placemark.getPropertyValue(KmlConstants.TAG_VIEW);
        assertEquals(1, camera0.extensions().complexes(Names.VIEW).size());
        final TimeStamp timeStamp = (TimeStamp) camera0.extensions().complexes(Names.VIEW).get(0);
        final String when = "1946-07-29T05:00:00-08:00";
        final Calendar calendarWhen = (Calendar) du.getCalendar(when).clone();
        assertEquals(calendarWhen, timeStamp.getWhen());
        assertEquals(-122.518172, camera0.getLongitude(), DELTA);
        assertEquals(37.778036, camera0.getLatitude(), DELTA);
        assertEquals(221.0, camera0.getAltitude(), DELTA);
        assertEquals(70.0, camera0.getHeading(), DELTA);
        assertEquals(75.0, camera0.getTilt(), DELTA);
    }
    assertTrue("Expected at least 2 elements.", i.hasNext());
    {
        final Feature placemark = (Feature) i.next();
        assertEquals("Palace of Fine Arts in 2002", placemark.getPropertyValue(KmlConstants.TAG_NAME));
        final Camera camera = (Camera) placemark.getPropertyValue(KmlConstants.TAG_VIEW);
        assertEquals(1, camera.extensions().complexes(Names.VIEW).size());
        final TimeSpan timeSpan = (TimeSpan) camera.extensions().complexes(Names.VIEW).get(0);
        final String begin = "2002-07-09T19:00:00-08:00";
        final Calendar calendarBegin = (Calendar) du.getCalendar(begin).clone();
        assertEquals(calendarBegin, timeSpan.getBegin());
        assertEquals(-122.444633, camera.getLongitude(), DELTA);
        assertEquals(37.801899, camera.getLatitude(), DELTA);
        assertEquals(139.629438, camera.getAltitude(), DELTA);
        assertEquals(-70.0, camera.getHeading(), DELTA);
        assertEquals(75.0, camera.getTilt(), DELTA);
    }
    assertFalse("Expected exactly 2 elements.", i.hasNext());
}
Also used : TimeSpan(org.geotoolkit.data.kml.model.TimeSpan) Calendar(java.util.Calendar) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) Kml(org.geotoolkit.data.kml.model.Kml) Camera(org.geotoolkit.data.kml.model.Camera) Feature(org.opengis.feature.Feature) GxReader(org.geotoolkit.data.gx.xml.GxReader) File(java.io.File) TimeStamp(org.geotoolkit.data.kml.model.TimeStamp) Test(org.junit.Test)

Example 3 with GxReader

use of org.geotoolkit.data.gx.xml.GxReader in project geotoolkit by Geomatys.

the class Tour2Test method tour2ReadTest.

@Test
public void tour2ReadTest() throws IOException, XMLStreamException, URISyntaxException, KmlException {
    final KmlReader reader = new KmlReader();
    final GxReader gxReader = new GxReader(reader);
    reader.setInput(new File(pathToTestFile));
    reader.addExtensionReader(gxReader);
    final Kml kmlObjects = reader.read();
    reader.dispose();
    final Feature tour = kmlObjects.getAbstractFeature();
    assertEquals(GxModelConstants.TYPE_TOUR, tour.getType());
    final PlayList playList = (PlayList) ((List) tour.getPropertyValue(KmlConstants.ATT_PLAYLIST)).get(0);
    assertEquals(4, playList.getTourPrimitives().size());
    final FlyTo flyTo = (FlyTo) playList.getTourPrimitives().get(0);
    assertEquals(5, flyTo.getDuration(), DELTA);
    assertEquals(EnumFlyToMode.SMOOTH, flyTo.getFlyToMode());
    final LookAt lookAt = (LookAt) flyTo.getView();
    assertEquals(-79.387, lookAt.getLongitude(), DELTA);
    assertEquals(43.643, lookAt.getLatitude(), DELTA);
    assertEquals(10, lookAt.getAltitude(), DELTA);
    assertEquals(-172.3, lookAt.getHeading(), DELTA);
    assertEquals(10, lookAt.getTilt(), DELTA);
    assertEquals(1200, lookAt.getRange(), DELTA);
    assertEquals(EnumAltitudeMode.RELATIVE_TO_GROUND, lookAt.getAltitudeMode());
    final TourControl tourControl = (TourControl) playList.getTourPrimitives().get(1);
    assertEquals(EnumPlayMode.PAUSE, tourControl.getPlayMode());
    final SoundCue soundCue = (SoundCue) playList.getTourPrimitives().get(2);
    assertEquals("http://dev.keyhole.com/codesite/cntowerfacts.mp3", soundCue.getHref());
    final Wait wait = (Wait) playList.getTourPrimitives().get(3);
    assertEquals(10, wait.getDuration(), DELTA);
}
Also used : PlayList(org.geotoolkit.data.gx.model.PlayList) LookAt(org.geotoolkit.data.kml.model.LookAt) FlyTo(org.geotoolkit.data.gx.model.FlyTo) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) TourControl(org.geotoolkit.data.gx.model.TourControl) Kml(org.geotoolkit.data.kml.model.Kml) SoundCue(org.geotoolkit.data.gx.model.SoundCue) Wait(org.geotoolkit.data.gx.model.Wait) GxReader(org.geotoolkit.data.gx.xml.GxReader) File(java.io.File) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Example 4 with GxReader

use of org.geotoolkit.data.gx.xml.GxReader in project geotoolkit by Geomatys.

the class TourControlTest method tourControlReadTest.

@Test
public void tourControlReadTest() throws IOException, XMLStreamException, URISyntaxException, KmlException {
    final Feature document;
    {
        final KmlReader reader = new KmlReader();
        final GxReader gxReader = new GxReader(reader);
        reader.setInput(new File(pathToTestFile));
        reader.addExtensionReader(gxReader);
        final Kml kmlObjects = reader.read();
        reader.dispose();
        document = kmlObjects.getAbstractFeature();
    }
    assertEquals(KmlModelConstants.TYPE_DOCUMENT, document.getType());
    assertEquals("gx:TourControl example", document.getPropertyValue(KmlConstants.TAG_NAME));
    assertEquals(Boolean.TRUE, document.getPropertyValue(KmlConstants.TAG_OPEN));
    final Feature tour = (Feature) document.getProperty(KmlConstants.TAG_FEATURES).getValue();
    assertEquals(GxModelConstants.TYPE_TOUR, tour.getType());
    assertEquals("example", tour.getPropertyValue(KmlConstants.TAG_NAME));
    Iterator<?> i = ((Iterable<?>) tour.getPropertyValue(KmlConstants.ATT_PLAYLIST)).iterator();
    assertTrue("Expected at least one element.", i.hasNext());
    final PlayList playList = (PlayList) i.next();
    assertEquals(1, playList.getTourPrimitives().size());
    final TourControl tourControl = (TourControl) playList.getTourPrimitives().get(0);
    assertEquals(EnumPlayMode.PAUSE, tourControl.getPlayMode());
    assertFalse("Expected exactly one element.", i.hasNext());
}
Also used : PlayList(org.geotoolkit.data.gx.model.PlayList) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) TourControl(org.geotoolkit.data.gx.model.TourControl) Kml(org.geotoolkit.data.kml.model.Kml) Feature(org.opengis.feature.Feature) GxReader(org.geotoolkit.data.gx.xml.GxReader) File(java.io.File) Test(org.junit.Test)

Example 5 with GxReader

use of org.geotoolkit.data.gx.xml.GxReader in project geotoolkit by Geomatys.

the class TourTest method tourReadTest.

@Test
public void tourReadTest() throws IOException, XMLStreamException, URISyntaxException, KmlException {
    final KmlReader reader = new KmlReader();
    final GxReader gxReader = new GxReader(reader);
    reader.setInput(new File(pathToTestFile));
    reader.addExtensionReader(gxReader);
    final Kml kmlObjects = reader.read();
    reader.dispose();
    final Feature document = kmlObjects.getAbstractFeature();
    assertEquals(KmlModelConstants.TYPE_DOCUMENT, document.getType());
    assertEquals("gx:AnimatedUpdate example", document.getPropertyValue(KmlConstants.TAG_NAME));
    assertEquals(Boolean.TRUE, document.getPropertyValue(KmlConstants.TAG_OPEN));
    Feature tour = (Feature) document.getProperty(KmlConstants.TAG_FEATURES).getValue();
    assertEquals(GxModelConstants.TYPE_TOUR, tour.getType());
    assertEquals("Play me!", tour.getPropertyValue(KmlConstants.TAG_NAME));
    Iterator<?> i = ((Iterable<?>) tour.getPropertyValue(KmlConstants.ATT_PLAYLIST)).iterator();
    assertTrue("Expected at least one element.", i.hasNext());
    assertTrue(i.next() instanceof PlayList);
    assertFalse("Expected exactly one element.", i.hasNext());
}
Also used : PlayList(org.geotoolkit.data.gx.model.PlayList) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) Kml(org.geotoolkit.data.kml.model.Kml) GxReader(org.geotoolkit.data.gx.xml.GxReader) File(java.io.File) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Aggregations

File (java.io.File)14 GxReader (org.geotoolkit.data.gx.xml.GxReader)14 Kml (org.geotoolkit.data.kml.model.Kml)14 KmlReader (org.geotoolkit.data.kml.xml.KmlReader)14 Test (org.junit.Test)14 Feature (org.opengis.feature.Feature)14 PlayList (org.geotoolkit.data.gx.model.PlayList)7 Coordinate (org.locationtech.jts.geom.Coordinate)6 CoordinateSequence (org.locationtech.jts.geom.CoordinateSequence)5 URI (java.net.URI)3 Calendar (java.util.Calendar)3 Extensions (org.geotoolkit.data.kml.model.Extensions)3 Update (org.geotoolkit.data.kml.model.Update)3 Angles (org.geotoolkit.data.gx.model.Angles)2 AnimatedUpdate (org.geotoolkit.data.gx.model.AnimatedUpdate)2 FlyTo (org.geotoolkit.data.gx.model.FlyTo)2 SoundCue (org.geotoolkit.data.gx.model.SoundCue)2 TourControl (org.geotoolkit.data.gx.model.TourControl)2 Track (org.geotoolkit.data.gx.model.Track)2 Wait (org.geotoolkit.data.gx.model.Wait)2