コード例 #1
0
  @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);
  }
コード例 #2
0
  @Test
  public void altitudeModeReadTest()
      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 placemark = kmlObjects.getAbstractFeature();
    assertEquals(KmlModelConstants.TYPE_PLACEMARK, placemark.getType());
    assertEquals("gx:altitudeMode Example", placemark.getPropertyValue(KmlConstants.TAG_NAME));
    final LookAt lookAt = (LookAt) placemark.getPropertyValue(KmlConstants.TAG_VIEW);

    assertEquals(146.806, lookAt.getLongitude(), DELTA);
    assertEquals(12.219, lookAt.getLatitude(), DELTA);
    assertEquals(-60, lookAt.getHeading(), DELTA);
    assertEquals(70, lookAt.getTilt(), DELTA);
    assertEquals(6300, lookAt.getRange(), DELTA);
    assertEquals(EnumAltitudeMode.RELATIVE_TO_SEA_FLOOR, lookAt.getAltitudeMode());

    final LineString lineString =
        (LineString) placemark.getPropertyValue(KmlConstants.TAG_GEOMETRY);
    assertTrue(lineString.getExtrude());
    assertEquals(EnumAltitudeMode.RELATIVE_TO_SEA_FLOOR, lineString.getAltitudeMode());

    CoordinateSequence coordinates = lineString.getCoordinateSequence();
    assertEquals(5, coordinates.size());
    Coordinate coordinate0 = coordinates.getCoordinate(0);
    assertEquals(146.825, coordinate0.x, DELTA);
    assertEquals(12.233, coordinate0.y, DELTA);
    assertEquals(400.0, coordinate0.z, DELTA);

    Coordinate coordinate1 = coordinates.getCoordinate(1);
    assertEquals(146.820, coordinate1.x, DELTA);
    assertEquals(12.222, coordinate1.y, DELTA);
    assertEquals(400.0, coordinate1.z, DELTA);

    Coordinate coordinate2 = coordinates.getCoordinate(2);
    assertEquals(146.812, coordinate2.x, DELTA);
    assertEquals(12.212, coordinate2.y, DELTA);
    assertEquals(400.0, coordinate2.z, DELTA);

    Coordinate coordinate3 = coordinates.getCoordinate(3);
    assertEquals(146.796, coordinate3.x, DELTA);
    assertEquals(12.209, coordinate3.y, DELTA);
    assertEquals(400.0, coordinate3.z, DELTA);

    Coordinate coordinate4 = coordinates.getCoordinate(4);
    assertEquals(146.788, coordinate4.x, DELTA);
    assertEquals(12.205, coordinate4.y, DELTA);
    assertEquals(400.0, coordinate4.z, DELTA);
  }
コード例 #3
0
ファイル: PlacemarkTest.java プロジェクト: tjkr/geotoolkit
  @Test
  public void placemarkReadTest()
      throws IOException, XMLStreamException, KmlException, URISyntaxException {

    final KmlReader reader = new KmlReader();
    reader.setInput(new File(pathToTestFile));
    final Kml kmlObjects = reader.read();
    reader.dispose();

    final Feature placemark = kmlObjects.getAbstractFeature();
    assertTrue(placemark.getType().equals(KmlModelConstants.TYPE_PLACEMARK));
    assertEquals(
        "Google Earth - New Placemark",
        placemark.getProperty(KmlModelConstants.ATT_NAME.getName()).getValue());
    assertEquals(
        "Some Descriptive text.",
        placemark.getProperty(KmlModelConstants.ATT_DESCRIPTION.getName()).getValue());

    final AbstractView view =
        (AbstractView) placemark.getProperty(KmlModelConstants.ATT_VIEW.getName()).getValue();
    assertTrue(view instanceof LookAt);
    LookAt lookAt = (LookAt) view;
    assertEquals(-90.86879847669974, lookAt.getLongitude(), DELTA);
    assertEquals(48.25330383601299, lookAt.getLatitude(), DELTA);
    assertEquals(2.7, lookAt.getHeading(), DELTA);
    assertEquals(8.3, lookAt.getTilt(), DELTA);
    assertEquals(440.8, lookAt.getRange(), DELTA);

    final AbstractGeometry geometry =
        (AbstractGeometry)
            placemark.getProperty(KmlModelConstants.ATT_PLACEMARK_GEOMETRY.getName()).getValue();
    assertTrue(geometry instanceof Point);
    Point point = (Point) geometry;
    final CoordinateSequence coordinates = point.getCoordinateSequence();
    assertEquals(1, coordinates.size());
    Coordinate coordinate = coordinates.getCoordinate(0);
    assertEquals(-90.86948943473118, coordinate.x, DELTA);
    assertEquals(48.25450093195546, coordinate.y, DELTA);
    assertEquals(0, coordinate.z, DELTA);
  }
コード例 #4
0
  @Test
  public void balloonStyleReadTest()
      throws IOException, XMLStreamException, URISyntaxException, KmlException {

    Iterator i;

    final KmlReader reader = new KmlReader();
    reader.setInput(new File(pathToTestFile));
    final Kml kmlObjects = reader.read();
    reader.dispose();

    final Feature document = kmlObjects.getAbstractFeature();
    assertTrue(document.getType().equals(KmlModelConstants.TYPE_DOCUMENT));
    assertEquals(
        "BalloonStyle.kml", document.getProperty(KmlModelConstants.ATT_NAME.getName()).getValue());
    assertTrue((Boolean) document.getProperty(KmlModelConstants.ATT_OPEN.getName()).getValue());
    assertEquals(1, document.getProperties(KmlModelConstants.ATT_STYLE_SELECTOR.getName()).size());
    i = document.getProperties(KmlModelConstants.ATT_STYLE_SELECTOR.getName()).iterator();
    if (i.hasNext()) {
      Object styleSelector = ((Property) i.next()).getValue();
      assertTrue(styleSelector instanceof Style);
      final Style style = (Style) styleSelector;
      assertEquals("exampleBalloonStyle", style.getIdAttributes().getId());
      final BalloonStyle balloonStyle = style.getBalloonStyle();
      assertEquals(new Color(187, 255, 255, 255), balloonStyle.getBgColor());
      final Cdata text =
          new DefaultCdata(
              "\n      <b><font color=\"#CC0000\" size=\"+3\">$[name]</font></b>\n"
                  + "      <br/><br/>\n"
                  + "      <font face=\"Courier\">$[description]</font>\n"
                  + "      <br/><br/>\n"
                  + "      Extra text that will appear in the description balloon\n"
                  + "      <br/><br/>\n"
                  + "      $[geDirections]\n"
                  + "      ");
      assertEquals(text, balloonStyle.getText());
    }

    assertEquals(
        1, document.getProperties(KmlModelConstants.ATT_DOCUMENT_FEATURES.getName()).size());
    i = document.getProperties(KmlModelConstants.ATT_DOCUMENT_FEATURES.getName()).iterator();
    if (i.hasNext()) {
      final Object object = i.next();
      assertTrue(object instanceof Feature);
      Feature placemark = (Feature) object;
      assertTrue(placemark.getType().equals(KmlModelConstants.TYPE_PLACEMARK));
      assertEquals(
          "BalloonStyle", placemark.getProperty(KmlModelConstants.ATT_NAME.getName()).getValue());
      assertEquals(
          "An example of BalloonStyle",
          placemark.getProperty(KmlModelConstants.ATT_DESCRIPTION.getName()).getValue());
      assertEquals(
          new URI("#exampleBalloonStyle"),
          placemark.getProperty(KmlModelConstants.ATT_STYLE_URL.getName()).getValue());
      assertTrue(
          placemark.getProperty(KmlModelConstants.ATT_PLACEMARK_GEOMETRY.getName()).getValue()
              instanceof Point);
      final Point point =
          (Point)
              placemark.getProperty(KmlModelConstants.ATT_PLACEMARK_GEOMETRY.getName()).getValue();
      final CoordinateSequence coordinates = point.getCoordinateSequence();
      assertEquals(1, coordinates.size());
      final Coordinate coordinate = coordinates.getCoordinate(0);
      assertEquals(-122.370533, coordinate.x, DELTA);
      assertEquals(37.823842, coordinate.y, DELTA);
      assertEquals(0, coordinate.z, DELTA);
    }
  }
