public void TestExtrudeAltitudePolygon()
        {
            var writer = new KMLWriter {
                Extrude = true, AltitudeMode = KMLWriter.AltitudeModeAbsolute
            };

            CheckEqual(writer, "POLYGON ((1 1, 2 1, 2 2, 1 2, 1 1))",
                       "<Polygon><extrude>1</extrude><altitudeMode>absolute</altitudeMode><outerBoundaryIs><LinearRing><coordinates>1,1 2,1 2,2 1,2 1,1</coordinates></LinearRing></outerBoundaryIs></Polygon>");
        }
        public void TestExtrudeAltitudeLineString()
        {
            var writer = new KMLWriter {
                Extrude = true, AltitudeMode = KMLWriter.AltitudeModeAbsolute
            };

            CheckEqual(writer, "LINESTRING (1 1, 2 2)",
                       "<LineString><extrude>1</extrude><altitudeMode>absolute</altitudeMode><coordinates>1,1 2,2</coordinates></LineString>");
        }
        public void TestExtrudeTesselateLineString()
        {
            var writer = new KMLWriter {
                Extrude = true, Tesselate = true
            };

            CheckEqual(writer, "LINESTRING (1 1, 2 2)",
                       "<LineString><extrude>1</extrude><tesselate>1</tesselate><coordinates>1,1 2,2</coordinates></LineString>");
        }
        public void negative_precision_means_floating_precision()
        {
            var writer = new KMLWriter {
                Precision = -1
            };

            CheckEqual(writer, "LINESTRING (1.0001 1.1234, 2.5555 2.99999)",
                       " <LineString><coordinates>1.0001,1.1234 2.5555,2.99999</coordinates></LineString>");
        }
        private void CheckEqual(KMLWriter writer, IGeometry geom, string expected)
        {
            string actual       = writer.Write(geom);
            string actualNorm   = normalizeKML(actual);
            string expectedNorm = normalizeKML(expected);
            bool   isEqual      = string.Equals(actualNorm, expectedNorm, StringComparison.OrdinalIgnoreCase);

            Assert.IsTrue(isEqual, string.Format("\nGenerated KML:  {0}\n  Expected KML: {1}", actualNorm, expectedNorm));
        }
        public void TestPrecision()
        {
            var writer = new KMLWriter {
                Precision = 1
            };

            CheckEqual(writer, "LINESTRING (1.0001 1.1234, 2.5555 2.99999)",
                       " <LineString><coordinates>1,1.1 2.6,3</coordinates></LineString>");
        }
        public void precision_zero_means_only_integers_allowed()
        {
            var writer = new KMLWriter {
                Precision = 0
            };

            CheckEqual(writer, "LINESTRING (1.0001 1.1234, 2.5555 2.99999)",
                       " <LineString><coordinates>1,1 3,3</coordinates></LineString>");
        }
        public void TestExtrudeGeometryCollection()
        {
            var writer = new KMLWriter {
                Extrude = true
            };

            CheckEqual(writer, "GEOMETRYCOLLECTION (LINESTRING (1 9, 1 2, 3 2), POLYGON ((3 9, 5 9, 5 7, 3 7, 3 9)), POINT (5 5))",
                       "<MultiGeometry><LineString><extrude>1</extrude><coordinates>1,9 1,2 3,2</coordinates></LineString><Polygon><extrude>1</extrude><outerBoundaryIs><LinearRing><coordinates>3,9 5,9 5,7 3,7 3,9</coordinates></LinearRing></outerBoundaryIs></Polygon><Point><extrude>1</extrude><coordinates>5,5</coordinates></Point></MultiGeometry>");
        }
