Esempio 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();
    }
  }
Esempio 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();
    }
  }
Esempio n. 3
0
  public void testParseCompany() {
    String xmlBody =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
            + "<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"
            + "<Document>\r\n"
            + "	<name>ericsson.kml</name>\r\n"
            + "	<StyleMap id=\"m_ylw-pushpin1\">\r\n"
            + "		<Pair>\r\n"
            + "			<key>normal</key>\r\n"
            + "			<styleUrl>#s_ylw-pushpin00</styleUrl>\r\n"
            + "		</Pair>\r\n"
            + "		<Pair>\r\n"
            + "			<key>highlight</key>\r\n"
            + "			<styleUrl>#s_ylw-pushpin_hl0</styleUrl>\r\n"
            + "		</Pair>\r\n"
            + "	</StyleMap>\r\n"
            + "	<Style id=\"sn_ylw-pushpin\">\r\n"
            + "		<IconStyle>\r\n"
            + "			<scale>1.1</scale>\r\n"
            + "			<Icon>\r\n"
            + "				<href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>\r\n"
            + "			</Icon>\r\n"
            + "			<hotSpot x=\"20\" y=\"2\" xunits=\"pixels\" yunits=\"pixels\"/>\r\n"
            + "		</IconStyle>\r\n"
            + "		<PolyStyle>\r\n"
            + "			<color>e37f00ff</color>\r\n"
            + "		</PolyStyle>\r\n"
            + "	</Style>\r\n"
            + "	<Folder>\r\n"
            + "		<name>Ericsson</name>\r\n"
            + "		<open>1</open>\r\n"
            + "		<Folder>\r\n"
            + "			<name>Mjardevi</name>\r\n"
            + "			<open>1</open>\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>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.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"
            + "				<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"
            + "			</Folder>\r\n"
            + "			<Folder>\r\n"
            + "				<name>Reception</name>\r\n"
            + "				<open>1</open>\r\n"
            + "				<Placemark>\r\n"
            + "					<name>Reception 1</name>\r\n"
            + "					<styleUrl>#msn_ylw-pushpin</styleUrl>\r\n"
            + "					<Polygon>\r\n"
            + "						<tessellate>1</tessellate>\r\n"
            + "						<outerBoundaryIs>\r\n"
            + "							<LinearRing>\r\n"
            + "								<coordinates>\r\n"
            + "									15.55580674354399,58.39702770164073,0 15.55605831057186,58.39686290566417,0 15.55622568005853,58.3969220218273,0 15.55599962275058,58.39708869161678,0 15.55580674354399,58.39702770164073,0 \r\n"
            + "								</coordinates>\r\n"
            + "							</LinearRing>\r\n"
            + "						</outerBoundaryIs>\r\n"
            + "					</Polygon>\r\n"
            + "				</Placemark>\r\n"
            + "			</Folder>\r\n"
            + "		</Folder>\r\n"
            + "		<Folder>\r\n"
            + "			<name>Kista</name>\r\n"
            + "			<open>1</open>\r\n"
            + "			<Folder>\r\n"
            + "				<name>Parkering</name>\r\n"
            + "				<open>1</open>\r\n"
            + "				<Placemark>\r\n"
            + "					<name>Parking for employees</name>\r\n"
            + "					<styleUrl>#m_ylw-pushpin0</styleUrl>\r\n"
            + "					<Polygon>\r\n"
            + "						<tessellate>1</tessellate>\r\n"
            + "						<outerBoundaryIs>\r\n"
            + "							<LinearRing>\r\n"
            + "								<coordinates>\r\n"
            + "									17.95652237297804,59.4034859346524,0 17.95734879911315,59.40278073205812,0 17.95603699657349,59.40233075744884,0 17.95668843982264,59.40189566245388,0 17.95904003622361,59.40278343624011,0 17.95761272428177,59.40388537542285,0 17.95652237297804,59.4034859346524,0 \r\n"
            + "								</coordinates>\r\n"
            + "							</LinearRing>\r\n"
            + "						</outerBoundaryIs>\r\n"
            + "					</Polygon>\r\n"
            + "				</Placemark>\r\n"
            + "			</Folder>\r\n"
            + "			<Folder>\r\n"
            + "				<name>Houses</name>\r\n"
            + "				<open>1</open>\r\n"
            + "				<Placemark>\r\n"
            + "					<name>House 5</name>\r\n"
            + "					<styleUrl>#m_ylw-pushpin0</styleUrl>\r\n"
            + "					<Polygon>\r\n"
            + "						<tessellate>1</tessellate>\r\n"
            + "						<outerBoundaryIs>\r\n"
            + "							<LinearRing>\r\n"
            + "								<coordinates>\r\n"
            + "									17.95132364356021,59.40393745619702,0 17.95044751544161,59.4036551695751,0 17.9508780281932,59.40331676438417,0 17.95178689000125,59.4035903622625,0 17.95132364356021,59.40393745619702,0 \r\n"
            + "								</coordinates>\r\n"
            + "							</LinearRing>\r\n"
            + "						</outerBoundaryIs>\r\n"
            + "					</Polygon>\r\n"
            + "				</Placemark>\r\n"
            + "			</Folder>\r\n"
            + "		</Folder>\r\n"
            + "	</Folder>\r\n"
            + "</Document>\r\n"
            + "</kml>\r\n"
            + "";
    KMLparser kmlParser = new KMLparser(true);

    try {
      parser.setInput(new StringReader(xmlBody));
      Vector<Company> cas = kmlParser.parseKML(parser);
      assertNotNull(cas);
      assertEquals(1, cas.size());
      Company c = cas.get(0);
      assertNotNull(c);
      assertTrue("Ericsson".equals(c.getName()));
      Iterator<CompanyArea> e = c.getCompanyAreas();
      assertTrue(e.hasNext());
      CompanyArea ca = e.next();
      assertNotNull(ca);
      assertTrue("Mjardevi".equals(ca.getName()));
      assertTrue(e.hasNext());
      ca = e.next();
      assertNotNull(ca);
      assertTrue("Kista".equals(ca.getName()));
    } catch (Exception e) {
      fail();
    }
  }
