public KmlDocument(string name, string description, List <KmlPlacemark> placemarks) { Name = name; _description = description; Placemarks = placemarks; styles = KmlStyle.getStyleList(); }
protected virtual void ConvertProperties(KmlStyle style, GeoJsonProperties properties) { if (style == null) { return; } ConvertProperties(style.IconStyle, properties); ConvertProperties(style.LineStyle, properties); ConvertProperties(style.PolyStyle, properties); }
public static XElement ToKml(this KmlStyle style) { return(new XElement(ns + "Style", new XAttribute("id", style.GetHashCode()), new XElement(ns + "IconStyle", new XElement(ns + "color", style.IconColour), new XElement(ns + "scale", style.IconScale), new XElement(ns + "Icon", style.IconUrl)), new XElement(ns + "LineStyle", new XElement(ns + "color", style.LineColour), new XElement(ns + "width", style.LineWidth)), new XElement(ns + "PolyStyle", new XElement(ns + "color", style.PolygonColour)))); }
/// <summary> /// Initializes a new KML <c><Document></c> element. /// </summary> /// <param name="xml">The XML element the document should be based on.</param> /// <param name="namespaces">The XML namespace.</param> protected KmlDocument(XElement xml, XmlNamespaceManager namespaces) : base(xml, namespaces) { NetworkLink = xml.GetElement("kml:NetworkLink", namespaces, KmlNetworkLink.Parse); List <KmlStyleSelector> selectors = new List <KmlStyleSelector>(); List <KmlFeature> features = new List <KmlFeature>(); foreach (XElement child in xml.Elements()) { switch (child.Name.LocalName) { case "Style": selectors.Add(KmlStyle.Parse(child, namespaces)); break; case "StyleMap": selectors.Add(KmlStyleMap.Parse(child, namespaces)); break; case "Document": features.Add(KmlDocument.Parse(child, namespaces)); break; case "Folder": features.Add(KmlFolder.Parse(child, namespaces)); break; case "NetworkLink": features.Add(KmlNetworkLink.Parse(child, namespaces)); break; case "Placemark": features.Add(KmlPlacemark.Parse(child, namespaces)); break; case "GroundOverlay": case "PhotoOverlay": case "ScreenOverlay": // currently not supported break; } } StyleSelectors = new KmlStyleSelectorCollection(selectors); Features = new KmlFeatureCollection(features); }
public static void ExportAsKMZ(ILog log, Session session, string filename) { // Save session info as a KMZ file string kmzFile = filename; string kmlFile = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(filename) + ".kml"; string donutFile = GAEnvironment.SettingsPath + Path.DirectorySeparatorChar + "donut.png"; using (XmlWriter writer = XmlWriter.Create(kmlFile)) { // Initialize KML document writer.WriteStartDocument(); writer.WriteStartElement("kml"); writer.WriteString("\n"); writer.WriteStartElement("Document"); writer.WriteString("\n"); // Store KML styles KmlStyle s = new KmlStyle(); string[] colors = { "FFF0B414", "FF00D214", "FF78FFF0", "FF1478FF", "FF1400FF" }; // IAEA color codes XmlSerializer serializer = new XmlSerializer(typeof(KmlStyle)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); for (int i = 0; i < 5; i++) { s.ID = i.ToString(); s.IconStyle.Icon.Href = "files/donut.png"; s.IconStyle.Scale = "1.0"; s.IconStyle.Color = colors[i]; s.LabelStyle.Scale = "1.0"; serializer.Serialize(writer, s, ns); writer.WriteString("\n"); } // Store a KML placemark for each spectrum serializer = new XmlSerializer(typeof(KmlPlacemark)); KmlPlacemark p = new KmlPlacemark(); int styleID = 0; foreach (Spectrum spec in session.Spectrums) { double dose = spec.Doserate / 1000d; // Convert Doserate to micro // Calculate the style id for this sample if (dose <= 1d) { styleID = 0; } else if (dose <= 5) { styleID = 1; } else if (dose <= 10) { styleID = 2; } else if (dose <= 20) { styleID = 3; } else { styleID = 4; } p.Name = ""; p.StyleURL = "#" + styleID.ToString(); p.TimeStamp.When = spec.GpsTime.ToString("yyyy-MM-ddTHH:mm:ss"); p.Point.Coordinates = spec.Longitude.ToString(CultureInfo.InvariantCulture) + "," + spec.Latitude.ToString(CultureInfo.InvariantCulture); p.Description = "Value: " + dose.ToString("e", CultureInfo.InvariantCulture) + " μSv/h" + "\nLatitude: " + spec.Latitude.ToString(CultureInfo.InvariantCulture) + "\nLongitude: " + spec.Longitude.ToString(CultureInfo.InvariantCulture) + "\nAltitude: " + spec.Altitude.ToString(CultureInfo.InvariantCulture) + "\nTime: " + spec.GpsTime.ToString("yyyy-MM-dd HH:mm:ss") + " UTC"; serializer.Serialize(writer, p, ns); writer.WriteString("\n"); } // Finish KML document writer.WriteEndElement(); writer.WriteString("\n"); writer.WriteEndElement(); writer.WriteEndDocument(); } // Create a icon file to use for placemarks Bitmap bmpDonut = new Bitmap(crash.Properties.Resources.donut); bmpDonut.Save(donutFile, ImageFormat.Png); // Zip the KML and icon files to create a KMZ file using (ZipFile zip = new ZipFile()) { zip.AddFile(kmlFile, ""); zip.AddFile(donutFile, "files"); zip.Save(kmzFile); } // Delete temporary files if (File.Exists(donutFile)) { File.Delete(donutFile); } if (File.Exists(kmlFile)) { File.Delete(kmlFile); } }
public void DrawPlaceMarks() { // todo11 port this Maybe instancing later? Matrix projection = Earth3d.MainWindow.RenderContext11.Projection.Matrix11; Matrix view = Earth3d.MainWindow.RenderContext11.View.Matrix11; Matrix world = Earth3d.MainWindow.RenderContext11.World.Matrix11; Matrix3d worldD = Earth3d.MainWindow.RenderContext11.World; Matrix wvp = (world * view * projection); try { Vector3 center = new Vector3(0f, 0f, 0); foreach (KmlPlacemark placemark in Placemarks) { if (placemark.ShouldDisplay()) { SharpDX.Direct3D11.Viewport vp = Earth3d.MainWindow.RenderContext11.ViewPort; double alt = placemark.Point.altitude + EGM96Geoid.Height(placemark.Point.latitude, placemark.Point.longitude); Vector3d point3d = Coordinates.GeoTo3dDouble(placemark.Point.latitude, placemark.Point.longitude, 1 + (alt / Earth3d.MainWindow.RenderContext11.NominalRadius)); Vector3 point = Vector3.Project(point3d.Vector311, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0, 1, wvp); // point.Z = 1; KmlStyle style = placemark.Style.GetStyle(placemark.Selected); Texture11 texture = style.IconStyle.Icon.Texture; if (String.IsNullOrEmpty(style.IconStyle.Icon.Href)) { texture = Star; } double sizeFactor = 1; if (placemark.Selected) { double ticks = HiResTimer.TickCount; double elapsedSeconds = ((double)(ticks - TicksAtLastSelect)) / HiResTimer.Frequency; sizeFactor = 1 + .3 * (Math.Sin(elapsedSeconds * 15) * Math.Max(0, (1 - elapsedSeconds))); } point3d.TransformCoordinate(worldD); Vector3d dist = Earth3d.MainWindow.RenderContext11.CameraPosition - point3d; double distance = dist.Length() * Earth3d.MainWindow.RenderContext11.NominalRadius; dist.Normalize(); double dot = Vector3d.Dot(point3d, dist); // if (dot > -.2) { double baseSize = Math.Min(40, 25 * ((2 * Math.Atan(.5 * (5884764 / distance))) / .7853)) * sizeFactor; float size = (float)baseSize * style.IconStyle.Scale; //todo fix this with real centers and offset by KML data placemark.hitTestRect = new Rectangle((int)(point.X - (size / 2)), (int)(point.Y - (size / 2)), (int)(size + .5), (int)(size + .5)); if (texture != null) { center = new Vector3((float)texture.Width / 2f, (float)texture.Height / 2f, 0); Sprite2d.Draw2D(Earth3d.MainWindow.RenderContext11, texture, new SizeF(size, size), new PointF(center.X, center.Y), (float)(style.IconStyle.Heading * Math.PI / 180f), new PointF(point.X, point.Y), Color.White); } if (style.LabelStyle.Color.A > 0 && style.LabelStyle.Scale > 0) { Rectangle recttext = new Rectangle((int)(point.X + (size / 2) + 10), (int)(point.Y - (size / 2)), 1000, 100); //todo11 Earth3d.MainWindow.labelFont.DrawText(null, placemark.Name, recttext, DrawTextFormat.NoClip, style.LabelStyle.Color); } } } } } finally { } }
private void AddFeatureToDisplay(KmlFeature feature, bool sky) { KmlDocument doc = feature as KmlDocument; if (doc != null) { sky = doc.sky; } if (!(feature is KmlNetworkLink)) { if (feature.visibility == false) { return; } else if (feature is KmlPlacemark) { KmlPlacemark placemark = (KmlPlacemark)feature; KmlStyle style = placemark.Style.GetStyle(placemark.Selected); Color lineColor = Color.White; if (style != null) { lineColor = style.LineStyle.Color; } if (placemark.geometry is KmlPoint) { placemark.Point = (KmlPoint)placemark.geometry; AddPlacemark(placemark); } else if (placemark.geometry is KmlMultiGeometry) { KmlMultiGeometry geo = (KmlMultiGeometry)placemark.geometry; AddMultiGeometry(sky, placemark, (float)style.LineStyle.Width, style.PolyStyle.Color, lineColor, geo); } else if (placemark.geometry is KmlPolygon) { KmlPolygon geo = (KmlPolygon)placemark.geometry; if (geo.OuterBoundary != null) { AddLines(sky, geo.OuterBoundary as KmlLineList, (float)style.LineStyle.Width, style.PolyStyle.Color, lineColor, geo.extrude); // to do 3d work and subtract inner rings } } else if (placemark.geometry is KmlLineString) { KmlLineString geo = (KmlLineString)placemark.geometry; List <Vector3d> vertexList = new List <Vector3d>(); for (int i = 0; i < (geo.PointList.Count); i++) { vertexList.Add(Coordinates.GeoTo3dDouble(geo.PointList[i].Lat, geo.PointList[i].Lng, 1 + (geo.PointList[i].Alt / geo.MeanRadius))); } for (int i = 0; i < (geo.PointList.Count - 1); i++) { if (sky) { lines.AddLine(Coordinates.RADecTo3d(-(180.0 - geo.PointList[i].Lng) / 15 + 12, geo.PointList[i].Lat, 1), Coordinates.RADecTo3d(-(180.0 - geo.PointList[i + 1].Lng) / 15 + 12, geo.PointList[i + 1].Lat, 1), lineColor, new Dates()); } else { lines.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates()); } } } } if (feature is KmlGroundOverlay && feature.visibility) { AddGroundOverlay(feature as KmlGroundOverlay); } if (feature is KmlScreenOverlay && feature.visibility) { AddScreenOverlay(feature as KmlScreenOverlay); } } if (feature.visibility) { if (feature is KmlContainer) { KmlContainer container = (KmlContainer)feature; if (container.children != null) { foreach (KmlFeature child in container.children) { AddFeatureToDisplay(child, sky); } } } else { if (feature is KmlNetworkLink) { KmlNetworkLink netLink = (KmlNetworkLink)feature; if (netLink.LinkRoot != null) { foreach (KmlFeature child in netLink.LinkRoot.children) { AddFeatureToDisplay(child, sky); } } } } } }
public static void ExportAsKMZ(Session session, string filename) { // Save session info as a KMZ file string kmzFile = filename; string kmlFile = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(filename) + ".kml"; string donutFile = CrashEnvironment.SettingsPath + Path.DirectorySeparatorChar + "donut.png"; using (XmlWriter writer = XmlWriter.Create(kmlFile)) { // Initialize KML document writer.WriteStartDocument(); writer.WriteStartElement("kml"); writer.WriteString("\n"); writer.WriteStartElement("Document"); writer.WriteString("\n"); // Store KML styles KmlStyle s = new KmlStyle(); string[] colors = { "FFF0B414", "FF00D214", "FF78FFF0", "FF1478FF", "FF1400FF" }; // IAEA color codes XmlSerializer serializer = new XmlSerializer(typeof(KmlStyle)); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); for(int i = 0; i < 5; i++) { s.ID = i.ToString(); s.IconStyle.Icon.Href = "files/donut.png"; s.IconStyle.Scale = "1.0"; s.IconStyle.Color = colors[i]; s.LabelStyle.Scale = "1.0"; serializer.Serialize(writer, s, ns); writer.WriteString("\n"); } // Store a KML placemark for each spectrum serializer = new XmlSerializer(typeof(KmlPlacemark)); KmlPlacemark p = new KmlPlacemark(); int styleID = 0; foreach (Spectrum spec in session.Spectrums) { double dose = spec.Doserate / 1000d; // Convert Doserate to micro // Calculate the style id for this sample if(dose <= 1d) styleID = 0; else if (dose <= 5) styleID = 1; else if (dose <= 10) styleID = 2; else if (dose <= 20) styleID = 3; else styleID = 4; p.Name = ""; p.StyleURL = "#" + styleID.ToString(); p.TimeStamp.When = spec.GpsTimeStart.ToString("yyyy-MM-ddTHH:mm:ss"); p.Point.Coordinates = spec.LongitudeStart.ToString(CultureInfo.InvariantCulture) + "," + spec.LatitudeStart.ToString(CultureInfo.InvariantCulture); p.Description = "Value: " + dose.ToString("e", CultureInfo.InvariantCulture) + " μSv/h" + "\nLatitude: " + spec.LatitudeStart.ToString(CultureInfo.InvariantCulture) + "\nLongitude: " + spec.LongitudeStart.ToString(CultureInfo.InvariantCulture) + "\nAltitude: " + spec.AltitudeStart.ToString(CultureInfo.InvariantCulture) + "\nTime: " + spec.GpsTimeStart.ToString("yyyy-MM-dd HH:mm:ss") + " UTC"; serializer.Serialize(writer, p, ns); writer.WriteString("\n"); } // Finish KML document writer.WriteEndElement(); writer.WriteString("\n"); writer.WriteEndElement(); writer.WriteEndDocument(); } // Create a icon file to use for placemarks Bitmap bmpDonut = new Bitmap(crash.Properties.Resources.donut); bmpDonut.Save(donutFile, ImageFormat.Png); // Zip the KML and icon files to create a KMZ file using (ZipFile zip = new ZipFile()) { zip.AddFile(kmlFile, ""); zip.AddFile(donutFile, "files"); zip.Save(kmzFile); } // Delete temporary files if (File.Exists(donutFile)) File.Delete(donutFile); if(File.Exists(kmlFile)) File.Delete(kmlFile); }