예제 #9
0
        /// <summary>
        /// Returns a KML respresentation of all of the flights represented by the specified query
        /// </summary>
        /// <param name="fq">The flight query</param>
        /// <param name="s">The stream to which to write</param>
        /// <param name="error">Any error</param>
        /// <param name="lstIDs">The list of specific flight IDs to request</param>
        /// <returns>KML string for the matching flights.</returns>
        public static void AllFlightsAsKML(FlightQuery fq, Stream s, out string error, IEnumerable <int> lstIDs = null)
        {
            if (fq == null)
            {
                throw new ArgumentNullException(nameof(fq));
            }
            if (String.IsNullOrEmpty(fq.UserName) && (lstIDs == null || !lstIDs.Any()))
            {
                throw new MyFlightbookException("Don't get all flights as KML for an empty user!!");
            }

            if (lstIDs != null)
            {
                fq.EnumeratedFlights = lstIDs;
            }

            // Get the master airport list
            AirportList alMaster = AllFlightsAndNavaids(fq);

            using (KMLWriter kw = new KMLWriter(s))
            {
                kw.BeginKML();

                error = LookAtAllFlights(
                    fq,
                    LogbookEntryCore.LoadTelemetryOption.LoadAll,
                    (le) =>
                {
                    if (le.Telemetry.HasPath)
                    {
                        using (FlightData fd = new FlightData())
                        {
                            try
                            {
                                fd.ParseFlightData(le.Telemetry.RawData, le.Telemetry.MetaData);
                                if (fd.HasLatLongInfo)
                                {
                                    kw.AddPath(fd.GetTrajectory(), String.Format(CultureInfo.CurrentCulture, "{0:d} - {1}", le.Date, le.Comment), fd.SpeedFactor);
                                    return;
                                }
                            }
                            catch (Exception ex) when(!(ex is OutOfMemoryException))
                            {
                            }                                                                   // eat any error and fall through below
                        }
                    }
                    // No path was found above.
                    AirportList al = alMaster.CloneSubset(le.Route);
                    kw.AddRoute(al.GetNormalizedAirports(), String.Format(CultureInfo.CurrentCulture, "{0:d} - {1}", le.Date, le.Route));
                },
                    lstIDs != null && lstIDs.Any());
                kw.EndKML();
            }
        }
예제 #10
0
        /// <summary>
        /// This method will output the analysed KML file to the given location.
        /// </summary>
        /// <param name="file">The output location of the KML file</param>
        public void GenerateKML(String file)
        {
            // Ensure that analysis has been performed
            if (DBscan == null)
            {
                throw new Exception("Input data has not been clustered");
            }

            // Output the KML
            KMLWriter.GenerateKML(DBscan.Clusters, DBscan.Noise, file);
        }
예제 #11
0
    public static void WriteFeaturesToKML(string path, List <Feature> features)
    {
        string filename       = path + "KMLFeatures" + ".kml";
        string header         = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
        string documentOpen   = "<Document>\n";
        string xmlns          = "<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n";
        string placemarkOpen  = "<Placemark>\n";
        string placemarkClose = "</Placemark>\n";
        string documentClose  = "</Document>\n";
        string kmlClose       = "</kml>\n";

        KMLWriter     writer = new KMLWriter();
        StringBuilder sb     = new StringBuilder();

        string[] title       = new string[features.Count];
        string[] description = new string[features.Count];

        for (int i = 0; i < features.Count; ++i)
        {
            sb.Append(placemarkOpen);
            sb.Append("<name>" + features[i].Attributes["Title"].ToString() + "</name>\n");
            sb.Append("<description>" + features[i].Attributes["Description"].ToString() + "</description>\n");
            writer.Write(features[i].Geometry, sb);
            sb.Append(placemarkClose);
        }

        if (File.Exists(filename))
        {
            File.Delete(filename);
        }

        string fileContents = header + xmlns + documentOpen + sb.ToString() + documentClose + kmlClose;

        using (StreamWriter streamWriter = File.CreateText(filename))
        {
            streamWriter.Write(fileContents);
            streamWriter.Close();
        }
    }
예제 #12
0
        public void TestGenerateKMLNoise()
        {
            // Generate the output file path
            String file = OUTPUT_DIR + "kml_noise.kml";

            // Write the Clusters to disk
            KMLWriter.GenerateKML(Clusters, Noise, file);
            // Get the output file as a String array
            String[] kml = ReadFile(file);
            // Ensure that there is an XML heading tag in the output file
            Assert.AreEqual(kml[0], "<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            // Ensure that there is a KML namespace present.
            Assert.AreEqual(kml[1], "<kml xmlns=\"http://www.opengis.net/kml/2.2\">");
            // Ensure that there are Folders
            Assert.AreEqual(kml[305], "<Folder>");
            // Ensure that a folder has a name
            Assert.AreEqual(kml[306], "<name>Cluster 0</name>");
            // Ensure that there is a placemark
            Assert.AreEqual(kml[308], "<Placemark>");
            // Ensure that the above placemark is closed
            Assert.AreEqual(kml[315], "</Placemark>");
            // Ensure that the above folder is closed
            Assert.AreEqual(kml[760], "</Folder>");
        }
        private void CheckEqual(KMLWriter writer, string wkt, string expected)
        {
            var geom = new WKTReader().Read(wkt);

            CheckEqual(writer, geom, expected);
        }
        private void CheckEqual(string wkt, string expectedKML)
        {
            var writer = new KMLWriter();

            CheckEqual(writer, wkt, expectedKML);
        }