Пример #1
0
 /// <summary>
 /// Creates a new router point.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="vehicle"></param>
 /// <param name="location"></param>
 public RouterPoint(long id, Vehicle vehicle, GeoCoordinate location)
 {
     _id = id;
     this.Location = location;
     this.Vehicle = vehicle;
     this.Tags = new List<KeyValuePair<string, string>>();
 }
Пример #2
0
        /// <summary>
        /// Builds a dummy route (as the crow flies) for segments of a route not found.
        /// </summary>
        /// <returns></returns>
        public virtual Route BuildDummyRoute(Vehicle vehicle, GeoCoordinate coordinate1, GeoCoordinate coordinate2)
        {
            var route = new Route();
            route.Vehicle = vehicle.UniqueName;

            var segments = new RouteSegment[2];
            segments[0] = new RouteSegment();
            segments[0].Distance = 0;
            segments[0].Time = 0;
            segments[0].Type = RouteSegmentType.Start;
            segments[0].Vehicle = vehicle.UniqueName;
            segments[0].Latitude = (float)coordinate1.Latitude;
            segments[0].Longitude = (float)coordinate1.Longitude;

            var distance = coordinate1.DistanceReal(coordinate2).Value;
            var timeEstimage = distance / (vehicle.MaxSpeed().Value) * 3.6;
            var tags = new TagsCollection();
            tags.Add("route", "not_found");
            segments[1] = new RouteSegment();
            segments[1].Distance = distance;
            segments[1].Time = timeEstimage;
            segments[1].Type = RouteSegmentType.Stop;
            segments[1].Vehicle = vehicle.UniqueName;
            segments[1].Latitude = (float)coordinate2.Latitude;
            segments[1].Longitude = (float)coordinate2.Longitude;
            segments[1].Tags = RouteTagsExtensions.ConvertFrom(tags);

            route.Segments = segments;

            return route;
        }
        /// <summary>
        /// Compares the two given routes.
        /// </summary>
        /// <param name="reference"></param>
        /// <param name="route"></param>
        protected void CompareRoutes(Route reference, Route route)
        {
            double delta = 0.0001;

            if (reference.Segments == null)
            { // both routes are empty.
                Assert.IsNull(route.Segments);
            }
            else
            { // compare the geometry of the routes.
                for (int idx = 0; idx < reference.Segments.Length; idx++)
                {
                    var referenceCoordinate = new GeoCoordinate(reference.Segments[idx].Latitude,
                        reference.Segments[idx].Longitude);
                    Meter referenceDistance, distance;
                    GeoCoordinate referenceProjected, projected;
                    Second referenceTime, time;
                    reference.ProjectOn(referenceCoordinate, out referenceProjected, out referenceDistance, out referenceTime);
                    route.ProjectOn(referenceCoordinate, out projected, out distance, out time);

                    Assert.AreEqual(0, referenceProjected.DistanceReal(projected).Value, delta); // projected points have to match.
                    Assert.AreEqual(referenceDistance.Value, distance.Value, 0.1); // compare calculated distance to 10cm accuracy.
                    Assert.AreEqual(referenceProjected.Latitude, projected.Latitude, delta);
                    Assert.AreEqual(referenceProjected.Longitude, projected.Longitude, delta);
                }
            }
        }
Пример #4
0
        public void RoutingRegressionTest1()
        {
            var interpreter = new OsmRoutingInterpreter();
            var tagsIndex = new TagsTableCollectionIndex();

            // do the data processing.
            var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_routing_regression1.osm"));
            var sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            var basicRouter = new Dykstra();
            var router = Router.CreateLiveFrom(memoryData, basicRouter, interpreter);

            // resolve the three points in question.
            var point35 = new GeoCoordinate(51.01257, 4.000753);
            var point35resolved = router.Resolve(Vehicle.Car, point35);
            var point45 = new GeoCoordinate(51.01315, 3.999588);
            var point45resolved = router.Resolve(Vehicle.Car, point45);

            // route between 35 and 45.
            var routebefore = router.Calculate(Vehicle.Car, point35resolved, point45resolved);

            // route between 35 and 45.
            var routeafter = router.Calculate(Vehicle.Car, point35resolved, point45resolved);
            Assert.AreEqual(routebefore.TotalDistance, routeafter.TotalDistance);
        }
