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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations