Ejemplo n.º 1
0
  public void testParsePlacemarkPoint() {
    String xmlBody =
        "<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\r\n"
            + ""
            + "					<Placemark>\r\n"
            + "					<name>PunktReception</name>\r\n"
            + "					<LookAt>\r\n"
            + "						<longitude>15.00000033315315</longitude>\r\n"
            + "						<latitude>61.99999830712358</latitude>\r\n"
            + "						<altitude>0</altitude>\r\n"
            + "						<heading>2.941567373323467e-007</heading>\r\n"
            + "						<tilt>0</tilt>\r\n"
            + "						<range>11003036.41038311</range>\r\n"
            + "						<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>\r\n"
            + "					</LookAt>\r\n"
            + "					<styleUrl>#m_ylw-pushpin</styleUrl>\r\n"
            + "					<Point>\r\n"
            + "						<coordinates>15.00000033315315,61.99999830712357,0</coordinates>\r\n"
            + "					</Point>\r\n"
            + "				</Placemark>\r\n"
            + "";
    KMLparser kmlParser = new KMLparser(true);

    try {
      parser.setInput(new StringReader(xmlBody));
      int eventType = parser.getEventType();
      while (eventType != XmlPullParser.START_TAG) {
        eventType = parser.next();
      }
      assertTrue("kml".equalsIgnoreCase(parser.getName()));
      eventType = parser.next();
      while (eventType != XmlPullParser.START_TAG) {
        eventType = parser.next();
      }
      assertTrue("getName() = " + parser.getName(), "Placemark".equalsIgnoreCase(parser.getName()));
      eventType = parser.next();
      Placemark pm = kmlParser.parsePlacemark(parser);
      assertNotNull(pm);
      assertTrue("PunktReception".equals(pm.getName()));
      Iterator<GeoPoint> e = pm.getCoords();
      assertTrue(e.hasNext());
      GeoPoint c = e.next();
      assertNotNull(c);
      assertTrue(Math.abs(c.getLatitudeE6() - 62 * 1E6) < 1E5);
      assertTrue((c.getLongitudeE6() - 15 * 1E6) < 1E5);
      assertFalse(e.hasNext());

    } catch (Exception e) {
      fail();
    }
  }
Ejemplo n.º 2
0
  public void testParsePlacemarkPolygon() {
    String xmlBody =
        "<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\" xmlns:kml=\"http://www.opengis.net/kml/2.2\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\r\n"
            + ""
            + "				<Placemark>\r\n"
            + "					<name>Parking</name>\r\n"
            + "					<description>Parking for employees</description>\r\n"
            + "					<styleUrl>#m_ylw-pushpin01</styleUrl>\r\n"
            + "					<Polygon>\r\n"
            + "						<tessellate>1</tessellate>\r\n"
            + "						<outerBoundaryIs>\r\n"
            + "							<LinearRing>\r\n"
            + "								<coordinates>\r\n"
            + "									15.55440546390407,58.3986574712261,0 15.55447317550318,58.39851378860297,0 15.5549053856946,58.3985742159012,0 15.55484182192279,58.39871652764229,0 15.55440546390407,58.3986574712261,0 \r\n"
            + "								</coordinates>\r\n"
            + "							</LinearRing>\r\n"
            + "						</outerBoundaryIs>\r\n"
            + "					</Polygon>\r\n"
            + "				</Placemark>\r\n"
            + "";
    KMLparser kmlParser = new KMLparser(true);

    try {
      parser.setInput(new StringReader(xmlBody));
      int eventType = parser.getEventType();
      while (eventType != XmlPullParser.START_TAG) {
        eventType = parser.next();
      }
      assertTrue("kml".equalsIgnoreCase(parser.getName()));
      eventType = parser.next();
      while (eventType != XmlPullParser.START_TAG) {
        eventType = parser.next();
      }
      assertTrue("getName() = " + parser.getName(), "Placemark".equalsIgnoreCase(parser.getName()));
      eventType = parser.next();
      Placemark pm = kmlParser.parsePlacemark(parser);
      assertNotNull(pm);
      assertTrue("Parking".equals(pm.getName()));
      assertTrue("Parking for employees".equals(pm.getInfo()));
      Iterator<GeoPoint> e = pm.getCoords();
      assertTrue(e.hasNext());
      GeoPoint c = e.next();
      assertNotNull(c);
      Log.e("Polygon", "lat=" + c.getLatitudeE6() + " const=" + 1555 * 1E4 + " diff=" + 1E5);
      assertTrue(Math.abs(c.getLatitudeE6() - 5840 * 1E4) < 1E5);
      assertTrue(Math.abs(c.getLongitudeE6() - 1555 * 1E4) < 1E5);
      assertTrue(e.hasNext());
      c = e.next();
      assertNotNull(c);
      assertTrue(Math.abs(c.getLatitudeE6() - 58399 * 1E3) < 1E5);
      assertTrue(Math.abs(c.getLongitudeE6() - 1555 * 1E4) < 1E5);
      assertTrue(e.hasNext());
      assertNotNull(e.next());
      assertTrue(e.hasNext());
      assertNotNull(e.next());
      assertTrue(e.hasNext());
      assertNotNull(e.next());
      assertFalse(e.hasNext());
    } catch (Exception e) {
      fail();
    }
  }