Пример #5
0
        /// <summary>
        /// Adds a line.
        /// </summary>
        public void AddLine(GeoCoordinate point1, GeoCoordinate point2, float sizePixels, int color)
        {
            if (point1 == null) { throw new ArgumentNullException(); }
            if (point2 == null) { throw new ArgumentNullException(); }

            // update envelope.
            if (_envelope == null)
            { // create initial envelope.
                _envelope = new GeoCoordinateBox(point1, point2);
            }
            // also include the current point.
            _envelope.ExpandWith(point1);
            _envelope.ExpandWith(point2);

            var projected1 = _projection.ToPixel(point1);
            var projected2 = _projection.ToPixel(point2);

            var x = new double[] { projected1[0], projected2[0] };
            var y = new double[] { projected1[1], projected2[1] };

            uint? pointsId = _scene.AddPoints(x, y);
            if (pointsId.HasValue)
            {
                _scene.AddStyleLine(pointsId.Value, 0, float.MinValue, float.MaxValue, color, sizePixels, Renderer.Primitives.LineJoin.Round, null);
                this.RaiseLayerChanged();
            }
        }
Пример #6
0
        public void TestGeoCoordinateOffsetWithDirection()
        {
            var distance = 1000; // 1km
            var start = new GeoCoordinate(53.32056, 1.72972);

            var offset = start.OffsetWithDirection(distance, DirectionEnum.North);
            Assert.AreEqual(53.32950, offset.Latitude, 0.0001);
            Assert.AreEqual(1.72970, offset.Longitude, 0.0001);

            offset = start.OffsetWithDirection(distance, DirectionEnum.NorthEast);
            Assert.AreEqual(53.32690, offset.Latitude, 0.0001);
            Assert.AreEqual(1.74040, offset.Longitude, 0.0001);

            start = new GeoCoordinate(0, 0);

            offset = start.OffsetWithDirection(distance, DirectionEnum.West);
            Assert.AreEqual(0, offset.Latitude, 0.0001);
            Assert.AreEqual(-0.008984, offset.Longitude, 0.0001);

            offset = start.OffsetWithDirection(distance, DirectionEnum.East);
            Assert.AreEqual(0, offset.Latitude, 0.0001);
            Assert.AreEqual(0.008984, offset.Longitude, 0.0001);

            offset = start.OffsetWithDirection(distance, DirectionEnum.North);
            Assert.AreEqual(0.008896, offset.Latitude, 0.0001);
            Assert.AreEqual(0, offset.Longitude, 0.0001);

            offset = start.OffsetWithDirection(distance, DirectionEnum.South);
            Assert.AreEqual(-0.008896, offset.Latitude, 0.0001);
            Assert.AreEqual(0, offset.Longitude, 0.0001);
        }
Пример #7
0
 /// <summary>
 /// Creates a geo coordinate line.
 /// </summary>
 /// <param name="point1"></param>
 /// <param name="point2"></param>
 /// <param name="is_segment1"></param>
 /// <param name="is_segment2"></param>
 public GeoCoordinateLine(
     GeoCoordinate point1,
     GeoCoordinate point2,
     bool is_segment1,
     bool is_segment2)
     : base(point1, point2, is_segment1, is_segment2)
 {
 }
