Пример #1
0
        private List <long?> GetRouteMeetingConditionsAndPointIds(List <int> indexesOfDurationList, List <DbModel.LocalizationPointDto> pointsInsideIsochrone, double maxInnerDistance, double maxInnerTime, out RouteModel route)
        {
            var sortedPointsByDuration = new List <DbModel.LocalizationPointDto>();

            foreach (var index in indexesOfDurationList)
            {
                sortedPointsByDuration.Add(pointsInsideIsochrone.ElementAt(index));
            }

            bool doesRouteMeetParameters = false;

            route = null;
            while (!doesRouteMeetParameters)
            {
                var routeJson = OsrmAPIHelper.GetOptimalRoute(sortedPointsByDuration.Select(x => (Position)x.Point.Coordinates).ToArray());
                if (routeJson == null)
                {
                    route = null;
                    return(null);
                }
                route = routeJson.ToRouteModel();
                doesRouteMeetParameters = DoesInnerRouteMeetParameters(route, maxInnerDistance, maxInnerTime);
                if (!doesRouteMeetParameters)
                {
                    sortedPointsByDuration.RemoveAt(sortedPointsByDuration.Count() - 1);
                }
            }

            var pointIds = sortedPointsByDuration.Select(x => x.PointId).ToList();

            return(pointIds);
        }
Пример #2
0
        protected RouteModel GetRouteBetweenTwoPoints(List <Position> waypoints)
        {
            //var routeJson = MapboxAPIHelper.GetOptimalRoute(this.startingPosition, this.endingPositions, waypoints.ToArray());
            var routeJson = OsrmAPIHelper.GetOptimalRoute(this.startingPosition, this.endingPositions, waypoints.ToArray());

            return(routeJson.ToRouteModel());
        }
Пример #3
0
        private List <ViewModel.Polyline> GetDifferencePolyline()
        {
            GeoJSON.Net.Geometry.Position warszawa = new GeoJSON.Net.Geometry.Position(52.229941, 21.011105);
            GeoJSON.Net.Geometry.Position mlawa    = new GeoJSON.Net.Geometry.Position(53.112154, 20.382377);
            GeoJSON.Net.Geometry.Position plock    = new GeoJSON.Net.Geometry.Position(52.546665, 19.687432);
            OsrmJsonRouteModel            parsed   = OsrmAPIHelper.GetOptimalRoute(warszawa, mlawa);
            var route = parsed.ToRouteModel();

            var jsonNew  = OsrmAPIHelper.GetOptimalRoute(warszawa, mlawa, plock);
            var newRoute = jsonNew.ToRouteModel();

            //var oldRouteGMultiLineString = route.MultiLineString.ToSqlGeography();
            //var newRouteGMultiLineString = newRoute.MultiLineString.ToSqlGeography();
            //var difference = newRouteGMultiLineString.STDifference(oldRouteGMultiLineString);


            //var oldRouteG = route.LineString.ToSqlGeography();
            //var newRouteG = newRoute.LineString.ToSqlGeography().MakeValidIfInvalid();
            //string isValid = newRouteG.IsValidDetailed();
            //var difference = newRouteG.STDifference(oldRouteG);


            Microsoft.SqlServer.Types.SqlGeography oldRouteGeography = route.MultiPointGeoJsonNet.ToSqlGeography();
            Microsoft.SqlServer.Types.SqlGeography newRouteGeography = newRoute.MultiPointGeoJsonNet.ToSqlGeography();
            Microsoft.SqlServer.Types.SqlGeography bufferOld         = oldRouteGeography.STBuffer(1000);
            Microsoft.SqlServer.Types.SqlGeography bufferNew         = newRouteGeography.STBuffer(1000);
            var difference = bufferNew.STDifference(bufferOld);


            double diffArea = (double)difference.STArea();
            double oldArea  = (double)bufferOld.STArea();
            double newArea  = (double)bufferNew.STArea();

            double howDifferent = diffArea / oldArea;



            List <ViewModel.Polyline> lines = new List <ViewModel.Polyline>();
            //lines.Add(GetFromSqlGeography(oldRouteGeography));
            //lines.Add(GetFromSqlGeography(newRouteGeography));
            //lines.Add(GetFromSqlGeography(difference));
            //lines.Add(GetFromSqlGeography(bufferNew));
            //lines.Add(GetFromSqlGeography(bufferOld));
            //lines.Add(GetFromSqlGeography(oldRouteG));
            //lines.Add(GetFromSqlGeography(newRouteG));
            //lines.Add(GetFromSqlGeography(difference));
            //lines.Add(GetFromSqlGeography(newRouteGMultiLineString));
            //lines.Add(GetFromSqlGeography(oldRouteGMultiLineString));

            var polylines = GetFromSqlGeographies(difference);

            foreach (var line in polylines)
            {
                lines.Add(line);
            }

            return(lines);
        }
Пример #4
0
        private List <ViewModel.Polyline> GetBufferPolyline()
        {
            GeoJSON.Net.Geometry.Position pos1   = new GeoJSON.Net.Geometry.Position(52.218703, 21.005044);
            GeoJSON.Net.Geometry.Position pos2   = new GeoJSON.Net.Geometry.Position(54.182346, 16.189145);
            OsrmJsonRouteModel            parsed = OsrmAPIHelper.GetOptimalRoute(pos1, pos2);
            var route = parsed.ToRouteModel();

            Microsoft.SqlServer.Types.SqlGeography sqlGeography = route.MultiPointGeoJsonNet.ToSqlGeography();


            Microsoft.SqlServer.Types.SqlGeography buffer = sqlGeography.STBuffer(100000);


            List <ViewModel.Polyline> lines = new List <ViewModel.Polyline>();

            lines.Add(GetFromSqlGeography(sqlGeography));
            lines.Add(GetFromSqlGeography(buffer));

            return(lines);
        }
Пример #5
0
        private static ViewModel.Polyline GetMapControlPolyLineFromOsrmApi()
        {
            //OsrmJsonRouteModel parsed = APIHelpers.OsrmAPIHelper.GetRouteBetweenPoints(GetManyCoordinatesForNormalRoute());

            GeoJSON.Net.Geometry.Position warszawa = new GeoJSON.Net.Geometry.Position(52.230320, 21.011132);
            GeoJSON.Net.Geometry.Position szczecin = new GeoJSON.Net.Geometry.Position(53.421684, 14.561405);
            OsrmJsonRouteModel            parsed   = OsrmAPIHelper.GetOptimalRoute(warszawa, szczecin, GetManyCoordinatesForOptimalRoute());

            var polyline = new ViewModel.Polyline();

            polyline.Locations = new MapControl.LocationCollection();
            foreach (var coordinate in parsed.routes[0].geometry.coordinates)
            {
                polyline.Locations.Add(new MapControl.Location((float)coordinate[1], (float)coordinate[0]));

                //if (feature.geometry.coordinates[0] is double longitude && feature.geometry.coordinates[1] is double latitude)
                //{
                //	polyline.Locations.Add(new MapControl.Location(latitude, longitude));
                //}
            }

            return(polyline);
        }