Ejemplo n.º 1
0
        /// <summary>
        /// <param name="locations">A 2D map of locations on the surface of earth. </param>
        /// </summary>
        public void FillElevationData(ref LatLonAlt[,] locations)
        {
            CultureInfo ci = new CultureInfo("en-US");
            List<string> loc = new List<string>();
            for (int J = 0; J < locations.GetLength(0); J++)
            {
                for (int I = 0; I < locations.GetLength(1); I++)
                {
                    loc.Add(String.Format(ci, "{0:0.0000},{1:0.0000}", locations[I, J].Latitude, locations[I, J].Longitude));
                }
            }
            var url = String.Format("http://maps.googleapis.com/maps/api/elevation/xml?sensor=false&locations={0}", loc.Aggregate((i, j) => i + "|" + j));

            Console.WriteLine("Fetching elevation data from maps.googleapis.com...");
            XmlDocument elevationData = new XmlDocument();
            elevationData.Load(url);

            XmlNodeList xmlNodeList = elevationData.SelectNodes("/ElevationResponse/result/elevation");

            var di = 0; // A local counter
            int x = 0; // the I-index of the matrix
            int y = 0; // the J-index of the matrix.
            foreach (XmlNode xmlNode in xmlNodeList)
            {
                // Update locations directly as we're spinning through all XML nodes.
                locations[x, y].Altitude = double.Parse(xmlNode.InnerText, ci.NumberFormat);
                di++;
                x = di % locations.GetLength(0);
                if (x == 0) y++;
            }
        }
Ejemplo n.º 2
0
        public static Vertex[,] ToVertex(ref LatLonAlt[,] pos)
        {
            var vertex = new Vertex[pos.GetLength(0), pos.GetLength(1)];
            for (var j = 0; j < pos.GetLength(1); j++)
            {
                for (var i = 0; i < pos.GetLength(1); i++)
                {
                    vertex[i, j] = ToVertex(pos[i, j]);
                }
            }

            return vertex;
        }
Ejemplo n.º 3
0
        public void GenerateSurface(ref LatLonAlt [,] locations)
        {
            var west = Geometry.CalculateDerivedPosition(Center, DistanceNS / 2.0, 180.0);
            var southWest = Geometry.CalculateDerivedPosition(west, DistanceEW / 2.0, 240.0);

            var ni = locations.GetLength(0);
            var nj = locations.GetLength(1);

            double dNS = DistanceNS / (double)ni;
            double dEW = DistanceEW / (double)nj;

            // Fill in the geographics from southWest up to northEast.
            var position = southWest;
            for (int J = 0; J < nj; ++J)
            {
                position = Geometry.CalculateDerivedPosition(position, dEW * (double)J, 90.0);
                locations[0, J] = position;

                for (int I = 1; I < ni; I++)
                {
                    locations[I, J] = Geometry.CalculateDerivedPosition(position, dNS * (double)I, 0.0);
                }
            }
        }