Search in sources :

Example 1 with Angles

use of org.geotoolkit.data.gx.model.Angles in project geotoolkit by Geomatys.

the class GxReader method readTrack.

/**
 * @return
 * @throws XMLStreamException
 * @throws KmlException
 * @throws URISyntaxException
 */
public Track readTrack() throws XMLStreamException, KmlException, URISyntaxException {
    AltitudeMode altitudeMode = DEF_ALTITUDE_MODE;
    List<Calendar> whens = new ArrayList<Calendar>();
    List<Coordinate> coordinates = new ArrayList<Coordinate>();
    List<Angles> anglesList = new ArrayList<Angles>();
    Model model = null;
    ExtendedData extendedData = null;
    boucle: while (reader.hasNext()) {
        switch(reader.next()) {
            case XMLStreamConstants.START_ELEMENT:
                final String eName = reader.getLocalName();
                final String eUri = reader.getNamespaceURI();
                if (URI_GX.equals(eUri)) {
                    if (TAG_ALTITUDE_MODE.equals(eName)) {
                        altitudeMode = this.readAltitudeMode();
                    } else if (TAG_COORD.equals(eName)) {
                        coordinates.add(this.readCoord());
                    } else if (TAG_ANGLES.equals(eName)) {
                        anglesList.add(this.readAngles());
                    }
                } else if (this.kmlReader.getVersionUri().equals(eUri)) {
                    if (KmlConstants.TAG_ALTITUDE_MODE.equals(eName)) {
                        altitudeMode = kmlReader.readAltitudeMode();
                    } else if (KmlConstants.TAG_WHEN.equals(eName)) {
                        whens.add(kmlReader.readCalendar());
                    } else if (KmlConstants.TAG_MODEL.equals(eName)) {
                        model = kmlReader.readModel();
                    } else if (KmlConstants.TAG_EXTENDED_DATA.equals(eName)) {
                        extendedData = kmlReader.readExtendedData();
                    }
                }
                break;
            case XMLStreamConstants.END_ELEMENT:
                if (TAG_TRACK.equals(reader.getLocalName()) && URI_GX.contains(reader.getNamespaceURI())) {
                    break boucle;
                }
                break;
        }
    }
    CoordinateSequence coord = KML_FACTORY.createCoordinates(coordinates);
    return GX_FACTORY.createTrack(altitudeMode, whens, coord, anglesList, model, extendedData);
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) ExtendedData(org.geotoolkit.data.kml.model.ExtendedData) Coordinate(org.locationtech.jts.geom.Coordinate) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Model(org.geotoolkit.data.kml.model.Model) Angles(org.geotoolkit.data.gx.model.Angles) EnumAltitudeMode(org.geotoolkit.data.gx.model.EnumAltitudeMode) AltitudeMode(org.geotoolkit.data.kml.model.AltitudeMode)

Example 2 with Angles

use of org.geotoolkit.data.gx.model.Angles in project geotoolkit by Geomatys.

the class GxWriter method writeTrack.

public void writeTrack(Track track) throws XMLStreamException, KmlException {
    writer.writeStartElement(URI_GX, TAG_TRACK);
    kmlWriter.writeCommonAbstractGeometry(track);
    kmlWriter.writeAltitudeMode(track.getAltitudeMode());
    for (Calendar when : track.getWhens()) {
        kmlWriter.writeWhen(when);
    }
    if (track.getCoord() != null) {
        for (Coordinate coord : track.getCoord().toCoordinateArray()) {
            writeCoord(coord);
        }
    }
    for (Angles angles : track.getAngles()) {
        writeAngles(angles);
    }
    if (track.getModel() != null) {
        kmlWriter.writeModel(track.getModel());
    }
    kmlWriter.writeExtendedData(track.getExtendedData());
    writer.writeEndElement();
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) Calendar(java.util.Calendar) Angles(org.geotoolkit.data.gx.model.Angles)

Example 3 with Angles

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

Example 4 with Angles

use of org.geotoolkit.data.gx.model.Angles in project geotoolkit by Geomatys.

the class MultiTrackTest method multiTrackReadTest.

