Search in sources :

Example 1 with Kml

use of org.geotoolkit.data.kml.model.Kml 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 Kml

use of org.geotoolkit.data.kml.model.Kml 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 Kml

use of org.geotoolkit.data.kml.model.Kml in project geotoolkit by Geomatys.

the class TimePrimitivesTest method timePrimitivesWriteTest.

@Test
public void timePrimitivesWriteTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException, URISyntaxException {
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();
    final Camera camera0 = kmlFactory.createCamera();
    camera0.setLongitude(-122.518172);
    camera0.setLatitude(37.778036);
    camera0.setAltitude(221.0);
    camera0.setHeading(70.0);
    camera0.setTilt(75.0);
    final String when = "1946-07-29T05:00:00-08:00";
    final Calendar calendarWhen = (Calendar) du.getCalendar(when).clone();
    final TimeStamp timeStamp = kmlFactory.createTimeStamp();
    timeStamp.setWhen(calendarWhen);
    camera0.extensions().complexes(Names.VIEW).add(timeStamp);
    final Feature placemark0 = kmlFactory.createPlacemark();
    placemark0.setPropertyValue(KmlConstants.TAG_NAME, "Sutro Baths in 1946");
    placemark0.setPropertyValue(KmlConstants.TAG_VIEW, camera0);
    final Camera camera1 = kmlFactory.createCamera();
    camera1.setLongitude(-122.444633);
    camera1.setLatitude(37.801899);
    camera1.setAltitude(139.629438);
    camera1.setHeading(-70.0);
    camera1.setTilt(75.0);
    final String begin = "2002-07-09T19:00:00-08:00";
    final Calendar calendarBegin = (Calendar) du.getCalendar(begin).clone();
    final TimeSpan timeSpan = kmlFactory.createTimeSpan();
    timeSpan.setBegin(calendarBegin);
    camera1.extensions().complexes(Names.VIEW).add(timeSpan);
    final Feature placemark1 = kmlFactory.createPlacemark();
    placemark1.setPropertyValue(KmlConstants.TAG_NAME, "Palace of Fine Arts in 2002");
    placemark1.setPropertyValue(KmlConstants.TAG_VIEW, camera1);
    final Feature document = kmlFactory.createDocument();
    document.setPropertyValue(KmlConstants.TAG_NAME, "Views with Time");
    final String description = "\n      In Google Earth, enable historical imagery and sunlight,\n" + "      then click on each placemark to fly to that point in time.\n" + "    ";
    document.setPropertyValue(KmlConstants.TAG_DESCRIPTION, description);
    document.setPropertyValue(KmlConstants.TAG_OPEN, Boolean.TRUE);
    document.setPropertyValue(KmlConstants.TAG_FEATURES, Arrays.asList(placemark0, placemark1));
    final Kml kml = kmlFactory.createKml(null, document, null, null);
    kml.addExtensionUri(GxConstants.URI_GX, "gx");
    final File temp = File.createTempFile("testTimePrimitives", ".kml");
    temp.deleteOnExit();
    final KmlWriter writer = new KmlWriter();
    final GxWriter gxWriter = new GxWriter(writer);
    writer.setOutput(temp);
    writer.addExtensionWriter(GxConstants.URI_GX, gxWriter);
    writer.write(kml);
    writer.dispose();
    DomCompare.compare(new File(pathToTestFile), temp);
}
Also used : TimeSpan(org.geotoolkit.data.kml.model.TimeSpan) KmlWriter(org.geotoolkit.data.kml.xml.KmlWriter) Calendar(java.util.Calendar) GxWriter(org.geotoolkit.data.gx.xml.GxWriter) KmlFactory(org.geotoolkit.data.kml.KmlFactory) DefaultKmlFactory(org.geotoolkit.data.kml.DefaultKmlFactory) Camera(org.geotoolkit.data.kml.model.Camera) Kml(org.geotoolkit.data.kml.model.Kml) Feature(org.opengis.feature.Feature) File(java.io.File) TimeStamp(org.geotoolkit.data.kml.model.TimeStamp) Test(org.junit.Test)

Example 4 with Kml

use of org.geotoolkit.data.kml.model.Kml in project geotoolkit by Geomatys.

the class Tour2Test method tour2WriteTest.