Пример #8
0
 /// <summary>
 /// Returns true if the given coordinate is contained in this ring.
 /// 
 /// See: http://geomalgorithms.com/a03-_inclusion.html
 /// </summary>
 /// <param name="coordinate"></param>
 /// <returns></returns>
 public bool Contains(GeoCoordinate coordinate)
 {
     int number = 0;
     if (this.Coordinates[0] == coordinate)
     { // the given point is one of the corners.
         return true;
     }
     // loop over all edges and calculate if they possibly intersect.
     for (int idx = 0; idx < this.Coordinates.Count - 1; idx++)
     {
         if (this.Coordinates[idx + 1] == coordinate)
         { // the given point is one of the corners.
             return true;
         }
         bool idxRight = this.Coordinates[idx].Longitude > coordinate.Longitude;
         bool idx1Right = this.Coordinates[idx + 1].Longitude > coordinate.Longitude;
         if (idxRight || idx1Right)
         { // at least on of the coordinates is to the right of the point to calculate for.
             if ((this.Coordinates[idx].Latitude <= coordinate.Latitude &&
                 this.Coordinates[idx + 1].Latitude >= coordinate.Latitude) &&
                 !(this.Coordinates[idx].Latitude == coordinate.Latitude &&
                 this.Coordinates[idx + 1].Latitude == coordinate.Latitude))
             { // idx is lower than idx+1
                 if (idxRight && idx1Right)
                 { // no need for the left/right algorithm the result is already known.
                     number++;
                 }
                 else
                 { // one of the coordinates is not to the 'right' now we need the left/right algorithm.
                     LineF2D localLine = new LineF2D(this.Coordinates[idx], this.Coordinates[idx + 1]);
                     if (localLine.PositionOfPoint(coordinate) == LinePointPosition.Left)
                     {
                         number++;
                     }
                 }
             }
             else if ((this.Coordinates[idx].Latitude >= coordinate.Latitude &&
                 this.Coordinates[idx + 1].Latitude <= coordinate.Latitude) &&
                 !(this.Coordinates[idx].Latitude == coordinate.Latitude &&
                 this.Coordinates[idx + 1].Latitude == coordinate.Latitude))
             { // idx is higher than idx+1
                 if (idxRight && idx1Right)
                 { // no need for the left/right algorithm the result is already known.
                     number--;
                 }
                 else
                 { // one of the coordinates is not to the 'right' now we need the left/right algorithm.
                     LineF2D localLine = new LineF2D(this.Coordinates[idx], this.Coordinates[idx + 1]);
                     if (localLine.PositionOfPoint(coordinate) == LinePointPosition.Right)
                     {
                         number--;
                     }
                 }
             }
         }
     }
     return number != 0;
 }
Пример #9
0
        /// <summary>
        /// Calculates a solution to the ATSP.
        /// </summary>
        /// <param name="weights">The weights between all the customers.</param>
        /// <param name="locations">The locations of all customers.</param>
        /// <param name="first">The first customer.</param>
        /// <param name="is_round">Return to the first customer or not.</param>
        /// <returns></returns>
        public IRoute CalculateTSP(double[][] weights, GeoCoordinate[] locations, int first, bool is_round)
        {
            // create solver.
            ISolver solver = this.DoCreateSolver(locations.Length);
            solver.IntermidiateResult += new SolverDelegates.IntermidiateDelegate(solver_IntermidiateResult);

            // calculate the TSP.
            return solver.Solve(this.GenerateProblem(weights, first, null, is_round));
        }
Пример #10
0
		/// <summary>
		/// Initializes a new instance of the <see cref="SomeTestProject.MapMarker"/> class.
		/// </summary>
		/// <param name="location">Coordinate.</param>
		/// <param name="image">Bitmap.</param>
		/// <param name="alignment">Alignment.</param>
		public MapMarker(GeoCoordinate location, MapMarkerAlignmentType alignment, UIImage image)
			: base(UIButtonType.Custom){
			_image = image;
			this.Location = location;
			_alignment = alignment;

			this.Frame = new System.Drawing.RectangleF (new System.Drawing.PointF (0, 0), image.Size);
			this.SetImage (image, UIControlState.Normal);
			this.SetImage (image, UIControlState.Highlighted);
			this.SetImage (image, UIControlState.Disabled);
		}
