Search in sources :

Example 1 with KmlWriter

use of org.geotoolkit.data.kml.xml.KmlWriter 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 2 with KmlWriter

use of org.geotoolkit.data.kml.xml.KmlWriter 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 3 with KmlWriter

use of org.geotoolkit.data.kml.xml.KmlWriter in project geotoolkit by Geomatys.

the class Tour3Test method tour3WriteTest.

/*
     * Méthode de test en écriture
     */
@Test
public void tour3WriteTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException, URISyntaxException {
    // Récupération des instances de deux fabriques (Kml et extensions Gx)
    final GxFactory gxFactory = DefaultGxFactory.getInstance();
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();
    // Construction de l'objet Kml
    final PlayList playList = gxFactory.createPlayList();
    final Feature tour = gxFactory.createTour();
    tour.setPropertyValue(KmlConstants.ATT_PLAYLIST, playList);
    final Delete delete = kmlFactory.createDelete();
    delete.setFeatures(Arrays.asList(tour));
    final Update update = kmlFactory.createUpdate();
    update.setTargetHref(new URI("http://myserver.com/Bof.kml"));
    update.setUpdates(Arrays.asList((Object) delete));
    final NetworkLinkControl networkLinkControl = kmlFactory.createNetworkLinkControl();
    networkLinkControl.setUpdate(update);
    final Kml kml = kmlFactory.createKml(networkLinkControl, null, null, null);
    // Ajout de l'espace de nom des extensions avec un préfixe
    kml.addExtensionUri(GxConstants.URI_GX, "gx");
    // Création du fichier d'écriture
    final File temp = File.createTempFile("testTour3", ".kml");
    temp.deleteOnExit();
    // Instanciation du writer Kml
    final KmlWriter writer = new KmlWriter();
    // Instanciation du writer d'extensions à partir du writer Kml
    final GxWriter gxWriter = new GxWriter(writer);
    // Affectation du fichier de sortie et du writer d'extensions au writer Kml
    writer.setOutput(temp);
    writer.addExtensionWriter(GxConstants.URI_GX, gxWriter);
    // Écriture, puis libération du writer Kml
    writer.write(kml);
    writer.dispose();
    // Vérification du contenu écrit...
    DomCompare.compare(new File(pathToTestFile), temp);
}
Also used : PlayList(org.geotoolkit.data.gx.model.PlayList) Delete(org.geotoolkit.data.kml.model.Delete) 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) Update(org.geotoolkit.data.kml.model.Update) Feature(org.opengis.feature.Feature) URI(java.net.URI) File(java.io.File) NetworkLinkControl(org.geotoolkit.data.kml.model.NetworkLinkControl) Test(org.junit.Test)

Example 4 with KmlWriter

use of org.geotoolkit.data.kml.xml.KmlWriter in project geotoolkit by Geomatys.

the class TourTest method tourWriteTest.