@Test
public void tour2WriteTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException, URISyntaxException {
    final GxFactory gxFactory = DefaultGxFactory.getInstance();
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();
    final FlyTo flyTo = gxFactory.createFlyTo();
    flyTo.setDuration(5);
    flyTo.setFlyToMode(EnumFlyToMode.SMOOTH);
    final LookAt lookAt = kmlFactory.createLookAt();
    lookAt.setLongitude(-79.387);
    lookAt.setLatitude(43.643);
    lookAt.setAltitude(10);
    lookAt.setHeading(-172.3);
    lookAt.setTilt(10);
    lookAt.setRange(1200);
    lookAt.setAltitudeMode(EnumAltitudeMode.RELATIVE_TO_GROUND);
    flyTo.setView(lookAt);
    final TourControl tourControl = gxFactory.createTourControl();
    tourControl.setPlayMode(EnumPlayMode.PAUSE);
    final SoundCue soundCue = gxFactory.createSoundCue();
    soundCue.setHref("http://dev.keyhole.com/codesite/cntowerfacts.mp3");
    final Wait wait = gxFactory.createWait();
    wait.setDuration(10);
    final PlayList playList = gxFactory.createPlayList();
    playList.setTourPrimitives(Arrays.asList(flyTo, tourControl, soundCue, wait));
    final Feature tour = gxFactory.createTour();
    tour.setPropertyValue(KmlConstants.ATT_PLAYLIST, playList);
    final Kml kml = kmlFactory.createKml(null, tour, null, null);
    kml.addExtensionUri(GxConstants.URI_GX, "gx");
    final File temp = File.createTempFile("testTour2", ".kml");
    temp.deleteOnExit();
    final KmlWriter writer = new KmlWriter();
    final GxWriter gxWriter = new GxWriter(writer);
    writer.setOutput(temp);
    writer.addExtensionWriter(GxConstants.URI_GX, gxWriter);
    writer.write(kml);
    writer.dispose();
    DomCompare.compare(new File(pathToTestFile), temp);
}
Also used : PlayList(org.geotoolkit.data.gx.model.PlayList) FlyTo(org.geotoolkit.data.gx.model.FlyTo) KmlWriter(org.geotoolkit.data.kml.xml.KmlWriter) GxWriter(org.geotoolkit.data.gx.xml.GxWriter) KmlFactory(org.geotoolkit.data.kml.KmlFactory) DefaultKmlFactory(org.geotoolkit.data.kml.DefaultKmlFactory) Kml(org.geotoolkit.data.kml.model.Kml) Feature(org.opengis.feature.Feature) LookAt(org.geotoolkit.data.kml.model.LookAt) TourControl(org.geotoolkit.data.gx.model.TourControl) SoundCue(org.geotoolkit.data.gx.model.SoundCue) Wait(org.geotoolkit.data.gx.model.Wait) File(java.io.File) Test(org.junit.Test)

Example 5 with Kml

use of org.geotoolkit.data.kml.model.Kml 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)

Aggregations

Kml (org.geotoolkit.data.kml.model.Kml)105 File (java.io.File)103 Test (org.junit.Test)103 Feature (org.opengis.feature.Feature)100 KmlReader (org.geotoolkit.data.kml.xml.KmlReader)52 KmlWriter (org.geotoolkit.data.kml.xml.KmlWriter)52 CoordinateSequence (org.locationtech.jts.geom.CoordinateSequence)46 Coordinate (org.locationtech.jts.geom.Coordinate)44 URI (java.net.URI)34 Point (org.geotoolkit.data.kml.model.Point)28 Color (java.awt.Color)21 Style (org.geotoolkit.data.kml.model.Style)19 IdAttributes (org.geotoolkit.data.kml.model.IdAttributes)15 PlayList (org.geotoolkit.data.gx.model.PlayList)14 GxReader (org.geotoolkit.data.gx.xml.GxReader)14 GxWriter (org.geotoolkit.data.gx.xml.GxWriter)14 Update (org.geotoolkit.data.kml.model.Update)14 DefaultKmlFactory (org.geotoolkit.data.kml.DefaultKmlFactory)13 KmlFactory (org.geotoolkit.data.kml.KmlFactory)13 NetworkLinkControl (org.geotoolkit.data.kml.model.NetworkLinkControl)12