Пример #11
0
        public void TestGeoCoordinateOffsetRandom()
        {
            var generator = new OsmSharp.Math.Random.RandomGenerator(10124613);

            for(int idx = 0; idx < 1000; idx++)
            {
                GeoCoordinate start = new GeoCoordinate(51, 4.8);
                GeoCoordinate offset = start.OffsetRandom(generator, 20);

                double distance = offset.DistanceReal(start).Value;
                Assert.IsTrue(distance <= 20.001);
            }
        }
Пример #12
0
        /// <summary>
        /// Adds a line.
        /// </summary>
        /// <param name="point1"></param>
        /// <param name="point2"></param>
        /// <param name="sizePixels"></param>
        /// <param name="color"></param>
        /// <returns></returns>
        public void AddLine(GeoCoordinate point1, GeoCoordinate point2, float sizePixels, int color)
        {
            double[] projected1 = _projection.ToPixel(point1);
            double[] projected2 = _projection.ToPixel(point2);

            double[] x = new double[] { projected1[0], projected2[0] };
            double[] y = new double[] { projected1[1], projected2[1] };

            uint? pointsId = _scene.AddPoints(x, y);
            if (pointsId.HasValue)
            {
                _scene.AddStyleLine(pointsId.Value, 0, float.MinValue, float.MaxValue, color, sizePixels, Renderer.Primitives.LineJoin.Round, null);
                this.RaiseLayerChanged();
            }
        }
Пример #13
0
        public override Tuple<string, double[][]>[] GetMatrix(Vehicle vehicle, GeoCoordinate[] source, GeoCoordinate[] target, string[] outputs,
            out Tuple<string, int, string>[] errors)
        {
            var errorsList = new List<Tuple<string, int, string>>();
            for (var i = 0; i < source.Length; i++)
            {
                if (source[i] == null || source[i].Latitude > 180)
                { // dummy incorrect coordinates had a lat bigger than 180.
                    errorsList.Add(new Tuple<string, int, string>("source", i, "Coordinate invalid."));
                    source[i] = null;
                }
            }
            for (var i = 0; i < target.Length; i++)
            {
                if (target[i] == null || target[i].Latitude > 180)
                { // dummy incorrect coordinates had a lat bigger than 180.
                    errorsList.Add(new Tuple<string, int, string>("target", i, "Coordinate invalid."));
                    target[i] = null;
                }
            }
            errors = errorsList.ToArray();

            // remove invalid coordinates.
            var sourceList = new List<GeoCoordinate>(source);
            sourceList.RemoveAll(x => x == null);
            source = sourceList.ToArray();
            var targetList = new List<GeoCoordinate>(target);
            targetList.RemoveAll(x => x == null);
            target = targetList.ToArray();

            // build a dummy response.
            var matrices = new Tuple<string, double[][]>[outputs.Length];
            for (var i = 0; i < outputs.Length; i++)
            {
                var weights = new double[source.Length][];
                for (var x = 0; x < weights.Length; x++)
                {
                    weights[x] = new double[target.Length];
                    for (var y = 0; y < target.Length; y++)
                    {
                        weights[x][y] = 100;
                    }
                }
                matrices[i] = new Tuple<string, double[][]>(outputs[i],
                    weights);
            }
            return matrices;
        }
Пример #14
0
        /// <summary>
        /// Handles the tap event.
        /// </summary>
        /// <param name="coordinate"></param>
        async void _mapView_MapTapEvent(GeoCoordinate coordinate)
        {
            if (_previous != null)
            {
                var route = RouterFacade.Calculate(_previous, coordinate);
                _routeLayer.Clear();
                if (route != null)
                {
                    _routeLayer.AddRoute(route);

                    // TODO: issue #120.
                    (_mapView as IMapView).Invalidate();
                }
            }
            _previous = coordinate;
        }
Пример #15
0
        public void TestGeoCoordinateOffsetEstimate()
        {
            GeoCoordinate coord1 = new GeoCoordinate(51, 4.8);

            Meter distance = 10000;

            GeoCoordinate coord3 = coord1.OffsetWithDistances(distance);
            GeoCoordinate coord3_lat = new GeoCoordinate(coord3.Latitude, coord1.Longitude);
            GeoCoordinate coord3_lon = new GeoCoordinate(coord1.Latitude, coord3.Longitude);

            Meter distance_lat = coord3_lat.DistanceReal(coord1);
            Meter distance_lon = coord3_lon.DistanceReal(coord1);

            Assert.AreEqual(distance.Value, distance_lat.Value, 0.001);
            Assert.AreEqual(distance.Value, distance_lon.Value, 0.001);
        }
