Search in sources :

Example 96 with Kml

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

the class GroundOverlayTest method groundOverlayReadTest.

@Test
public void groundOverlayReadTest() throws IOException, XMLStreamException, KmlException, URISyntaxException {
    final KmlReader reader = new KmlReader();
    reader.setInput(new File(pathToTestFile));
    final Kml kmlObjects = reader.read();
    reader.dispose();
    final Feature groundOverlay = kmlObjects.getAbstractFeature();
    assertEquals(KmlModelConstants.TYPE_GROUND_OVERLAY, groundOverlay.getType());
    assertEquals("GroundOverlay.kml", groundOverlay.getPropertyValue(KmlConstants.TAG_NAME));
    assertEquals("7fffffff", KmlUtilities.toKmlColor((Color) groundOverlay.getPropertyValue(KmlConstants.TAG_COLOR)));
    assertEquals(1, groundOverlay.getPropertyValue(KmlConstants.TAG_DRAW_ORDER));
    final Icon icon = (Icon) groundOverlay.getPropertyValue(KmlConstants.TAG_ICON);
    assertEquals("http://www.google.com/intl/en/images/logo.gif", icon.getHref());
    assertEquals(RefreshMode.ON_INTERVAL, icon.getRefreshMode());
    assertEquals(86400, icon.getRefreshInterval(), DELTA);
    assertEquals(0.75, icon.getViewBoundScale(), DELTA);
    final LatLonBox latLonBox = (LatLonBox) groundOverlay.getPropertyValue(KmlConstants.TAG_LAT_LON_BOX);
    assertEquals(37.83234, latLonBox.getNorth(), DELTA);
    assertEquals(37.832122, latLonBox.getSouth(), DELTA);
    assertEquals(-122.373033, latLonBox.getEast(), DELTA);
    assertEquals(-122.373724, latLonBox.getWest(), DELTA);
    assertEquals(45, latLonBox.getRotation(), DELTA);
}
Also used : Color(java.awt.Color) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) LatLonBox(org.geotoolkit.data.kml.model.LatLonBox) Kml(org.geotoolkit.data.kml.model.Kml) Icon(org.geotoolkit.data.kml.model.Icon) File(java.io.File) Feature(org.opengis.feature.Feature) Test(org.junit.Test)

Example 97 with Kml

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

the class SoundCueTest method soundCueWriteTest.