@Test
public void tourWriteTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException, URISyntaxException {
    final GxFactory gxFactory = DefaultGxFactory.getInstance();
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();
    final PlayList playList = gxFactory.createPlayList();
    final Feature tour = gxFactory.createTour();
    tour.setPropertyValue(KmlConstants.TAG_NAME, "Play me!");
    tour.setPropertyValue(KmlConstants.ATT_PLAYLIST, playList);
    final Feature document = kmlFactory.createDocument();
    document.setPropertyValue(KmlConstants.TAG_NAME, "gx:AnimatedUpdate 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("testTour", ".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) DefaultKmlFactory(org.geotoolkit.data.kml.DefaultKmlFactory) KmlFactory(org.geotoolkit.data.kml.KmlFactory) Kml(org.geotoolkit.data.kml.model.Kml) Feature(org.opengis.feature.Feature) File(java.io.File) Test(org.junit.Test)

Example 5 with KmlWriter

use of org.geotoolkit.data.kml.xml.KmlWriter in project geotoolkit by Geomatys.

the class TrackTest method trackWriteTest.

@Test
public void trackWriteTest() throws KmlException, IOException, XMLStreamException, ParserConfigurationException, SAXException, URISyntaxException {
    final GxFactory gxFactory = DefaultGxFactory.getInstance();
    final KmlFactory kmlFactory = DefaultKmlFactory.getInstance();
    final ISODateParser du = new ISODateParser();
    final Calendar when0 = (Calendar) du.getCalendar("2010-05-28T02:02:09Z").clone();
    final Calendar when1 = (Calendar) du.getCalendar("2010-05-28T02:02:35Z").clone();
    final Coordinate coordinate0 = gxFactory.createCoordinate("-122.207881 37.371915 156.0");
    final Coordinate coordinate1 = kmlFactory.createCoordinate(-122.205712, 37.373288, 152.0);
    final CoordinateSequence coordinates = kmlFactory.createCoordinates(Arrays.asList(coordinate0, coordinate1));
    final Angles angles0 = gxFactory.createAngles(45.54676, 66.2342, 77);
    final Angles angles1 = gxFactory.createAngles();
    angles1.setHeading(46.54676);
    angles1.setTilt(67.2342);
    angles1.setRoll(78);
    final Track track = gxFactory.createTrack();
    track.setCoord(coordinates);
    track.setWhens(Arrays.asList(when0, when1));
    track.setAngles(Arrays.asList(angles0, angles1));
    final Feature placemark = kmlFactory.createPlacemark();
    placemark.setPropertyValue(KmlConstants.TAG_GEOMETRY, track);
    final Feature folder = kmlFactory.createFolder();
    folder.setPropertyValue(KmlConstants.TAG_FEATURES, placemark);
    final Kml kml = kmlFactory.createKml(null, folder, null, null);
    kml.addExtensionUri(GxConstants.URI_GX, "gx");
    final File temp = File.createTempFile("testTrack", ".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 : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) KmlWriter(org.geotoolkit.data.kml.xml.KmlWriter) Calendar(java.util.Calendar) GxWriter(org.geotoolkit.data.gx.xml.GxWriter) Angles(org.geotoolkit.data.gx.model.Angles) KmlFactory(org.geotoolkit.data.kml.KmlFactory) DefaultKmlFactory(org.geotoolkit.data.kml.DefaultKmlFactory) Kml(org.geotoolkit.data.kml.model.Kml) Feature(org.opengis.feature.Feature) ISODateParser(org.geotoolkit.temporal.object.ISODateParser) Coordinate(org.locationtech.jts.geom.Coordinate) File(java.io.File) Track(org.geotoolkit.data.gx.model.Track) Test(org.junit.Test)

Aggregations

Kml (org.geotoolkit.data.kml.model.Kml)52 KmlWriter (org.geotoolkit.data.kml.xml.KmlWriter)52 File (java.io.File)51 Test (org.junit.Test)51 Feature (org.opengis.feature.Feature)50 CoordinateSequence (org.locationtech.jts.geom.CoordinateSequence)23 Coordinate (org.locationtech.jts.geom.Coordinate)22 URI (java.net.URI)17 GxWriter (org.geotoolkit.data.gx.xml.GxWriter)14 IdAttributes (org.geotoolkit.data.kml.model.IdAttributes)14 DefaultKmlFactory (org.geotoolkit.data.kml.DefaultKmlFactory)13 KmlFactory (org.geotoolkit.data.kml.KmlFactory)13 Point (org.geotoolkit.data.kml.model.Point)13 Color (java.awt.Color)10 Style (org.geotoolkit.data.kml.model.Style)9 Link (org.geotoolkit.data.kml.model.Link)8 PlayList (org.geotoolkit.data.gx.model.PlayList)7 Update (org.geotoolkit.data.kml.model.Update)7 NetworkLinkControl (org.geotoolkit.data.kml.model.NetworkLinkControl)6 Calendar (java.util.Calendar)5