コード例 #5
0
  @Test
  public void lineStringReadTest()
      throws IOException, XMLStreamException, KmlException, URISyntaxException {

    final KmlReader reader = new KmlReader();
    reader.setInput(new File(pathToTestFile));
    final Kml kmlObjects = reader.read();
    reader.dispose();

    final Feature document = kmlObjects.getAbstractFeature();
    assertTrue(document.getType().equals(KmlModelConstants.TYPE_DOCUMENT));

    assertEquals(
        "LineString.kml", document.getProperty(KmlModelConstants.ATT_NAME.getName()).getValue());
    assertTrue((Boolean) document.getProperty(KmlModelConstants.ATT_OPEN.getName()).getValue());

    assertTrue(
        document.getProperty(KmlModelConstants.ATT_VIEW.getName()).getValue() instanceof LookAt);
    final LookAt lookAt =
        (LookAt) document.getProperty(KmlModelConstants.ATT_VIEW.getName()).getValue();

    assertEquals(-122.36415, lookAt.getLongitude(), DELTA);
    assertEquals(37.824553, lookAt.getLatitude(), DELTA);
    assertEquals(1, lookAt.getAltitude(), DELTA);
    assertEquals(2, lookAt.getHeading(), DELTA);
    assertEquals(50, lookAt.getTilt(), DELTA);
    assertEquals(150, lookAt.getRange(), DELTA);

    assertEquals(
        2, document.getProperties(KmlModelConstants.ATT_DOCUMENT_FEATURES.getName()).size());

    Iterator i =
        document.getProperties(KmlModelConstants.ATT_DOCUMENT_FEATURES.getName()).iterator();

    if (i.hasNext()) {
      Object object = i.next();
      assertTrue(object instanceof Feature);
      Feature placemark0 = (Feature) object;
      assertTrue(placemark0.getType().equals(KmlModelConstants.TYPE_PLACEMARK));

      assertEquals(
          "unextruded", placemark0.getProperty(KmlModelConstants.ATT_NAME.getName()).getValue());
      assertTrue(
          placemark0.getProperty(KmlModelConstants.ATT_PLACEMARK_GEOMETRY.getName()).getValue()
              instanceof LineString);
      final LineString lineString0 =
          (LineString)
              placemark0.getProperty(KmlModelConstants.ATT_PLACEMARK_GEOMETRY.getName()).getValue();
      assertTrue(lineString0.getExtrude());
      assertTrue(lineString0.getTessellate());

      final CoordinateSequence coordinates0 = lineString0.getCoordinateSequence();
      assertEquals(2, coordinates0.size());

      final Coordinate coordinate00 = coordinates0.getCoordinate(0);
      assertEquals(-122.364383, coordinate00.x, DELTA);
      assertEquals(37.824664, coordinate00.y, DELTA);
      assertEquals(0, coordinate00.z, DELTA);

      final Coordinate coordinate01 = coordinates0.getCoordinate(1);
      assertEquals(-122.364152, coordinate01.x, DELTA);
      assertEquals(37.824322, coordinate01.y, DELTA);
      assertEquals(0, coordinate01.z, DELTA);
    }

    if (i.hasNext()) {
      Object object = i.next();
      assertTrue(object instanceof Feature);
      Feature placemark1 = (Feature) object;
      assertTrue(placemark1.getType().equals(KmlModelConstants.TYPE_PLACEMARK));

      assertEquals(
          "extruded", placemark1.getProperty(KmlModelConstants.ATT_NAME.getName()).getValue());
      assertTrue(
          placemark1.getProperty(KmlModelConstants.ATT_PLACEMARK_GEOMETRY.getName()).getValue()
              instanceof LineString);
      final LineString lineString1 =
          (LineString)
              placemark1.getProperty(KmlModelConstants.ATT_PLACEMARK_GEOMETRY.getName()).getValue();
      assertTrue(lineString1.getExtrude());
      assertTrue(lineString1.getTessellate());
      assertEquals(EnumAltitudeMode.RELATIVE_TO_GROUND, lineString1.getAltitudeMode());

      final CoordinateSequence coordinates1 = lineString1.getCoordinateSequence();
      assertEquals(2, coordinates1.size());

      final Coordinate coordinate10 = coordinates1.getCoordinate(0);
      assertEquals(-122.364167, coordinate10.x, DELTA);
      assertEquals(37.824787, coordinate10.y, DELTA);
      assertEquals(50, coordinate10.z, DELTA);

      final Coordinate coordinate11 = coordinates1.getCoordinate(1);
      assertEquals(-122.363917, coordinate11.x, DELTA);
      assertEquals(37.824423, coordinate11.y, DELTA);
      assertEquals(50, coordinate11.z, DELTA);
    }
  }