Пример #16
0
        /// <summary>
        /// Calculate a simple route.
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public static async Task<Route> Calculate(GeoCoordinate from, GeoCoordinate to)
        {
            // REMARK1: this sample needs ServiceStack.Client.Pcl
            // REMARK2: this sample could need a fix for a bug related to System.IO.Compression: https://github.com/ServiceStack/Hello#issues
            // REMARK3: to have a strongly type client to the OsmSharp.Service.Routing service the package OsmSharp.Service.Routing needs to be installed.

            try
            {
                // create Json client.
                var client = new JsonServiceClient("http://build.osmsharp.com:666/");
                client.Timeout = new TimeSpan(0, 5, 0);

                // creates the array of the routing hook.
                var hooks = new RoutingHook[2];

                // create the array of geocoordinates.
                hooks[0] = new RoutingHook()
                {
                    Id = 0,
                    Latitude = (float)from.Latitude,
                    Longitude = (float)from.Longitude,
                    Tags = new RoutingHookTag[0]
                };
                hooks[1] = new RoutingHook()
                {
                    Id = 1,
                    Latitude = (float)to.Latitude,
                    Longitude = (float)to.Longitude,
                    Tags = new RoutingHookTag[0]
                };

                // set the request.
                var routingResponse = client.Get<RoutingResponse>(
                            new RoutingOperation()
                            {
                                Vehicle = Vehicle.Car.UniqueName,
                                Hooks = hooks,
                                Type = RoutingOperationType.Regular
                            });
                return routingResponse.Route;
            }
            catch(Exception ex)
            {
                OsmSharp.Logging.Log.TraceEvent("Router", OsmSharp.Logging.TraceEventType.Critical, "Unhandled exception occured: {0}", ex.ToString());
            }
            return null;
        }
Пример #17
0
        /// <summary>
        /// Adds a point.
        /// </summary>
        public void AddPoint(GeoCoordinate coordinate, float sizePixels, int color)
        {
            if (coordinate == null) { throw new ArgumentNullException(); }

            // update envelope.
            if (_envelope == null)
            { // create initial envelope.
                _envelope = new GeoCoordinateBox(coordinate, coordinate);
            }
            // also include the current point.
            _envelope.ExpandWith(coordinate);

            double[] projectedCoordinates = _projection.ToPixel(coordinate);
            uint pointId = _scene.AddPoint(projectedCoordinates[0], projectedCoordinates[1]);
            _scene.AddStylePoint(pointId, 0, float.MinValue, float.MaxValue, color, sizePixels);
            this.RaiseLayerChanged();
        }
Пример #18
0
        /// <summary>
        /// Calculates a number of routes from one source to many targets.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="coordinates"></param>
        /// <param name="complete"></param>
        public override Route[] GetOneToMany(Vehicle vehicle, GeoCoordinate[] coordinates, bool complete)
        {
            // resolve all points.
            var resolved = _router.Resolve(vehicle, coordinates);

            // calculate one-to-many routes.
            if (resolved[0] != null)
            {
                var targets = new List<RouterPoint>();
                foreach(var point in resolved)
                {
                    if (point != null)
                    {
                        targets.Add(point);
                    }
                }

                return _router.CalculateOneToMany(vehicle, resolved[0], targets.ToArray());
            }
            return new Route[coordinates.Length - 1];
        }
