コード例 #1
0
ファイル: KMLparserTest.java プロジェクト: nilaz/Placefinder
  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();
    }
  }
コード例 #2
0
ファイル: KMLparserTest.java プロジェクト: nilaz/Placefinder
  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();
    }
  }
コード例 #3
0
ファイル: KMLparserTest.java プロジェクト: nilaz/Placefinder
  public void testParsePlacemarkerType() {
    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"
            + "			<Folder>\r\n"
            + "				<name>Parkering</name>\r\n"
            + "				<open>1</open>\r\n"
            + "				<Style>\r\n"
            + "					<ListStyle>\r\n"
            + "						<listItemType>check</listItemType>\r\n"
            + "						<bgColor>00ffffff</bgColor>\r\n"
            + "						<maxSnippetLines>2</maxSnippetLines>\r\n"
            + "					</ListStyle>\r\n"
            + "				</Style>\r\n"
            + "				<Placemark>\r\n"
            + "					<name>Parking1</name>\r\n"
            + "					<description>Enkel gästparkering</description>\r\n"
            + "					<styleUrl>#m_ylw-pushpin00</styleUrl>\r\n"
            + "					<Polygon>\r\n"
            + "						<tessellate>1</tessellate>\r\n"
            + "						<outerBoundaryIs>\r\n"
            + "							<LinearRing>\r\n"
            + "								<coordinates>\r\n"
            + "									15.55596143314125,58.39746581469188,0 15.5553913538694,58.39856164094756,0 15.55530072203812,58.39855030647441,0 15.5558711203315,58.39744114210799,0 15.55596143314125,58.39746581469188,0 \r\n"
            + "								</coordinates>\r\n"
            + "							</LinearRing>\r\n"
            + "						</outerBoundaryIs>\r\n"
            + "					</Polygon>\r\n"
            + "				</Placemark>\r\n"
            + "				<Placemark>\r\n"
            + "					<name>Parking2</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.55907486318708,58.39770553685341,0 15.55873061159417,58.39759161098356,0 15.55965179836237,58.3969299945208,0 15.55997543061963,58.39705193711266,0 15.55907486318708,58.39770553685341,0 \r\n"
            + "								</coordinates>\r\n"
            + "							</LinearRing>\r\n"
            + "						</outerBoundaryIs>\r\n"
            + "					</Polygon>\r\n"
            + "				</Placemark>\r\n"
            + "               </Folder>"
            + "";
    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(), "Folder".equalsIgnoreCase(parser.getName()));
      eventType = parser.next();
      PlacemarkerType pmt = kmlParser.parsePlacemarkerType(parser);
      assertNotNull(pmt);
      assertTrue("Parkering".equals(pmt.getName()));
      Iterator<Placemark> e = pmt.getPlacemarks();
      assertTrue(e.hasNext());
      Placemark pm = e.next();
      assertNotNull(pm);
      assertTrue("Parking1".equals(pm.getName()));
      assertTrue(e.hasNext());
      pm = e.next();
      assertNotNull(pm);
      assertTrue("Parking2".equals(pm.getName()));
      assertFalse(e.hasNext());
    } catch (Exception e) {
      fail();
    }
  }