public LineString(AltitudeMode altMode, List<ICoordinate> coords, bool extrude, bool tessellate) { this._altMode = altMode; this._coords = coords; this._extrude = extrude; this._tessellate = tessellate; }
public override object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is AltitudeMode) { AltitudeMode option = (AltitudeMode)value; switch (option) { case AltitudeMode.Absolute: return("Absolute"); case AltitudeMode.ClampToGround: return("Clamp to ground"); case AltitudeMode.RelativeToGround: return("Relative to ground"); default: return(option.ToString()); } } else { return(Binding.DoNothing); } }
//ICoordinate _loc; public Point(AltitudeMode altMode, double lat, double lon, double altMeters) { this._altMode = altMode; this._lat = lat; this._lon = lon; this._altMeters = altMeters; }
/// <summary> /// Creates a KML point /// </summary> /// <param name="ge">The plug-in instance</param> /// <param name="id">Optional placemark Id. Default is empty</param> /// <param name="latitude">The placemark latitude in decimal degrees</param> /// <param name="longitude">The placemark longitude in decimal degrees</param> /// <param name="altitude">Optional placemark altitude in metres. Default is 0</param> /// <param name="altitudeMode">Optional altitudeMode. Default is AltitudeMode.RelativeToGround</param> /// <returns>A Kml point (or null)</returns> public static dynamic CreatePoint( dynamic ge, string id = "", double latitude = 0, double longitude = 0, double altitude = 0, AltitudeMode altitudeMode = AltitudeMode.RelativeToGround) { if (!GEHelpers.IsGE(ge)) { throw new ArgumentException("ge is not of the type GEPlugin"); } dynamic point = null; try { point = ge.createPoint(id); point.setLatitude(latitude); point.setLongitude(longitude); point.setAltitude(altitude); point.setAltitudeMode(altitudeMode); } catch (RuntimeBinderException rbex) { Debug.WriteLine("CreatePoint: " + rbex.Message, "KmlHelpers"); } return(point); }
/// <summary> /// Initializes a new instance of the <see cref="LatLong">LatLong</see> object. /// </summary> /// <param name="latitude">Specifies the latitude of a single point on the globe.</param> /// <param name="longitude">Specifies the longitude of a single point on the globe.</param> /// <param name="altitude">Specifies the altitude of a single point on the globe.</param> /// <param name="altitudeMode">Specifies the mode in which an altitude is represented.</param> public LatLong(double latitude, double longitude, double altitude, AltitudeMode altitudeMode) { this.Latitude = latitude; this.Longitude = longitude; this.Altitude = altitude; this.AltitudeMode = altitudeMode; }
/// <inheritdoc /> public override XElement ToXElement() { if (Coordinates == null) { throw new PropertyNotSetException(nameof(Coordinates)); } XElement xml = base.ToXElement(); if (Extrude) { xml.Add(NewXElement("extrude", "1")); } if (Tesselate) { xml.Add(NewXElement("tessellate", "1")); } if (AltitudeMode != default(KmlAltitudeMode)) { xml.Add(NewXElement("altitudeMode", AltitudeMode.ToCamelCase())); } xml.Add(Coordinates.ToXElement()); return(xml); }
public AssetGeographicLocation(float InLongitude, float InLatitude, float InAltitude, AltitudeMode InMode = AltitudeMode.RelativeToGround) { this.Longitude = InLongitude; this.Latitude = InLatitude; this.Altitude = InAltitude; this.Mode = InMode; }
/// <summary> /// Initializes a new instance of the Coordinate class. /// </summary> /// <param name="latitude">the Coordinate latitude</param> /// <param name="longitude">the Coordinate longitude</param> /// <param name="altitude">the Coordinate altitude</param> /// <param name="altitudeMode">the Coordinate altitudeMode</param> public Coordinate( double latitude = 0, double longitude = 0, double altitude = 0, AltitudeMode altitudeMode = AltitudeMode.RelativeToGround) { this.Latitude = Maths.FixLatitude(latitude); this.Longitude = Maths.FixLongitude(longitude); this.Altitude = altitude; this.AltitudeMode = altitudeMode; }
/// <summary> /// Creates a KML placemark /// </summary> /// <param name="ge">The plug-in instance</param> /// <param name="id">Optional placemark Id. Default is empty</param> /// <param name="latitude">The placemark latitude in decimal degrees</param> /// <param name="longitude">The placemark longitude in decimal degrees</param> /// <param name="altitude">Optional placemark altitude in metres. Default is 0</param> /// <param name="altitudeMode">Optional altitudeMode. Default is AltitudeMode.RelativeToGround</param> /// <param name="name">Optional name of the placemark. Default is empty</param> /// <param name="description">Optional placemark description text. Default is empty</param> /// <param name="addFeature">Optionally adds the placemark directly to the plug-in. Default is true</param> /// <returns>A placemark (or null)</returns> public static dynamic CreatePlacemark( dynamic ge, string id = "", double latitude = 0, double longitude = 0, double altitude = 0, AltitudeMode altitudeMode = AltitudeMode.RelativeToGround, string name = "", string description = "", bool addFeature = true) { if (!GEHelpers.IsGE(ge)) { throw new ArgumentException("ge is not of the type GEPlugin"); } dynamic placemark = null; try { dynamic point = CreatePoint( ge, string.Empty, Maths.FixLatitude(latitude), Maths.FixLongitude(longitude), altitude, altitudeMode); placemark = ge.createPlacemark(id); placemark.setGeometry(point); placemark.setName(name); placemark.setDescription(description); if (addFeature) { GEHelpers.AddFeaturesToPlugin(ge, placemark); } } catch (RuntimeBinderException rbex) { Debug.WriteLine("CreatePlacemark: " + rbex.Message, "KmlHelpers"); } catch (COMException cex) { Debug.WriteLine("CreatePlacemark: " + cex.Message, "KmlHelpers"); } return(placemark); }
public static KML.AltitudeMode ToKML(this AltitudeMode altitudeMode) { if (altitudeMode == AltitudeMode.Absolute) { return(KML.AltitudeMode.Absolute); } if (altitudeMode == AltitudeMode.ClampToGround) { return(KML.AltitudeMode.ClampToGround); } if (altitudeMode == AltitudeMode.RelativeToGround) { return(KML.AltitudeMode.RelativeToGround); } return(KML.AltitudeMode.RelativeToGround); }
public SharpKml.Dom.Polygon makeSimplePolygon(List <Vector> lstVct, AltitudeMode altMode) { var pg = new SharpKml.Dom.Polygon(); pg.Tessellate = true; pg.Extrude = true; pg.AltitudeMode = altMode; var linring = new LinearRing(); OuterBoundary obdr = new OuterBoundary(); linring.Coordinates = new CoordinateCollection(lstVct); obdr.LinearRing = linring; obdr.LinearRing.CalculateBounds(); pg.OuterBoundary = obdr; return(pg); }
internal Camera Parse() { Camera camera = new Camera(); try { camera.Longitude = Longitude; camera.Latitude = Latitude; camera.Altitude = Altitude; camera.Heading = Heading; camera.Tilt = Tilt; camera.AltitudeMode = (AltitudeMode)Enum.Parse(typeof(AltitudeMode), AltitudeMode.ToString()); } catch (Exception ex) { Log.OutputBox(ex); } return(camera); }
public static string ToFriendlyName(this AltitudeMode Altitude) { switch (Altitude) { case AltitudeMode.Absolute: { return("absolute"); } case AltitudeMode.RelativeToGround: { return("relativeToGround"); } default: { return("absolute"); } } }
/// <summary> /// Look at the given coordinates /// </summary> /// <param name="ge">the plug-in</param> /// <param name="latitude">latitude in decimal degrees</param> /// <param name="longitude">longitude in decimal degrees</param> /// <param name="id">Optional LookAt Id. Default is empty</param> /// <param name="altitude">Optional altitude. Default is 0</param> /// <param name="altitudeMode">Optional altitudeMode. Default is AltitudeMode.RelativeToGround</param> /// <param name="heading">Optional heading in degrees. Default is 0 (north)</param> /// <param name="tilt">Optional tilt in degrees. Default is 0</param> /// <param name="range">Optional range in metres. Default is 1000</param> /// <param name="setView">Optional set the current view to the lookAt</param> /// <returns>a look at object (or null)</returns> public static dynamic CreateLookAt( dynamic ge, double latitude, double longitude, string id = "", double altitude = 0, AltitudeMode altitudeMode = AltitudeMode.RelativeToGround, double heading = 0, double tilt = 0, double range = 1000, bool setView = true) { if (!GEHelpers.IsGE(ge)) { throw new ArgumentException("ge is not of the type GEPlugin"); } dynamic lookat = null; try { lookat = ge.createLookAt(id); lookat.set(latitude, longitude, altitude, altitudeMode, heading, tilt, range); if (setView) { ge.getView().setAbstractView(lookat); } } catch (RuntimeBinderException rbex) { Debug.WriteLine("CreateLookAt: " + rbex.Message, "KmlHelpers"); } return(lookat); }
public override XmlNode ToXml(XmlDocument worldDoc) { XmlNode lfNode = worldDoc.CreateElement("LineFeature"); ConfigurationSaver.getRenderableObjectProperties(this, lfNode); XmlNode altitudeModeNode = worldDoc.CreateElement("AltitudeMode"); altitudeModeNode.AppendChild(worldDoc.CreateTextNode(AltitudeMode.ToString())); lfNode.AppendChild(altitudeModeNode); XmlNode minDANode = worldDoc.CreateElement("MinimumDisplayAltitude"); minDANode.AppendChild(worldDoc.CreateTextNode(MinimumDisplayAltitude.ToString(CultureInfo.InvariantCulture))); lfNode.AppendChild(minDANode); XmlNode maxDANode = worldDoc.CreateElement("MaximumDisplayAltitude"); maxDANode.AppendChild(worldDoc.CreateTextNode(MaximumDisplayAltitude.ToString(CultureInfo.InvariantCulture))); lfNode.AppendChild(maxDANode); XmlNode dASNode = worldDoc.CreateElement("DistanceAboveSurface"); dASNode.AppendChild(worldDoc.CreateTextNode(DistanceAboveSurface.ToString(CultureInfo.InvariantCulture))); lfNode.AppendChild(dASNode); XmlNode extrudeHeightNode = worldDoc.CreateElement("ExtrudeHeight"); extrudeHeightNode.AppendChild(worldDoc.CreateTextNode(ExtrudeHeight.ToString(CultureInfo.InvariantCulture))); lfNode.AppendChild(extrudeHeightNode); XmlNode extrudeNode = worldDoc.CreateElement("Extrude"); extrudeNode.AppendChild(worldDoc.CreateTextNode(Extrude.ToString(CultureInfo.InvariantCulture))); lfNode.AppendChild(extrudeNode); XmlNode extrudeUpwardsNode = worldDoc.CreateElement("ExtrudeUpwards"); extrudeUpwardsNode.AppendChild(worldDoc.CreateTextNode(ExtrudeUpwards.ToString(CultureInfo.InvariantCulture))); lfNode.AppendChild(extrudeUpwardsNode); XmlNode extrudeToGroundNode = worldDoc.CreateElement("ExtrudeToGround"); extrudeToGroundNode.AppendChild(worldDoc.CreateTextNode(ExtrudeToGround.ToString(CultureInfo.InvariantCulture))); lfNode.AppendChild(extrudeToGroundNode); XmlNode imageUriNode = worldDoc.CreateElement("ImageUri"); imageUriNode.AppendChild(worldDoc.CreateTextNode(ImageUri)); lfNode.AppendChild(imageUriNode); XmlNode outlineNode = worldDoc.CreateElement("Outline"); outlineNode.AppendChild(worldDoc.CreateTextNode(Outline.ToString(CultureInfo.InvariantCulture))); lfNode.AppendChild(outlineNode); // TODO: are these right? // FeatureColor in xml = LineColor, OutlineColor in xml = PolygonColor ? XmlNode featureColorNode = worldDoc.CreateElement("FeatureColor"); ConfigurationSaver.createColorNode(featureColorNode, LineColor); lfNode.AppendChild(featureColorNode); XmlNode outlineColornode = worldDoc.CreateElement("OutlineColor"); ConfigurationSaver.createColorNode(outlineColornode, PolygonColor); lfNode.AppendChild(outlineColornode); string posList = ConfigurationSaver.createPointList(Points); XmlNode lineStringNode = worldDoc.CreateElement("LineString"); XmlNode posListNode = worldDoc.CreateElement("posList"); posListNode.AppendChild(worldDoc.CreateTextNode(posList)); lineStringNode.AppendChild(posListNode); lfNode.AppendChild(lineStringNode); return(lfNode); }
/// <summary> /// Look at the given coordinates /// </summary> /// <param name="ge">the plug-in</param> /// <param name="latitude">latitude in decimal degrees</param> /// <param name="longitude">longitude in decimal degrees</param> /// <param name="id">Optional LookAt Id. Default is empty</param> /// <param name="altitude">Optional altitude. Default is 0</param> /// <param name="altitudeMode">Optional altitudeMode. Default is AltitudeMode.RelativeToGround</param> /// <param name="heading">Optional heading in degrees. Default is 0 (north)</param> /// <param name="tilt">Optional tilt in degrees. Default is 0</param> /// <param name="range">Optional range in metres. Default is 1000</param> /// <param name="setView">Optional set the current view to the lookAt</param> /// <returns>a look at object (or null)</returns> public static dynamic CreateLookAt( dynamic ge, double latitude, double longitude, string id = "", double altitude = 0, AltitudeMode altitudeMode = AltitudeMode.RelativeToGround, double heading = 0, double tilt = 0, double range = 1000, bool setView = true) { if (!GEHelpers.IsGE(ge)) { throw new ArgumentException("ge is not of the type GEPlugin"); } dynamic lookat = null; try { lookat = ge.createLookAt(id); lookat.set(latitude, longitude, altitude, altitudeMode, heading, tilt, range); if (setView) { ge.getView().setAbstractView(lookat); } } catch (RuntimeBinderException rbex) { Debug.WriteLine("CreateLookAt: " + rbex.Message, "KmlHelpers"); } return lookat; }
/// <summary> /// Creates a KML point /// </summary> /// <param name="ge">The plug-in instance</param> /// <param name="id">Optional placemark Id. Default is empty</param> /// <param name="latitude">The placemark latitude in decimal degrees</param> /// <param name="longitude">The placemark longitude in decimal degrees</param> /// <param name="altitude">Optional placemark altitude in metres. Default is 0</param> /// <param name="altitudeMode">Optional altitudeMode. Default is AltitudeMode.RelativeToGround</param> /// <returns>A Kml point (or null)</returns> public static dynamic CreatePoint( dynamic ge, string id = "", double latitude = 0, double longitude = 0, double altitude = 0, AltitudeMode altitudeMode = AltitudeMode.RelativeToGround) { if (!GEHelpers.IsGE(ge)) { throw new ArgumentException("ge is not of the type GEPlugin"); } dynamic point = null; try { point = ge.createPoint(id); point.setLatitude(latitude); point.setLongitude(longitude); point.setAltitude(altitude); point.setAltitudeMode(altitudeMode); } catch (RuntimeBinderException rbex) { Debug.WriteLine("CreatePoint: " + rbex.Message, "KmlHelpers"); } return point; }
/// <summary> /// Creates a KML placemark /// </summary> /// <param name="ge">The plug-in instance</param> /// <param name="id">Optional placemark Id. Default is empty</param> /// <param name="latitude">The placemark latitude in decimal degrees</param> /// <param name="longitude">The placemark longitude in decimal degrees</param> /// <param name="altitude">Optional placemark altitude in metres. Default is 0</param> /// <param name="altitudeMode">Optional altitudeMode. Default is AltitudeMode.RelativeToGround</param> /// <param name="name">Optional name of the placemark. Default is empty</param> /// <param name="description">Optional placemark description text. Default is empty</param> /// <param name="addFeature">Optionally adds the placemark directly to the plug-in. Default is true</param> /// <returns>A placemark (or null)</returns> public static dynamic CreatePlacemark( dynamic ge, string id = "", double latitude = 0, double longitude = 0, double altitude = 0, AltitudeMode altitudeMode = AltitudeMode.RelativeToGround, string name = "", string description = "", bool addFeature = true) { if (!GEHelpers.IsGE(ge)) { throw new ArgumentException("ge is not of the type GEPlugin"); } dynamic placemark = null; try { dynamic point = CreatePoint( ge, string.Empty, Maths.FixLatitude(latitude), Maths.FixLongitude(longitude), altitude, altitudeMode); placemark = ge.createPlacemark(id); placemark.setGeometry(point); placemark.setName(name); placemark.setDescription(description); if (addFeature) { GEHelpers.AddFeaturesToPlugin(ge, placemark); } } catch (RuntimeBinderException rbex) { Debug.WriteLine("CreatePlacemark: " + rbex.Message, "KmlHelpers"); } catch (COMException cex) { Debug.WriteLine("CreatePlacemark: " + cex.Message, "KmlHelpers"); } return placemark; }
private void init(Coordinates c, AltitudeMode altMode) { Coordinates = c; AltMode = altMode; _CN = Guid.NewGuid().ToString(); }
public KmlPoint(Coordinates c, AltitudeMode altMode) { init(c, altMode); }
public SharpKml.Dom.Polygon makeSimplePolygon(SharpKml.Dom.LineString lineString, AltitudeMode altMode) { List <Vector> lstVct = new List <Vector>(); lstVct.AddRange(lineString.Coordinates); lstVct.Add(lineString.Coordinates.First()); var pg = new SharpKml.Dom.Polygon(); pg.Extrude = true; pg.AltitudeMode = altMode; var linring = new LinearRing(); OuterBoundary obdr = new OuterBoundary(); linring.Coordinates = new CoordinateCollection(lstVct); obdr.LinearRing = linring; obdr.LinearRing.CalculateBounds(); pg.OuterBoundary = obdr; return(pg); }
private void writeKML(string filename) { try { writeGPX(filename); } catch { } Color[] colours = { Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet, Color.Pink }; AltitudeMode altmode = AltitudeMode.absolute; // all new logs have both agl and asl, we are using asl. this may break old logs // if (MainV2.comPort.MAV.cs.firmware == MainV2.Firmwares.ArduCopter2) { // altmode = AltitudeMode.relativeToGround; // because of sonar, this is both right and wrong. right for sonar, wrong in terms of gps as the land slopes off. } KMLRoot kml = new KMLRoot(); Folder fldr = new Folder("Log"); Style style = new Style(); style.Id = "yellowLineGreenPoly"; style.Add(new LineStyle(HexStringToColor("7f00ffff"), 4)); PolyStyle pstyle = new PolyStyle(); pstyle.Color = HexStringToColor("7f00ff00"); style.Add(pstyle); kml.Document.AddStyle(style); int stylecode = 0xff; int g = -1; foreach (List <Point3D> poslist in position) { g++; if (poslist == null) { continue; } LineString ls = new LineString(); ls.AltitudeMode = altmode; ls.Extrude = true; //ls.Tessellate = true; Coordinates coords = new Coordinates(); coords.AddRange(poslist); ls.coordinates = coords; Placemark pm = new Placemark(); string mode = ""; if (g < modelist.Count) { mode = modelist[g]; } pm.name = g + " Flight Path " + mode; pm.styleUrl = "#yellowLineGreenPoly"; pm.LineString = ls; stylecode = colours[g % (colours.Length - 1)].ToArgb(); Style style2 = new Style(); Color color = Color.FromArgb(0xff, (stylecode >> 16) & 0xff, (stylecode >> 8) & 0xff, (stylecode >> 0) & 0xff); log.Info("colour " + color.ToArgb().ToString("X") + " " + color.ToKnownColor().ToString()); style2.Add(new LineStyle(color, 4)); pm.AddStyle(style2); fldr.Add(pm); } Folder planes = new Folder(); planes.name = "Planes"; fldr.Add(planes); Folder waypoints = new Folder(); waypoints.name = "Waypoints"; fldr.Add(waypoints); LineString lswp = new LineString(); lswp.AltitudeMode = AltitudeMode.relativeToGround; lswp.Extrude = true; Coordinates coordswp = new Coordinates(); foreach (PointLatLngAlt p1 in cmd) { coordswp.Add(new Point3D(p1.Lng, p1.Lat, p1.Alt)); } lswp.coordinates = coordswp; Placemark pmwp = new Placemark(); pmwp.name = "Waypoints"; //pm.styleUrl = "#yellowLineGreenPoly"; pmwp.LineString = lswp; waypoints.Add(pmwp); int a = 0; int l = -1; Model lastmodel = null; foreach (Data mod in flightdata) { l++; if (mod.model.Location.latitude == 0) { continue; } if (lastmodel != null) { if (lastmodel.Location.Equals(mod.model.Location)) { continue; } } Placemark pmplane = new Placemark(); pmplane.name = "Plane " + a; pmplane.visibility = false; Model model = mod.model; model.AltitudeMode = altmode; model.Scale.x = 2; model.Scale.y = 2; model.Scale.z = 2; try { pmplane.description = @"<![CDATA[ <table> <tr><td>Roll: " + model.Orientation.roll + @" </td></tr> <tr><td>Pitch: " + model.Orientation.tilt + @" </td></tr> <tr><td>Yaw: " + model.Orientation.heading + @" </td></tr> <tr><td>WP dist " + mod.ntun[2] + @" </td></tr> <tr><td>tar bear " + mod.ntun[3] + @" </td></tr> <tr><td>nav bear " + mod.ntun[4] + @" </td></tr> <tr><td>alt error " + mod.ntun[5] + @" </td></tr> </table> ]]>"; } catch { } try { pmplane.Point = new KmlPoint((float)model.Location.longitude, (float)model.Location.latitude, (float)model.Location.altitude); pmplane.Point.AltitudeMode = altmode; Link link = new Link(); link.href = "block_plane_0.dae"; model.Link = link; pmplane.Model = model; planes.Add(pmplane); } catch { } // bad lat long value lastmodel = mod.model; a++; } kml.Document.Add(fldr); kml.Save(filename); // create kmz - aka zip file FileStream fs = File.Open(filename.Replace(".log.kml", ".kmz"), FileMode.Create); ZipOutputStream zipStream = new ZipOutputStream(fs); zipStream.SetLevel(9); //0-9, 9 being the highest level of compression zipStream.UseZip64 = UseZip64.Off; // older zipfile // entry 1 string entryName = ZipEntry.CleanName(Path.GetFileName(filename)); // Removes drive from name and fixes slash direction ZipEntry newEntry = new ZipEntry(entryName); newEntry.DateTime = DateTime.Now; zipStream.PutNextEntry(newEntry); // Zip the file in buffered chunks // the "using" will close the stream even if an exception occurs byte[] buffer = new byte[4096]; using (FileStream streamReader = File.OpenRead(filename)) { StreamUtils.Copy(streamReader, zipStream, buffer); } zipStream.CloseEntry(); File.Delete(filename); filename = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "block_plane_0.dae"; // entry 2 entryName = ZipEntry.CleanName(Path.GetFileName(filename)); // Removes drive from name and fixes slash direction newEntry = new ZipEntry(entryName); newEntry.DateTime = DateTime.Now; zipStream.PutNextEntry(newEntry); // Zip the file in buffered chunks // the "using" will close the stream even if an exception occurs buffer = new byte[4096]; using (FileStream streamReader = File.OpenRead(filename)) { StreamUtils.Copy(streamReader, zipStream, buffer); } zipStream.CloseEntry(); zipStream.IsStreamOwner = true; // Makes the Close also Close the underlying stream zipStream.Close(); positionindex = 0; modelist.Clear(); flightdata.Clear(); position = new List <Core.Geometry.Point3D> [200]; cmd.Clear(); }
/// <summary> /// This method will be called when a new figure is passed to sink /// </summary> /// <param name="x">X coordinate</param> /// <param name="y">Y coordinate</param> /// <param name="z">Z coordinate</param> /// <param name="m">M coordinate</param> public void BeginFigure(double x, double y, Nullable <double> z, Nullable <double> m) { m_Context.BeginFigure(); #region Export of Altitude Mode flag if ((m_Context.Type == OpenGisGeographyType.Polygon && m_Context.IsFirstFigure) || m_Context.Type == OpenGisGeographyType.Point || m_Context.Type == OpenGisGeographyType.LineString) { // The following code exports the geography instance's altitude mode. // Altitude mode is stored as the m coordinate of every point, // but altitude mode is a geography instance property, so it must be the same for all vertices, // and we take it from the m coordinate of the first point. if (m.HasValue) { int altitudeModeCode = (int)m.Value; if (Enum.IsDefined(typeof(AltitudeMode), altitudeModeCode)) { AltitudeMode altitudeMode = (AltitudeMode)altitudeModeCode; switch (altitudeMode) { case AltitudeMode.absolute: case AltitudeMode.relativeToGround: case AltitudeMode.relativeToSeaFloor: { StartElement("altitudeMode"); WriteString(altitudeMode.ToString()); EndElement(); break; } case AltitudeMode.clampToGround: case AltitudeMode.clampToSeaFloor: { _writer.WriteStartElement("altitudeMode", Constants.GxNamespace); WriteString(altitudeMode.ToString()); _writer.WriteEndElement(); break; } default: { throw new KMLException("Altitude mode not supported: " + altitudeMode.ToString()); } } } } } #endregion #region Export of Tesselate Flag // If the altitude mode is "clamp to ground" or "clamp to sea floor" then a tesselate flag will be exported if (m_Context.Type == OpenGisGeographyType.LineString || (m_Context.Type == OpenGisGeographyType.Polygon && m_Context.IsFirstFigure)) { if (m.HasValue) { int altitudeModeCode = (int)m.Value; if (Enum.IsDefined(typeof(AltitudeMode), altitudeModeCode)) { AltitudeMode altitudeMode = (AltitudeMode)altitudeModeCode; if (altitudeMode == AltitudeMode.clampToGround || altitudeMode == AltitudeMode.clampToSeaFloor) { StartElement("tessellate"); WriteString("1"); EndElement(); } } } } #endregion if (m_Context.Type == OpenGisGeographyType.Point || m_Context.Type == OpenGisGeographyType.LineString) { StartElement("coordinates"); } else if (m_Context.Type == OpenGisGeographyType.Polygon) { StartElement(m_Context.IsFirstFigure ? "outerBoundaryIs" : "innerBoundaryIs"); StartElement("LinearRing"); StartElement("coordinates"); } _writer.WriteValue(Utilities.ShiftInRange(y, 180)); _writer.WriteValue(","); _writer.WriteValue(Utilities.ShiftInRange(x, 90)); if (z != null && z.HasValue) { _writer.WriteValue(","); _writer.WriteValue(z.Value); } }
public void writeKML(string filename) { try { writeGPX(filename); } catch { } try { writeRinex(filename); } catch { } try { writeWPFile(filename); } catch { } try { writeParamFile(filename); } catch { } Color[] colours = { Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet, Color.Pink }; AltitudeMode altmode = AltitudeMode.absolute; KMLRoot kml = new KMLRoot(); Folder fldr = new Folder("Log"); Style style = new Style(); style.Id = "yellowLineGreenPoly"; style.Add(new LineStyle(HexStringToColor("7f00ffff"), 4)); Style style1 = new Style(); style1.Id = "spray"; style1.Add(new LineStyle(HexStringToColor("4c0000ff"), 0)); style1.Add(new PolyStyle() { Color = HexStringToColor("4c0000ff") }); PolyStyle pstyle = new PolyStyle(); pstyle.Color = HexStringToColor("7f00ff00"); style.Add(pstyle); kml.Document.AddStyle(style); kml.Document.AddStyle(style1); int stylecode = 0xff; int g = -1; foreach (List <Point3D> poslist in position) { g++; if (poslist == null) { continue; } /* * List<PointLatLngAlt> pllalist = new List<PointLatLngAlt>(); * * foreach (var point in poslist) * { * pllalist.Add(new PointLatLngAlt(point.Y, point.X, point.Z, "")); * } * * var ans = Utilities.LineOffset.GetPolygon(pllalist, 2); * * * * while (ans.Count > 0) * { * var first = ans[0]; * var second = ans[1]; * var secondlast = ans[ans.Count - 2]; * var last = ans[ans.Count-1]; * * ans.Remove(first); * ans.Remove(last); * * var polycoords = new BoundaryIs(); * * polycoords.LinearRing = new LinearRing(); * * polycoords.LinearRing.Coordinates.Add(new Point3D(first.Lng, first.Lat, 1)); * polycoords.LinearRing.Coordinates.Add(new Point3D(second.Lng, second.Lat, 1)); * polycoords.LinearRing.Coordinates.Add(new Point3D(secondlast.Lng, secondlast.Lat, 1)); * polycoords.LinearRing.Coordinates.Add(new Point3D(last.Lng, last.Lat, 1)); * polycoords.LinearRing.Coordinates.Add(new Point3D(first.Lng, first.Lat, 1)); * * //if (!IsClockwise(polycoords.LinearRing.Coordinates)) * // polycoords.LinearRing.Coordinates.Reverse(); * * Polygon kmlpoly = new Polygon() { AltitudeMode = AltitudeMode.relativeToGround, Extrude = false, OuterBoundaryIs = polycoords }; * * Placemark pmpoly = new Placemark(); * pmpoly.Polygon = kmlpoly; * pmpoly.name = g + " test"; * pmpoly.styleUrl = "#spray"; * * fldr.Add(pmpoly); * } */ LineString ls = new LineString(); ls.AltitudeMode = altmode; ls.Extrude = true; //ls.Tessellate = true; Coordinates coords = new Coordinates(); coords.AddRange(poslist); ls.coordinates = coords; Placemark pm = new Placemark(); string mode = ""; if (g < modelist.Count) { mode = modelist[g]; } pm.name = g + " Flight Path " + mode; pm.styleUrl = "#yellowLineGreenPoly"; pm.LineString = ls; stylecode = colours[g % (colours.Length - 1)].ToArgb(); Style style2 = new Style(); Color color = Color.FromArgb(0xff, (stylecode >> 16) & 0xff, (stylecode >> 8) & 0xff, (stylecode >> 0) & 0xff); log.Info("colour " + color.ToArgb().ToString("X") + " " + color.ToKnownColor().ToString()); style2.Add(new LineStyle(color, 4)); pm.AddStyle(style2); fldr.Add(pm); } Placemark pmPOS = new Placemark(); pmPOS.name = "POS Message"; pmPOS.LineString = new LineString(); pmPOS.LineString.coordinates = new Coordinates(); Point3D lastPoint3D = new Point3D(); PointLatLngAlt lastplla = PointLatLngAlt.Zero; foreach (var item in PosLatLngAlts) { var newpoint = new Point3D(item.Lng, item.Lat, item.Alt); if (item.GetDistance(lastplla) < 0.1 && lastPoint3D.Z >= (newpoint.Z - 0.3) && lastPoint3D.Z <= (newpoint.Z + 0.3)) { continue; } pmPOS.LineString.coordinates.Add(newpoint); lastPoint3D = newpoint; lastplla = item; if (pmPOS.LineString.coordinates.Count > 20000) { //add current pmPOS.AddStyle(style); fldr.Add(pmPOS); // create new pmPOS = new Placemark(); pmPOS.name = "POS Message - extra"; pmPOS.LineString = new LineString(); pmPOS.LineString.coordinates = new Coordinates(); lastPoint3D = new Point3D(); lastplla = PointLatLngAlt.Zero; } } pmPOS.AddStyle(style); fldr.Add(pmPOS); Folder planes = new Folder(); planes.name = "Planes"; fldr.Add(planes); Folder waypoints = new Folder(); waypoints.name = "Waypoints"; fldr.Add(waypoints); LineString lswp = new LineString(); lswp.AltitudeMode = AltitudeMode.relativeToGround; lswp.Extrude = true; Coordinates coordswp = new Coordinates(); foreach (PointLatLngAlt p1 in cmd) { if (p1.Lng == 0 && p1.Lat == 0) { continue; } coordswp.Add(new Point3D(p1.Lng, p1.Lat, p1.Alt)); } lswp.coordinates = coordswp; Placemark pmwp = new Placemark(); pmwp.name = "Waypoints"; //pm.styleUrl = "#yellowLineGreenPoly"; pmwp.LineString = lswp; if (coordswp.Count > 0) { waypoints.Add(pmwp); } int a = 0; int l = -1; Model lastmodel = null; foreach (Data mod in flightdata) { l++; if (mod.model.Location.latitude == 0) { continue; } if (lastmodel != null) { if (lastmodel.Location.Equals(mod.model.Location)) { continue; } } Placemark pmplane = new Placemark(); pmplane.name = "Plane " + a; pmplane.visibility = false; Model model = mod.model; model.AltitudeMode = altmode; model.Scale.x = 2; model.Scale.y = 2; model.Scale.z = 2; try { pmplane.description = @"<![CDATA[ <table> <tr><td>Roll: " + model.Orientation.roll + @" </td></tr> <tr><td>Pitch: " + model.Orientation.tilt + @" </td></tr> <tr><td>Yaw: " + model.Orientation.heading + @" </td></tr> <tr><td>WP dist " + mod.ntun[2] + @" </td></tr> <tr><td>tar bear " + mod.ntun[3] + @" </td></tr> <tr><td>nav bear " + mod.ntun[4] + @" </td></tr> <tr><td>alt error " + mod.ntun[5] + @" </td></tr> </table> ]]>"; } catch { } try { pmplane.Point = new KmlPoint((float)model.Location.longitude, (float)model.Location.latitude, (float)model.Location.altitude); pmplane.Point.AltitudeMode = altmode; Link link = new Link(); link.href = "block_plane_0.dae"; model.Link = link; pmplane.Model = model; planes.Add(pmplane); } catch { } // bad lat long value lastmodel = mod.model; a++; } kml.Document.Add(fldr); kml.Save(filename); // create kmz - aka zip file FileStream fs = File.Open(filename.ToLower().Replace(".log.kml", ".kmz").Replace(".bin.kml", ".kmz"), FileMode.Create); ZipOutputStream zipStream = new ZipOutputStream(fs); zipStream.SetLevel(9); //0-9, 9 being the highest level of compression zipStream.UseZip64 = UseZip64.Off; // older zipfile // entry 1 string entryName = ZipEntry.CleanName(Path.GetFileName(filename)); // Removes drive from name and fixes slash direction ZipEntry newEntry = new ZipEntry(entryName); newEntry.DateTime = DateTime.Now; zipStream.PutNextEntry(newEntry); // Zip the file in buffered chunks // the "using" will close the stream even if an exception occurs byte[] buffer = new byte[4096]; using (FileStream streamReader = File.OpenRead(filename)) { StreamUtils.Copy(streamReader, zipStream, buffer); } zipStream.CloseEntry(); File.Delete(filename); filename = Settings.GetRunningDirectory() + "block_plane_0.dae"; // entry 2 entryName = ZipEntry.CleanName(Path.GetFileName(filename)); // Removes drive from name and fixes slash direction newEntry = new ZipEntry(entryName); newEntry.DateTime = DateTime.Now; zipStream.PutNextEntry(newEntry); // Zip the file in buffered chunks // the "using" will close the stream even if an exception occurs buffer = new byte[4096]; using (FileStream streamReader = File.OpenRead(filename)) { StreamUtils.Copy(streamReader, zipStream, buffer); } zipStream.CloseEntry(); zipStream.IsStreamOwner = true; // Makes the Close also Close the underlying stream zipStream.Close(); positionindex = 0; modelist.Clear(); flightdata.Clear(); position = new List <Core.Geometry.Point3D> [200]; cmd.Clear(); cmdraw.Clear(); }
public KmlPoint(Coordinates coordinates = new Coordinates(), AltitudeMode altMode = AltitudeMode.ClampToGround) { CN = Guid.NewGuid().ToString(); Coordinates = coordinates; AltMode = altMode; }