private static void SetPlacemarkData(XmlNode xmlElement, out KMLPlacemark placemark) { placemark = new KMLPlacemark(); foreach (XmlNode item in xmlElement.ChildNodes) { if (item.Name.Equals("name")) { placemark.Name = item.InnerText; placemark.Type = KMLPlacemark.TypeByName(placemark.Name); } //pins if (item.Name.Equals("Point")) { foreach (XmlNode child in item) { if (child.Name.Equals("coordinates")) { string val = child.InnerText; placemark.Longitude = Convert.ToDouble(val.Split(',')[0]); placemark.Latitude = Convert.ToDouble(val.Split(',')[1]); } } } //routes if (item.Name.Equals("LineString")) { placemark.RouteValues = new List <Vector2>(); string val = item.FirstChild.InnerText; //Remove last ',' and spaces val = val.Remove(item.FirstChild.InnerText.LastIndexOf(',')).Trim(); //Remove altitude values from array (,0 ) val = val.Replace("0 ", ""); //Split values by ',' string[] routeVals = val.Split(','); for (int i = 0; i < routeVals.Length; i += 2) { placemark.RouteValues.Add( new Vector2( Convert.ToSingle(routeVals[i]), Convert.ToSingle(routeVals[i + 1]) )); } } } }
public static List <KMLPlacemark> ReadKMLFile(string kmlPath) { List <KMLPlacemark> placemarks = new List <KMLPlacemark>(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(kmlPath); XmlNodeList placesmarks = xmlDoc.GetElementsByTagName("Placemark"); foreach (XmlNode item in placesmarks) { KMLPlacemark pl = new KMLPlacemark(); SetPlacemarkData(item, out pl); placemarks.Add(pl); //Debug.Log(pl.type + " | " + pl.name + " lat:" + pl.latitude + " long:" + pl.longitude); } return(placemarks); }
/** * Create an instance. * * @param tc the current {@link KMLTraversalContext}. * @param placemark the <i>Placemark</i> element containing the <i>Point</i>. * @param geom the {@link KMLPoint} geometry. * * @throws NullPointerException if the geometry is null. * @throws ArgumentException if the parent placemark or the traversal context is null. */ public KMLPointPlacemarkImpl(KMLTraversalContext tc, KMLPlacemark placemark, KMLAbstractGeometry geom) { super(((KMLPoint)geom).getCoordinates()); if (tc == null) { String msg = Logging.getMessage("nullValue.TraversalContextIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (placemark == null) { String msg = Logging.getMessage("nullValue.ParentIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } this.parent = placemark; KMLPoint point = (KMLPoint)geom; this.setAltitudeMode(WorldWind.CLAMP_TO_GROUND); // KML default if (point.isExtrude()) { this.setLineEnabled(true); } String altMode = point.getAltitudeMode(); if (!WWUtil.isEmpty(altMode)) { if ("clampToGround".Equals(altMode)) { this.setAltitudeMode(WorldWind.CLAMP_TO_GROUND); } else if ("relativeToGround".Equals(altMode)) { this.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND); } else if ("absolute".Equals(altMode)) { this.setAltitudeMode(WorldWind.ABSOLUTE); } } if (this.parent.getVisibility() != null) { this.setVisible(this.parent.getVisibility()); } if (placemark.getName() != null) { this.setLabelText(placemark.getName()); this.setValue(AVKey.DISPLAY_NAME, placemark.getName()); } String description = placemark.getDescription(); if (description != null) { this.setValue(AVKey.DESCRIPTION, description); } if (placemark.getSnippetText() != null) { this.setValue(AVKey.SHORT_DESCRIPTION, placemark.getSnippetText()); } this.setValue(AVKey.CONTEXT, this.parent); }
/** * Create an instance. * * @param tc the current {@link KMLTraversalContext}. * @param placemark the <i>Placemark</i> element containing the <i>LineString</i>. * @param geom the {@link SharpEarth.ogc.kml.KMLPolygon} geometry. * * @throws NullPointerException if the geometry is null. * @throws ArgumentException if the parent placemark or the traversal context is null. */ public KMLSurfacePolygonImpl(KMLTraversalContext tc, KMLPlacemark placemark, KMLAbstractGeometry geom) { if (tc == null) { String msg = Logging.getMessage("nullValue.TraversalContextIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (placemark == null) { String msg = Logging.getMessage("nullValue.ParentIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } this.parent = placemark; KMLPolygon polygon = (KMLPolygon)geom; // KMLPolygon's use linear interpolation between corners by definition. Configure the World Wind SurfacePolygon // to use the appropriate path type for linear interpolation in geographic coordinates. this.setPathType(AVKey.LINEAR); // Note: SurfacePolygon implies altitude mode "clampToGround", therefore KMLSurfacePolygonImpl ignores the // KMLPolygon's altitude mode property. KMLLinearRing outerBoundary = polygon.getOuterBoundary(); if (outerBoundary != null) { Position.PositionList coords = outerBoundary.getCoordinates(); if (coords != null && coords.list != null) { this.setOuterBoundary(outerBoundary.getCoordinates().list); } } Iterable <? extends KMLLinearRing> innerBoundaries = polygon.getInnerBoundaries(); if (innerBoundaries != null) { foreach (KMLLinearRing ring in innerBoundaries) { Position.PositionList coords = ring.getCoordinates(); if (coords != null && coords.list != null) { this.addInnerBoundary(ring.getCoordinates().list); } } } if (placemark.getName() != null) { this.setValue(AVKey.DISPLAY_NAME, placemark.getName()); } if (placemark.getDescription() != null) { this.setValue(AVKey.DESCRIPTION, placemark.getDescription()); } if (placemark.getSnippetText() != null) { this.setValue(AVKey.SHORT_DESCRIPTION, placemark.getSnippetText()); } this.setValue(AVKey.CONTEXT, this.parent); }
/** * Create an instance. * * @param tc the current {@link KMLTraversalContext}. * @param placemark the <i>Placemark</i> element containing the <i>LineString</i>. * @param geom the {@link SharpEarth.ogc.kml.KMLPolygon} geometry. * * @throws NullPointerException if the geometry is null. * @throws ArgumentException if the parent placemark or the traversal context is null. */ public KMLPolygonImpl(KMLTraversalContext tc, KMLPlacemark placemark, KMLAbstractGeometry geom) { if (tc == null) { String msg = Logging.getMessage("nullValue.TraversalContextIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (placemark == null) { String msg = Logging.getMessage("nullValue.ParentIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } this.parent = placemark; KMLPolygon polygon = (KMLPolygon)geom; this.setAltitudeMode(WorldWind.CLAMP_TO_GROUND); // KML default String altMode = polygon.getAltitudeMode(); if (!WWUtil.isEmpty(altMode)) { if ("relativeToGround".Equals(altMode)) { this.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND); } else if ("absolute".Equals(altMode)) { this.setAltitudeMode(WorldWind.ABSOLUTE); } } KMLLinearRing outerBoundary = polygon.getOuterBoundary(); if (outerBoundary != null) { Position.PositionList coords = outerBoundary.getCoordinates(); if (coords != null && coords.list != null) { this.setOuterBoundary(outerBoundary.getCoordinates().list); } } Iterable <? extends KMLLinearRing> innerBoundaries = polygon.getInnerBoundaries(); if (innerBoundaries != null) { foreach (KMLLinearRing ring in innerBoundaries) { Position.PositionList coords = ring.getCoordinates(); if (coords != null && coords.list != null) { this.addInnerBoundary(ring.getCoordinates().list); } } } if (placemark.getName() != null) { this.setValue(AVKey.DISPLAY_NAME, placemark.getName()); } if (placemark.getDescription() != null) { this.setValue(AVKey.DESCRIPTION, placemark.getDescription()); } if (placemark.getSnippetText() != null) { this.setValue(AVKey.SHORT_DESCRIPTION, placemark.getSnippetText()); } this.setValue(AVKey.CONTEXT, this.parent); }
/** * Create an instance. * * @param tc the current {@link KMLTraversalContext}. * @param placemark the <i>Placemark</i> element containing the <i>LineString</i>. * @param geom the {@link KMLLineString} geometry. * * @throws NullPointerException if the geometry is null. * @throws ArgumentException if the parent placemark or the traversal context is null. */ public KMLLineStringPlacemarkImpl(KMLTraversalContext tc, KMLPlacemark placemark, KMLAbstractGeometry geom) { super(((KMLLineString)geom).getCoordinates()); if (tc == null) { String msg = Logging.getMessage("nullValue.TraversalContextIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (placemark == null) { String msg = Logging.getMessage("nullValue.ParentIsNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } this.parent = placemark; KMLLineString lineString = (KMLLineString)geom; if (lineString.isExtrude()) { this.setExtrude(true); } if (lineString.getTessellate() != null && lineString.getTessellate()) { this.setFollowTerrain(true); } this.setAltitudeMode(WorldWind.CLAMP_TO_GROUND); // KML default String altMode = lineString.getAltitudeMode(); if (!WWUtil.isEmpty(altMode)) { if ("clampToGround".Equals(altMode)) { this.setAltitudeMode(WorldWind.CLAMP_TO_GROUND); } else if ("relativeToGround".Equals(altMode)) { this.setAltitudeMode(WorldWind.RELATIVE_TO_GROUND); } else if ("absolute".Equals(altMode)) { this.setAltitudeMode(WorldWind.ABSOLUTE); } } // If the path is clamped to the ground and terrain conforming, draw as a great circle. Otherwise draw // as linear segments. if (this.getAltitudeMode() == WorldWind.CLAMP_TO_GROUND && this.isFollowTerrain()) { this.setPathType(AVKey.GREAT_CIRCLE); } else { this.setPathType(AVKey.LINEAR); } if (placemark.getName() != null) { this.setValue(AVKey.DISPLAY_NAME, placemark.getName()); } if (placemark.getDescription() != null) { this.setValue(AVKey.DESCRIPTION, placemark.getDescription()); } if (placemark.getSnippetText() != null) { this.setValue(AVKey.SHORT_DESCRIPTION, placemark.getSnippetText()); } this.setValue(AVKey.CONTEXT, this.parent); }
private static RenderableObject Construct(String strRelativeDirectory, KMLObject oSource, World oWorld, GeographicBoundingBox oBounds, ProjectedVectorRenderer oPVR, Icons oIcons) { if (oSource is KMLContainer) { KMLContainer oCastSource = oSource as KMLContainer; KMLRenderableObjectList result = new KMLRenderableObjectList(oCastSource.Name); if (oPVR == null) { oPVR = new ProjectedVectorRenderer("Polygons and LineStrings", oWorld); result.Add(oPVR); } if (oIcons == null) { oIcons = new Icons("Icons"); result.Add(oIcons); } for (int count = 0; count < oCastSource.Count; count++) { if (oCastSource[count].Visibility == true) { RenderableObject oLayer = Construct(strRelativeDirectory, oCastSource[count], oWorld, oBounds, oPVR, oIcons); if (oLayer != null) { result.Add(oLayer); } } } return(result); } else if (oSource is KMLPlacemark) { KMLPlacemark oCastSource = oSource as KMLPlacemark; return(Construct(strRelativeDirectory, oCastSource.Geometry, oWorld, oBounds, oPVR, oIcons)); } else if (oSource is KMLMultiGeometry) { KMLMultiGeometry oCastSource = oSource as KMLMultiGeometry; KMLRenderableObjectList result = new KMLRenderableObjectList("MultiGeometry"); for (int count = 0; count < oCastSource.Count; count++) { RenderableObject oLayer = Construct(strRelativeDirectory, oCastSource[count], oWorld, oBounds, oPVR, oIcons); if (oLayer != null) { result.Add(oLayer); } } return(result); } else if (oSource is KMLPoint) { KMLPoint oCastSource = oSource as KMLPoint; KMLIcon result = new KMLIcon(oCastSource.Owner.Name, oCastSource.Coordinates.Latitude, oCastSource.Coordinates.Longitude, oCastSource.Coordinates.Altitude); result.DrawGroundStick = oCastSource.Extrude; result.Rotation = WorldWind.Angle.FromDegrees(oCastSource.Style.NormalStyle.IconStyle.Heading); result.IsRotated = oCastSource.Style.NormalStyle.IconStyle.Heading != 0.0f; result.NormalColor = oCastSource.Style.NormalStyle.LabelStyle.Color; result.HotColor = oCastSource.Style.HighlightStyle.LabelStyle.Color; oIcons.Add(result); oBounds.Union(oCastSource.Coordinates.Longitude, oCastSource.Coordinates.Latitude, oCastSource.Coordinates.Altitude); return(null); } else if (oSource is KMLPolygon) { KMLPolygon oCastSource = oSource as KMLPolygon; Polygon oTool = new Polygon(); oTool.outerBoundary = new WorldWind.LinearRing(GetPoints(oCastSource.OuterBoundary)); oTool.innerBoundaries = GetInnerBoundaries(oCastSource); oTool.PolgonColor = oCastSource.Style.NormalStyle.PolyStyle.Color; oTool.Fill = oCastSource.Style.NormalStyle.PolyStyle.Fill; oTool.LineWidth = oCastSource.Style.NormalStyle.LineStyle.Width; oTool.Outline = oCastSource.Style.NormalStyle.PolyStyle.Outline; oTool.OutlineColor = oCastSource.Style.NormalStyle.LineStyle.Color; oPVR.Add(oTool); oBounds.Union(oTool.GetGeographicBoundingBox()); return(null); } else if (oSource is KMLLineString) { KMLLineString oCastSource = oSource as KMLLineString; LineString oTool = new LineString(); oTool.Coordinates = GetPoints(oCastSource); oTool.Color = oCastSource.Style.NormalStyle.LineStyle.Color; oTool.LineWidth = oCastSource.Style.NormalStyle.LineStyle.Width; oPVR.Add(oTool); oBounds.Union(oTool.GetGeographicBoundingBox()); return(null); } else if (oSource is KMLGroundOverlay) { KMLGroundOverlay oCastSource = oSource as KMLGroundOverlay; KMLGroundOverlayRenderable result = new KMLGroundOverlayRenderable(oCastSource, strRelativeDirectory); oBounds.Union(new GeographicBoundingBox(oCastSource.LatLonBox.North, oCastSource.LatLonBox.South, oCastSource.LatLonBox.West, oCastSource.LatLonBox.East)); return(result); } else { return(null); } }