Ejemplo n.º 1
0
        public void Srtm()
        {
            string path = "srtmcache";

            if (System.IO.Directory.Exists(path))
            {
                System.IO.Directory.Delete(path, true);
            }

            System.IO.Directory.CreateDirectory(path);

            var srtmData = new SRTMData(path);

            // get elevations for some locations
            int?elevation = srtmData.GetElevation(47.267222, 11.392778);

            Console.WriteLine("Elevation of Innsbruck: {0}m", elevation);
            Assert.AreEqual(584, elevation);

            elevation = srtmData.GetElevation(-16.5, -68.15);
            Console.WriteLine("Elevation of La Paz: {0}m", elevation);
            Assert.AreEqual(3782, elevation);

            elevation = srtmData.GetElevation(27.702983735525862f, 85.2978515625f);
            Console.WriteLine("Elevation of Kathmandu {0}m", elevation);
            Assert.AreEqual(1312, elevation);

            elevation = srtmData.GetElevation(21.030673628606102f, 105.853271484375f);
            Console.WriteLine("Elevation of Ha Noi {0}m", elevation);
            Assert.AreEqual(14, elevation);
        }
        public void DebugHeight()
        {
            var srtmData = new SRTMData(@"C:\temp\srtm-cache");

            // -38.26192626 144.6653395
            int?DebugHeight = srtmData.GetElevation(-38.26192626, 144.6653395);


            int expected = 136;

            // -33.47330 151.31728
            int?result = srtmData.GetElevation(-33.47330, 151.31728);

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 3
0
        public static void Build(string filename)
        {
            var routerDb = new RouterDb();

            routerDb.LoadOsmDataFromOverpass(new Box(51.25380399985758f, 4.809179306030273f,
                                                     51.273138772415194f, 4.765233993530273f), Itinero.Osm.Vehicles.Vehicle.Car);

            // create a new srtm data instance.
            // it accepts a folder to download and cache data into.
            var srtmCache = new DirectoryInfo("srtm-cache");

            if (!srtmCache.Exists)
            {
                srtmCache.Create();
            }
            var srtmData = new SRTMData("srtm-cache");

            LocalGeo.Elevation.ElevationHandler.GetElevation = (lat, lon) =>
            {
                return((short)srtmData.GetElevation(lat, lon));
            };
            routerDb.AddElevation();

            routerDb.AddContracted(Itinero.Osm.Vehicles.Vehicle.Car.Fastest(), true);

            using (var stream = File.Open(filename, FileMode.Create))
            {
                routerDb.Serialize(stream);
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var log = new LoggerConfiguration()
                      .WriteTo.ColoredConsole(outputTemplate: "{Timestamp:HH:mm} [{Level}] ({Name:l}) {Message}{NewLine}{Exception}")
                      .CreateLogger();

            Log.Logger = log;

            // https://dds.cr.usgs.gov/srtm/version2_1/SRTM3/
            var srtmData = new SRTMData(@"srtm-cache");

            int?elevationUlm = srtmData.GetElevation(48.197845, 9.954862);

            int?elevationInnsbruck = srtmData.GetElevation(47.267222, 11.392778);

            Console.WriteLine("Elevation of Innsbruck: {0}m", elevationInnsbruck);

            int?elevationLaPaz = srtmData.GetElevation(-16.5, -68.15);

            Console.WriteLine("Elevation of La Paz: {0}m", elevationLaPaz);

            int?elevationKathmandu = srtmData.GetElevation(27.702983735525862f, 85.2978515625f);

            Console.WriteLine("Elevation of Kathmandu {0}m", elevationLaPaz);

            int?elevationHanoi = srtmData.GetElevation(21.030673628606102f, 105.853271484375f);

            Console.WriteLine("Elevation of Ha Noi {0}m", elevationHanoi);

            // tries to get elevation from an empty cell.
            int?elevationSomeplace1 = srtmData.GetElevation(52.02237f, 2.55853224f);

            Console.WriteLine("Elevation of nowhere returns {0}", elevationSomeplace1);

            int?elevationNamibia1 = srtmData.GetElevation(-20, 19.89597);

            Console.WriteLine("Elevation of namibia1 returns {0}", elevationNamibia1);

            int?elevationRostock = srtmData.GetElevation(54.1298258, 12.0630578);

            Console.WriteLine("Elevation of Rostock returns {0}", elevationRostock);

            elevationRostock = srtmData.GetElevation(54.1238326, 12.0641476);
            Console.WriteLine("Elevation of Rostock returns {0}", elevationRostock);

            Console.WriteLine("Testing finished.");
            Console.ReadLine();
        }
        public void TestMethod1()
        {
            var srtmData = new SRTMData(@"C:\temp\srtm-cache");

            int expected = 136;

            // -33.47330 151.31728
            int?result = srtmData.GetElevation(-33.47330, 151.31728);

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 6
0
        public static double ReadTerrain(double latitude, double longitude)
        {
            var srtmData = new SRTMData(@"C:\Users\Ciclicci\Desktop\SRTM_USGS", new USGSSource());

            //var credentials = new NetworkCredential("mikeyart", "Prince5498");
            //var srtmData = new SRTMData(@"C:\Users\Ciclicci\Desktop\SRTM_NASA", new NASASource(credentials));

            int?   elevation1 = srtmData.GetElevation(latitude, longitude);
            double elevation  = Convert.ToDouble(elevation1);

            return(elevation);
        }
Ejemplo n.º 7
0
        static void USGSTest()
        {
            Console.WriteLine("Start USGSTest.");

            // https://dds.cr.usgs.gov/srtm/version2_1/SRTM3/
            var srtmData = new SRTMData(@"srtm-cache", new USGSSource());

            int?elevationInnsbruck = srtmData.GetElevation(47.267222, 11.392778);

            Console.WriteLine("Elevation of Innsbruck: {0}m", elevationInnsbruck);

            int?elevationLaPaz = srtmData.GetElevation(-16.5, -68.15);

            Console.WriteLine("Elevation of La Paz: {0}m", elevationLaPaz);

            int?elevationKathmandu = srtmData.GetElevation(27.702983735525862f, 85.2978515625f);

            Console.WriteLine("Elevation of Kathmandu {0}m", elevationKathmandu);

            int?elevationHanoi = srtmData.GetElevation(21.030673628606102f, 105.853271484375f);

            Console.WriteLine("Elevation of Ha Noi {0}m", elevationHanoi);

            // tries to get elevation from an empty cell.
            int?elevationSomeplace1 = srtmData.GetElevation(52.02237f, 2.55853224f);

            Console.WriteLine("Elevation of nowhere returns {0}", elevationSomeplace1);

            int?elevationNamibia1 = srtmData.GetElevation(-20, 19.89597);

            Console.WriteLine("Elevation of namibia1 returns {0}", elevationNamibia1);

            Console.WriteLine("End USGSTest.");
        }
Ejemplo n.º 8
0
        public List <Point> GenerateIntermediateProfilePoints(GlobalCoordinates start, GlobalCoordinates end)
        {
            List <Point> points = new List <Point>();

            int?startHeight = srtmData.GetElevation(start.Latitude.Degrees, start.Longitude.Degrees);

            points.Add(new Point(start, startHeight));

            path = geoCalc.CalculateGeodeticCurve(ellipsoid, start, end);
            Angle  azimuth       = path.Azimuth.Degrees;
            double totalDistance = path.EllipsoidalDistance;

            int numberOfPoints = (Convert.ToInt32(Math.Floor(totalDistance / distanceBetweenPoints)));

            for (int i = 0; i < numberOfPoints; i++)
            {
                GlobalCoordinates nextPoint = geoCalc.CalculateEndingGlobalCoordinates(ellipsoid, points[i].coordinate, azimuth, distanceBetweenPoints, out azimuth);
                int?height = srtmData.GetElevation(nextPoint.Latitude.Degrees, nextPoint.Longitude.Degrees);

                points.Add(new Point(nextPoint, height));
            }

            int?endHeight = srtmData.GetElevation(end.Latitude.Degrees, end.Longitude.Degrees);

            points.Add(new Point(end, endHeight));

            /*
             * Perform a sanity check
             * Occasionally the SRTM library throws up odd values like 65,535 so if we detect values above mount everest (about 8900m) we use the average height between the next points
             */
            FixHeights(ref points);



            return(points);
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            // enable logging.
            OsmSharp.Logging.Logger.LogAction = (o, level, message, parameters) =>
            {
                Console.WriteLine(string.Format("[{0}] {1} - {2}", o, level, message));
            };
            Itinero.Logging.Logger.LogAction = (o, level, message, parameters) =>
            {
                Console.WriteLine(string.Format("[{0}] {1} - {2}", o, level, message));
            };

            Download.ToFile("http://files.itinero.tech/data/OSM/planet/europe/luxembourg-latest.osm.pbf", "luxembourg-latest.osm.pbf").Wait();

            // load some routing data and create a router.
            var routerDb = new RouterDb();
            var router   = new Router(routerDb);

            using (var stream = File.OpenRead("luxembourg-latest.osm.pbf"))
            {
                routerDb.LoadOsmData(stream, Vehicle.Car);
            }

            // create a new srtm data instance.
            // it accepts a folder to download and cache data into.
            var srtmCache = new DirectoryInfo("srtm-cache");

            if (!srtmCache.Exists)
            {
                srtmCache.Create();
            }
            var srtmData = new SRTMData("srtm-cache");

            ElevationHandler.GetElevation = (lat, lon) =>
            {
                return((short)srtmData.GetElevation(lat, lon));
            };

            // add elevation.
            routerDb.AddElevation();

            // calculate route.
            // this should be the result: http://geojson.io/#id=gist:anonymous/c944cb9741f1fd511c8213b2dd83d58d&map=17/49.75454/6.09571
            var route = router.Calculate(Vehicle.Car.Fastest(), new Coordinate(49.75635954613685f, 6.095362901687622f),
                                         new Coordinate(49.75263039062888f, 6.098860502243042f));
            var routeGeoJson = route.ToGeoJson();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Tests adding elevation data.
        /// </summary>
        public static Action GetTestAddElevation(RouterDb routerDb)
        {
            // create a new srtm data instance.
            // it accepts a folder to download and cache data into.
            var srtmCache = new DirectoryInfo("srtm-cache");

            if (!srtmCache.Exists)
            {
                srtmCache.Create();
            }
            var srtmData = new SRTMData("srtm-cache");

            LocalGeo.Elevation.ElevationHandler.GetElevation = (lat, lon) =>
            {
                return((short)srtmData.GetElevation(lat, lon));
            };

            return(() =>
            {
                routerDb.AddElevation();
            });
        }
Ejemplo n.º 11
0
        public static int GetHeight(double lat, double lon, string path)
        {
            var srtmData = new SRTMData(path);

            return(srtmData.GetElevation(lat, lon) ?? -1);
        }