Esempio n. 4
0
  public void testParseCompanyArea() {
    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>Mjardevi</name>\r\n"
            + "			<open>1</open>\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>Gästparkering</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"
            + "			</Folder>\r\n"
            + "			<Folder>\r\n"
            + "				<name>Houses</name>\r\n"
            + "				<Placemark>\r\n"
            + "					<name>KB</name>\r\n"
            + "					<styleUrl>#m_ylw-pushpin1</styleUrl>\r\n"
            + "					<Polygon>\r\n"
            + "						<tessellate>1</tessellate>\r\n"
            + "						<outerBoundaryIs>\r\n"
            + "							<LinearRing>\r\n"
            + "								<coordinates>\r\n"
            + "									15.55668214920198,58.39768692967193,0 15.556795061081,58.39761666339918,0 15.55671470722432,58.39758486460966,0 15.55679305101447,58.39754262601683,0 15.5566952877097,58.39752021347346,0 15.55685979988558,58.39739865154839,0 15.55692186407407,58.39740744522897,0 15.55717430140551,58.39727134236146,0 15.55736187612139,58.39734862387047,0 15.55682494482019,58.39774140457978,0 15.55668214920198,58.39768692967193,0 \r\n"
            + "								</coordinates>\r\n"
            + "							</LinearRing>\r\n"
            + "						</outerBoundaryIs>\r\n"
            + "					</Polygon>\r\n"
            + "				</Placemark>\r\n"
            + "			</Folder>\r\n"
            + "		</Folder>\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(), "Folder".equalsIgnoreCase(parser.getName()));
      eventType = parser.next();
      CompanyArea ca = kmlParser.parseCompanyArea(parser);
      assertNotNull(ca);
      assertTrue("Mjardevi".equals(ca.getName()));
      Iterator<PlacemarkerType> e = ca.getPlacemarkerTypes();
      assertTrue(e.hasNext());
      PlacemarkerType pmt = e.next();
      assertNotNull(pmt);
      assertTrue("Parkering".equals(pmt.getName()));
      assertTrue(e.hasNext());
      pmt = e.next();
      assertNotNull(pmt);
      assertTrue("Houses".equals(pmt.getName()));
      assertFalse(e.hasNext());
    } catch (Exception e) {
      fail();
    }
  }
Esempio n. 5
0
  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();
    }
  }