Пример #19
0
        public void TestLineairRingContainsPoint()
        {
            LineairRing ring = new LineairRing(new GeoCoordinate(0, 0),
                new GeoCoordinate(3, 0), new GeoCoordinate(0, 3), new GeoCoordinate(0, 0));

            foreach (GeoCoordinate ringCoordinate in ring.Coordinates)
            {
                Assert.IsTrue(ring.Contains(ringCoordinate));
            }

            GeoCoordinate coordinate = new GeoCoordinate(1, 1);
            Assert.IsTrue(ring.Contains(coordinate));
            coordinate = new GeoCoordinate(2, 2);
            Assert.IsFalse(ring.Contains(coordinate));
            coordinate = new GeoCoordinate(-1, 1);
            Assert.IsFalse(ring.Contains(coordinate));
            coordinate = new GeoCoordinate(0, 1);
            Assert.IsTrue(ring.Contains(coordinate));
            coordinate = new GeoCoordinate(1, 0);
            Assert.IsTrue(ring.Contains(coordinate));
        }
        public void RoutingRegressionTest1()
        {
            OsmRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            SimpleTagsIndex tags_index = new SimpleTagsIndex();

            // do the data processing.
            DynamicGraphRouterDataSource<LiveEdge> memory_data =
                new DynamicGraphRouterDataSource<LiveEdge>(tags_index);
            LiveGraphOsmStreamTarget target_data = new LiveGraphOsmStreamTarget(
                memory_data, interpreter, memory_data.TagsIndex);
            XmlOsmStreamSource data_processor_source = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test_routing_regression1.osm"));
            OsmStreamFilterSort sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(data_processor_source);
            target_data.RegisterSource(sorter);
            target_data.Pull();

            IBasicRouter<LiveEdge> basic_router = new DykstraRoutingLive(memory_data.TagsIndex);
            Router router = Router.CreateLiveFrom(memory_data, basic_router, interpreter);

            // resolve the three points in question.
            GeoCoordinate point35 = new GeoCoordinate(51.01257, 4.000753);
            RouterPoint point35resolved = router.Resolve(Vehicle.Car, point35);
            //            GeoCoordinate point40 = new GeoCoordinate(51.01250, 4.000013);
            //            RouterPoint point40resolved = router.Resolve(Vehicle.Car, point40);
            GeoCoordinate point45 = new GeoCoordinate(51.01315, 3.999588);
            RouterPoint point45resolved = router.Resolve(Vehicle.Car, point45);

            // route between 35 and 45.
            Route routebefore = router.Calculate(Vehicle.Car, point35resolved, point45resolved);

            //            GeoCoordinate point129 = new GeoCoordinate(51.01239, 3.999573);
            //            RouterPoint point129resolved = router.Resolve(Vehicle.Car, point129);

            // route between 35 and 45.
            Route routeafter = router.Calculate(Vehicle.Car, point35resolved, point45resolved);
            Assert.AreEqual(routebefore.TotalDistance, routeafter.TotalDistance);
        }
Пример #21
0
        /// <summary>
        /// Returns true if the given coordinate is contained in the inner area of the ring or lying on the border of the ring.
        /// Fast way based on the winding number aproach.        
        /// </summary>
        /// <param name="coordinate"></param>
        /// <returns></returns>
        public bool Contains(GeoCoordinate coordinate)
        {
            bool flipflop = false;
            const bool includeBorder = true; // Algoritm could be parameterized to optionally include the border.

            for (int i = 0, j = Coordinates.Count - 1; i < Coordinates.Count; j = i++)
            {
                if (Coordinates[j].Equals(coordinate))
                    return includeBorder;

                bool b = Coordinates[i].Latitude <= coordinate.Latitude;
                if (b != (Coordinates[j].Latitude <= coordinate.Latitude))
                {
                    var triangularOrientation = (Coordinates[j].Longitude - Coordinates[i].Longitude) * (coordinate.Latitude - Coordinates[i].Latitude) - (Coordinates[j].Latitude - Coordinates[i].Latitude) * (coordinate.Longitude - Coordinates[i].Longitude);
                    if (triangularOrientation > 0 && b || triangularOrientation < 0 && !b)
                        flipflop = !flipflop;
                    else if (triangularOrientation == 0)
                        return includeBorder;
                }
            }
            return flipflop;
        }