@Test
public void soundCueWriteTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException, URISyntaxException {
    final GxFactory gxFactory = DefaultGxFactory.getInstance();
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();
    final SoundCue soundCue = gxFactory.createSoundCue();
    soundCue.setHref("http://monsite.com/maressource");
    final PlayList playList = gxFactory.createPlayList();
    playList.setTourPrimitives(Arrays.asList((AbstractTourPrimitive) soundCue));
    final Feature tour = gxFactory.createTour();
    tour.setPropertyValue(KmlConstants.TAG_NAME, "example");
    tour.setPropertyValue(KmlConstants.ATT_PLAYLIST, playList);
    final Feature document = kmlFactory.createDocument();
    document.setPropertyValue(KmlConstants.TAG_NAME, "gx:SoundCue example");
    document.setPropertyValue(KmlConstants.TAG_OPEN, Boolean.TRUE);
    document.setPropertyValue(KmlConstants.TAG_FEATURES, tour);
    final Kml kml = kmlFactory.createKml(null, document, null, null);
    kml.addExtensionUri(GxConstants.URI_GX, "gx");
    final File temp = File.createTempFile("testSoundCue", ".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) 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) AbstractTourPrimitive(org.geotoolkit.data.gx.model.AbstractTourPrimitive) Kml(org.geotoolkit.data.kml.model.Kml) SoundCue(org.geotoolkit.data.gx.model.SoundCue) Feature(org.opengis.feature.Feature) File(java.io.File) Test(org.junit.Test)

Example 98 with Kml

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

the class Tour3Test method tour3ReadTest.

/*
     * Methode de test en lecture
     */
@Test
public void tour3ReadTest() throws IOException, XMLStreamException, URISyntaxException, KmlException {
    // Instanciation du reader Kml
    final KmlReader reader = new KmlReader();
    // Instanciation du reader d'extensions à partir du reader Kml
    final GxReader gxReader = new GxReader(reader);
    // Affectation au reader Kml du fichier de lecture et d'un reader d'extensions
    reader.setInput(new File(pathToTestFile));
    reader.addExtensionReader(gxReader);
    // Lecture, puis libération du reader Kml
    final Kml kmlObjects = reader.read();
    reader.dispose();
    // Vérification du contenu lu...
    final NetworkLinkControl networkLinkControl = kmlObjects.getNetworkLinkControl();
    final Update update = networkLinkControl.getUpdate();
    assertEquals(new URI("http://myserver.com/Bof.kml"), update.getTargetHref());
    assertEquals(1, update.getUpdates().size());
    final Delete delete = (Delete) update.getUpdates().get(0);
    assertEquals(1, delete.getFeatures().size());
    assertEquals(GxModelConstants.TYPE_TOUR, delete.getFeatures().get(0).getType());
    final Feature tour = delete.getFeatures().get(0);
    final PlayList playlist = (PlayList) ((List) tour.getPropertyValue(KmlConstants.ATT_PLAYLIST)).get(0);
    assertEquals(0, playlist.getTourPrimitives().size());
}
Also used : Delete(org.geotoolkit.data.kml.model.Delete) PlayList(org.geotoolkit.data.gx.model.PlayList) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) Kml(org.geotoolkit.data.kml.model.Kml) Update(org.geotoolkit.data.kml.model.Update) GxReader(org.geotoolkit.data.gx.xml.GxReader) File(java.io.File) URI(java.net.URI) Feature(org.opengis.feature.Feature) NetworkLinkControl(org.geotoolkit.data.kml.model.NetworkLinkControl) Test(org.junit.Test)

Example 99 with Kml

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

the class TourControlTest method tourControlWriteTest.

@Test
public void tourControlWriteTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException, URISyntaxException {
    final GxFactory gxFactory = DefaultGxFactory.getInstance();
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();
    final TourControl tourControl = gxFactory.createTourControl();
    tourControl.setPlayMode(EnumPlayMode.PAUSE);
    final PlayList playList = gxFactory.createPlayList();
    playList.setTourPrimitives(Arrays.asList((AbstractTourPrimitive) tourControl));
    final Feature tour = gxFactory.createTour();
    tour.setPropertyValue(KmlConstants.TAG_NAME, "example");
    tour.setPropertyValue(KmlConstants.ATT_PLAYLIST, playList);
    final Feature document = kmlFactory.createDocument();
    document.setPropertyValue(KmlConstants.TAG_NAME, "gx:TourControl example");
    document.setPropertyValue(KmlConstants.TAG_OPEN, Boolean.TRUE);
    document.setPropertyValue(KmlConstants.TAG_FEATURES, tour);
    final Kml kml = kmlFactory.createKml(null, document, null, null);
    kml.addExtensionUri(GxConstants.URI_GX, "gx");
    final File temp = File.createTempFile("testTourControl", ".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) 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) TourControl(org.geotoolkit.data.gx.model.TourControl) AbstractTourPrimitive(org.geotoolkit.data.gx.model.AbstractTourPrimitive) Kml(org.geotoolkit.data.kml.model.Kml) Feature(org.opengis.feature.Feature) File(java.io.File) Test(org.junit.Test)

Example 100 with Kml

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

the class TrackTest method trackReadTest.

@Test
public void trackReadTest() 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 folder = kmlObjects.getAbstractFeature();
    assertEquals(KmlModelConstants.TYPE_FOLDER, folder.getType());
    Feature placemark = (Feature) ((List) folder.getPropertyValue(KmlConstants.TAG_FEATURES)).get(0);
    assertEquals(KmlModelConstants.TYPE_PLACEMARK, placemark.getType());
    final Track track = (Track) placemark.getPropertyValue(KmlConstants.TAG_GEOMETRY);
    assertEquals(2, track.getWhens().size());
    assertEquals(2, track.getCoord().size());
    String when0 = "2010-05-28T02:02:09Z";
    String when1 = "2010-05-28T02:02:35Z";
    ISODateParser du = new ISODateParser();
    Calendar cal = du.getCalendar(when0);
    assertEquals(cal, track.getWhens().get(0));
    cal = du.getCalendar(when1);
    assertEquals(cal, track.getWhens().get(1));
    CoordinateSequence coordinates = track.getCoord();
    Coordinate coordinate0 = coordinates.getCoordinate(0);
    Coordinate coordinate1 = coordinates.getCoordinate(1);
    assertEquals(-122.207881, coordinate0.x, DELTA);
    assertEquals(37.371915, coordinate0.y, DELTA);
    assertEquals(156, coordinate0.z, DELTA);
    assertEquals(-122.205712, coordinate1.x, DELTA);
    assertEquals(37.373288, coordinate1.y, DELTA);
    assertEquals(152, coordinate1.z, DELTA);
    assertEquals(2, track.getAngles().size());
    Angles angles0 = track.getAngles().get(0);
    assertEquals(45.54676, angles0.getHeading(), DELTA);
    assertEquals(66.2342, angles0.getTilt(), DELTA);
    assertEquals(77, angles0.getRoll(), DELTA);
    Angles angles1 = track.getAngles().get(1);
    assertEquals(46.54676, angles1.getHeading(), DELTA);
    assertEquals(67.2342, angles1.getTilt(), DELTA);
    assertEquals(78, angles1.getRoll(), DELTA);
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) ISODateParser(org.geotoolkit.temporal.object.ISODateParser) Coordinate(org.locationtech.jts.geom.Coordinate) Calendar(java.util.Calendar) Angles(org.geotoolkit.data.gx.model.Angles) 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) Track(org.geotoolkit.data.gx.model.Track) 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