@Test
public void multiTrackReadTest() 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 MultiTrack multiTrack = (MultiTrack) placemark.getPropertyValue(KmlConstants.TAG_GEOMETRY);
    assertEquals(EnumAltitudeMode.CLAMP_TO_SEA_FLOOR, multiTrack.getAltitudeMode());
    assertTrue(multiTrack.getInterpolate());
    assertEquals(2, multiTrack.getTracks().size());
    final Track track0 = multiTrack.getTracks().get(0);
    assertEquals(1, track0.getWhens().size());
    assertEquals(1, track0.getCoord().size());
    assertEquals(1, track0.getAngles().size());
    String when0 = "2010-05-28T02:02:09Z";
    ISODateParser du = new ISODateParser();
    Calendar cal = du.getCalendar(when0);
    assertEquals(cal, track0.getWhens().get(0));
    CoordinateSequence coordinates0 = track0.getCoord();
    Coordinate coordinate0 = coordinates0.getCoordinate(0);
    assertEquals(-122.207881, coordinate0.x, DELTA);
    assertEquals(37.371915, coordinate0.y, DELTA);
    assertEquals(156, coordinate0.z, DELTA);
    Angles angles0 = track0.getAngles().get(0);
    assertEquals(45.54676, angles0.getHeading(), DELTA);
    assertEquals(66.2342, angles0.getTilt(), DELTA);
    assertEquals(77, angles0.getRoll(), DELTA);
    final Track track1 = multiTrack.getTracks().get(1);
    assertEquals(1, track1.getWhens().size());
    assertEquals(1, track1.getCoord().size());
    assertEquals(1, track1.getAngles().size());
    String when1 = "2010-05-28T02:02:35Z";
    cal = du.getCalendar(when1);
    assertEquals(cal, track1.getWhens().get(0));
    CoordinateSequence coordinates1 = track1.getCoord();
    Coordinate coordinate1 = coordinates1.getCoordinate(0);
    assertEquals(-122.205712, coordinate1.x, DELTA);
    assertEquals(37.373288, coordinate1.y, DELTA);
    assertEquals(152, coordinate1.z, DELTA);
    Angles angles1 = track1.getAngles().get(0);
    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) MultiTrack(org.geotoolkit.data.gx.model.MultiTrack) Calendar(java.util.Calendar) Angles(org.geotoolkit.data.gx.model.Angles) Kml(org.geotoolkit.data.kml.model.Kml) Feature(org.opengis.feature.Feature) ISODateParser(org.geotoolkit.temporal.object.ISODateParser) Coordinate(org.locationtech.jts.geom.Coordinate) KmlReader(org.geotoolkit.data.kml.xml.KmlReader) GxReader(org.geotoolkit.data.gx.xml.GxReader) File(java.io.File) Track(org.geotoolkit.data.gx.model.Track) MultiTrack(org.geotoolkit.data.gx.model.MultiTrack) Test(org.junit.Test)

Example 5 with Angles

use of org.geotoolkit.data.gx.model.Angles in project geotoolkit by Geomatys.

the class MultiTrackTest method multiTrackWriteTest.

@Test
public void multiTrackWriteTest() 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 coordinates0 = kmlFactory.createCoordinates(Arrays.asList(coordinate0));
    final CoordinateSequence coordinates1 = kmlFactory.createCoordinates(Arrays.asList(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 track0 = gxFactory.createTrack();
    track0.setCoord(coordinates0);
    track0.setWhens(Arrays.asList(when0));
    track0.setAngles(Arrays.asList(angles0));
    final Track track1 = gxFactory.createTrack();
    track1.setCoord(coordinates1);
    track1.setWhens(Arrays.asList(when1));
    track1.setAngles(Arrays.asList(angles1));
    final MultiTrack multiTrack = gxFactory.createMultiTrack();
    multiTrack.setAltitudeMode(EnumAltitudeMode.CLAMP_TO_SEA_FLOOR);
    multiTrack.setInterpolate(true);
    multiTrack.setTracks(Arrays.asList(track0, track1));
    final Feature placemark = kmlFactory.createPlacemark();
    placemark.setPropertyValue(KmlConstants.TAG_GEOMETRY, multiTrack);
    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("testMultiTrack", ".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) MultiTrack(org.geotoolkit.data.gx.model.MultiTrack) 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) MultiTrack(org.geotoolkit.data.gx.model.MultiTrack) Test(org.junit.Test)

Aggregations

Calendar (java.util.Calendar)6 Angles (org.geotoolkit.data.gx.model.Angles)6 Coordinate (org.locationtech.jts.geom.Coordinate)6 CoordinateSequence (org.locationtech.jts.geom.CoordinateSequence)5 File (java.io.File)4 Track (org.geotoolkit.data.gx.model.Track)4 Kml (org.geotoolkit.data.kml.model.Kml)4 ISODateParser (org.geotoolkit.temporal.object.ISODateParser)4 Test (org.junit.Test)4 Feature (org.opengis.feature.Feature)4 MultiTrack (org.geotoolkit.data.gx.model.MultiTrack)2 GxReader (org.geotoolkit.data.gx.xml.GxReader)2 GxWriter (org.geotoolkit.data.gx.xml.GxWriter)2 DefaultKmlFactory (org.geotoolkit.data.kml.DefaultKmlFactory)2 KmlFactory (org.geotoolkit.data.kml.KmlFactory)2 KmlReader (org.geotoolkit.data.kml.xml.KmlReader)2 KmlWriter (org.geotoolkit.data.kml.xml.KmlWriter)2 ArrayList (java.util.ArrayList)1 EnumAltitudeMode (org.geotoolkit.data.gx.model.EnumAltitudeMode)1 AltitudeMode (org.geotoolkit.data.kml.model.AltitudeMode)1