Пример #22
0
 /// <summary>
 /// Adds a new entry.
 /// </summary>
 /// <param name="country"></param>
 /// <param name="postalCode"></param>
 /// <param name="commune"></param>
 /// <param name="street"></param>
 /// <param name="houseNumber"></param>
 /// <param name="value"></param>
 public void Add(string country, string postalCode, string commune, string street, 
     string houseNumber, GeoCoordinate value)
 {
     IndexCommunes communes = _index.SearchExact(postalCode);
     if (communes == null)
     {
         communes = new IndexCommunes();
         _index.Add(postalCode, communes);
     }
     IndexStreets streets = communes.SearchExact(commune);
     if (streets == null)
     {
         streets = new IndexStreets();
         communes.Add(commune, streets);
     }
     IndexHouseNumbers numbers = streets.SearchExact(street);
     if (numbers == null)
     {
         numbers = new IndexHouseNumbers();
         streets.Add(street, numbers);
     }
     numbers.Add(houseNumber, value);
 }
Пример #23
0
        /// <summary>
        /// Calculate a simple route.
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public static Route Calculate(GeoCoordinate from, GeoCoordinate to)
        {
            try
            {
                lock(_graph)
                {
                    var router = Router.CreateCHFrom(_graph, new CHRouter(), new OsmRoutingInterpreter());

                    var fromResolved = router.Resolve(Vehicle.Car, from);
                    var toResolved = router.Resolve(Vehicle.Car, to);

                    if(fromResolved != null && toResolved !=null)
                    {
                        return router.Calculate(Vehicle.Car, fromResolved, toResolved);
                    }
                }
            }
            catch(Exception ex)
            {
                OsmSharp.Logging.Log.TraceEvent("Router", OsmSharp.Logging.TraceEventType.Critical, "Unhandled exception occured: {0}", ex.ToString());
            }
            return null;
        }
Пример #24
0
        public void TestSimpleWebMercator()
        {
            // TODO: stabalize the webmercator projection numerically for lower zoom levels (0-9).
            var mercator = new WebMercator();
            for (int zoomLevel = 10; zoomLevel <= 25; zoomLevel++)
            {
                var tile = Tile.CreateAroundLocation(new GeoCoordinate(0, 0), zoomLevel);

                var topleft = mercator.ToPixel(tile.Box.TopLeft);
                var bottomright = mercator.ToPixel(tile.Box.BottomRight);

                var scaleFactor = mercator.ToZoomFactor(zoomLevel);

                Assert.AreEqual(-256, (topleft[0] - bottomright[0]) * scaleFactor, 0.01);
                Assert.AreEqual(-256, (topleft[1] - bottomright[1]) * scaleFactor, 0.01);
            }

            var coordinate = new GeoCoordinate(51.26337, 4.78739);
            var projected = mercator.ToPixel(coordinate);
            var reProjected = mercator.ToGeoCoordinates(projected[0], projected[1]);

            Assert.AreEqual(coordinate.Longitude, reProjected.Longitude, 0.0001);
            Assert.AreEqual(coordinate.Latitude, reProjected.Latitude, 0.0001);
        }
Пример #25
0
 /// <summary>
 /// Sets the map view.
 /// </summary>
 /// <param name="center">Center.</param>
 /// <param name="mapTilt">Map tilt.</param>
 /// <param name="mapZoom">Map zoom.</param>
 void IMapView.SetMapView(GeoCoordinate center, Degree mapTilt, float mapZoom)
 {
     _mapView.SetMapView(center, mapTilt, mapZoom);
 }
Пример #26
0
        /// <summary>
        /// Adds the marker.
        /// </summary>
        /// <returns>The marker.</returns>
        /// <param name="location">Coordinate.</param>
        public MapMarker AddMarker(GeoCoordinate location)
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }
            ;

            var marker = new MapMarker(this.Context, location);
            this.AddMarker(marker);
            return marker;
        }
Пример #27
0
        /// <summary>
        /// Raises the map tap event.
        /// </summary>
        /// <param name="coordinate"></param>
        internal void RaiseMapTapEvent(GeoCoordinate coordinate)
        {
            if (this.MapTapEvent != null)
            {
                this.MapTapEvent(coordinate);
            }

            this.NotifyMapTapToControls();
        }
Пример #28
0
        /// <summary>
        /// Called when the view on the map has changed.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="zoomFactor"></param>
        /// <param name="center"></param>
        /// <param name="view"></param>
        /// <param name="extraView"></param>
        protected internal override void ViewChanged(Map map, float zoomFactor, GeoCoordinate center, View2D view, View2D extraView)
        {
            // all data is preloaded for now.

            // when displaying huge amounts of GPX-data use another approach.
        }
Пример #29
0
        /// <summary>
        /// Adds a polyline.
        /// </summary>
        /// <param name="points"></param>
        /// <param name="sizePixels"></param>
        /// <param name="color"></param>
        /// <returns></returns>
        public void AddPolyline(GeoCoordinate[] points, float sizePixels, int color)
        {
            var x = new double[points.Length];
            var y = new double[points.Length];
            for(int idx = 0; idx < points.Length; idx++)
            {
                // update envelope.
                if (_envelope == null)
                { // create initial envelope.
                    _envelope = new GeoCoordinateBox(points[idx], points[idx]);
                }
                // also include the current point.
                _envelope.ExpandWith(points[idx]);

                var projected =_projection.ToPixel(points[idx]);
                x[idx] = projected[0];
                y[idx] = projected[1];
            }

            uint? pointsId = _scene.AddPoints(x, y);
            if (pointsId.HasValue)
            {
                _scene.AddStyleLine(pointsId.Value, 0, float.MinValue, float.MaxValue, color, sizePixels, Renderer.Primitives.LineJoin.Round, null);
                this.RaiseLayerChanged();
            }
        }
Пример #30
0
        /// <summary>
        /// Adds a polyline.
        /// </summary>
        /// <param name="points"></param>
        /// <param name="color"></param>
        /// <param name="width"></param>
        /// <param name="fill"></param>
        /// <returns></returns>
        public void AddPolygon(GeoCoordinate[] points, int color, float width, bool fill)
        {
            var x = new double[points.Length];
            var y = new double[points.Length];
            for (int idx = 0; idx < points.Length; idx++)
            {
                // update envelope.
                if (_envelope == null)
                { // create initial envelope.
                    _envelope = new GeoCoordinateBox(points[idx], points[idx]);
                }
                // also include the current point.
                _envelope.ExpandWith(points[idx]);

                var projected = _projection.ToPixel(points[idx]);
                x[idx] = projected[0];
                y[idx] = projected[1];
            }

            var pointsId = _scene.AddPoints(x, y);
            if (pointsId.HasValue)
            {
                _scene.AddStylePolygon(pointsId.Value, 0, float.MinValue, float.MaxValue, color, width, fill);
                this.RaiseLayerChanged();
            }
        }
Пример #31
0
 public static double DistanceEstimateInMeter(ICoordinate location1, ICoordinate location2)
 {
     return(GeoCoordinate.DistanceEstimateInMeter((double)location1.Latitude, (double)location1.Longitude, (double)location2.Latitude, (double)location2.Longitude));
 }
Пример #32
0
 /// <summary>
 /// Creates a geo coordinate line.
 /// </summary>
 /// <param name="point1"></param>
 /// <param name="point2"></param>
 public GeoCoordinateLine(
     GeoCoordinate point1,
     GeoCoordinate point2)
     : base(point1, point2)
 {
 }
Пример #33
0
 /// <summary>
 /// Calculates the distance between this point and the given point.
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 public double Distance(GeoCoordinate point)
 {
     return(PointF2D.Distance(this, point));
 }
Пример #34
0
 public Meter DistanceEstimate(GeoCoordinate point)
 {
     return((Meter)GeoCoordinate.DistanceEstimateInMeter(this.Latitude, this.Longitude, point.Latitude, point.Longitude));
 }