Пример #1
0
        private static void OsrmTravelTimeTableUsage()
        {
            GeoJSON.Net.Geometry.Position mlawa           = new GeoJSON.Net.Geometry.Position(53.112128, 20.383661);
            GeoJSON.Net.Geometry.Position positionInside  = new GeoJSON.Net.Geometry.Position(53.125982, 20.358108);
            GeoJSON.Net.Geometry.Position positionOutside = new GeoJSON.Net.Geometry.Position(53.155378, 20.363038);

            OsrmAPIHelper.GetTravelTimesMatrix(mlawa, positionInside, positionOutside);
            MapboxAPIHelper.GetTravelTimesMatrix(mlawa, positionInside, positionOutside);
        }
Пример #2
0
        private static void MapboxAPIUsage()
        {
            GeoJSON.Net.Geometry.Position mlawa = new GeoJSON.Net.Geometry.Position(53.112128, 20.383661);
            var polygon = MapboxAPIHelper.GetIsochroneAsPolygon(mlawa, 10);

            GeoJSON.Net.Geometry.Position positionInside  = new GeoJSON.Net.Geometry.Position(53.125982, 20.358108);
            GeoJSON.Net.Geometry.Point    pointInside     = new GeoJSON.Net.Geometry.Point(positionInside);
            GeoJSON.Net.Geometry.Position positionOutside = new GeoJSON.Net.Geometry.Position(53.155378, 20.363038);
            GeoJSON.Net.Geometry.Point    pointOutside    = new GeoJSON.Net.Geometry.Point(positionOutside);

            bool inside  = GeometryUtils.CheckIfPointIsInsidePolygon(polygon, pointInside);
            bool outside = GeometryUtils.CheckIfPointIsInsidePolygon(polygon, pointOutside);
        }
Пример #3
0
        private void InsertAggregatedPointsToDb()
        {
            var repo       = new MockLocalizationPointRepositoryMazowieckie();
            var pointItems = GetPointsItemsFromRepo(repo);

            foreach (var pointItem in pointItems)
            {
                (this.DataContext as MapViewModel).Pushpins.Add(pointItem);
            }

            var points = repo.GetWithoutAggregated();

            for (int i = 0; i < points.Count(); i++)
            {
                if (points.ElementAt(i).ParentPointId != null || points.ElementAt(i).StaticScore != 0)
                {
                    continue;
                }

                var          isochrone             = MapboxAPIHelper.GetIsochroneAsPolygon((Position)points.ElementAt(i).Point.Coordinates, 15);
                SqlGeography isochroneSqlGeography = isochrone.ToSqlGeography().MakeValid();
                isochroneSqlGeography = GetCorrectlyOrientedGeography(isochroneSqlGeography);
                this.AddPolylineToMap(GetFromSqlGeography(isochroneSqlGeography));

                // take points that are not parent or child points in aggregation
                var pointsWithoutParentPoint = points.Where(i => i.ParentPointId == null && i.StaticScore == 0).ToList();
                var pointsInsideIsochrone    = pointsWithoutParentPoint.Where(i => (bool)isochroneSqlGeography.STContains(i.Point.ToSqlGeography())).ToList();
                if (pointsInsideIsochrone.Count() > 1)
                {
                    var positionsInsideIsochrone       = pointsInsideIsochrone.Where(x => x.PointId != points.ElementAt(i).PointId).Select(x => (Position)x.Point.Coordinates).ToArray();
                    var travelTimesMatrixModel         = OsrmAPIHelper.GetTravelTimesMatrix((Position)points.ElementAt(i).Point.Coordinates, positionsInsideIsochrone);
                    var durationsList                  = travelTimesMatrixModel.durations[0].ToList();
                    var durationsListSortedWithIndexes = durationsList.Select((x, index) => new KeyValuePair <int, float>(index, x)).OrderBy(x => x.Value).ToList();

                    // get route that innerdistance and time is no longer than 30min and x? km
                    RouteModel resultRoute;
                    double     maxInnerDistance = 30 * 1000;
                    double     maxInnerTime     = 15 * 60;
                    var        pointIds         = GetRouteMeetingConditionsAndPointIds(durationsListSortedWithIndexes.Select(x => x.Key).ToList(), pointsInsideIsochrone, maxInnerDistance, maxInnerTime, out resultRoute);

                    if (pointIds != null)
                    {
                        // Create aggregated point
                        var aggregatedPoint = GetAggregatedPoint(pointIds, pointsWithoutParentPoint, resultRoute.Distance, resultRoute.Time);
                        points.Add(aggregatedPoint);
                        // Update parentId for child points
                        var updatedPoints = GetUpdatedChildPointsWithParentId(pointIds, ref points, aggregatedPoint.PointId);
                    }
                }
            }
        }
Пример #4
0
        private static void InsertAggregatedPointsToDb()
        {
            var repo = new LocalizationPointRepository();
            List <LocalizationPointDto> points = repo.GetWithoutAggregated();
            var mappedPointsIds = new HashSet <long>();

            foreach (LocalizationPointDto dbPoint in points)
            {
                if (dbPoint.ParentPointId != null || dbPoint.StaticScore != 0 || mappedPointsIds.Contains(dbPoint.PointId.Value))
                {
                    continue;
                }

                Polygon      isochrone             = MapboxAPIHelper.GetIsochroneAsPolygon((Position)dbPoint.Point.Coordinates, 15);
                SqlGeography isochroneSqlGeography = isochrone.ToSqlGeography().MakeValid();
                isochroneSqlGeography = GetCorrectlyOrientedGeography(isochroneSqlGeography);

                // take points that are not parent or child points in aggregation
                var pointsWithoutParentPoint = points.Where(i => i.ParentPointId == null && i.StaticScore == 0 && !mappedPointsIds.Contains(i.PointId.Value)).ToList();
                var pointsInsideIsochrone    = pointsWithoutParentPoint.Where(i => (bool)isochroneSqlGeography.STContains(i.Point.ToSqlGeography())).ToList();
                if (pointsInsideIsochrone.Count > 1)
                {
                    Position[] positionsInsideIsochrone = pointsInsideIsochrone.Where(x => x.PointId != dbPoint.PointId).Select(x => (Position)x.Point.Coordinates).ToArray();

                    TravelTimesMatrixModel travelTimesMatrixModel = OsrmAPIHelper.GetTravelTimesMatrix((Position)dbPoint.Point.Coordinates, positionsInsideIsochrone);
                    var durationsList = travelTimesMatrixModel.durations != null ? travelTimesMatrixModel.durations[0].ToList() : new List <float>();
                    var durationsListSortedWithIndexes = durationsList.Select((x, index) => new KeyValuePair <int, float>(index, x)).OrderBy(x => x.Value).ToList();

                    // get route that innerdistance and time is no longer than 30min and x? km
                    double       maxInnerDistance = 30 * 1000;
                    double       maxInnerTime     = 15 * 60;
                    List <long?> pointIds         = GetRouteMeetingConditionsAndPointIds(durationsListSortedWithIndexes.Select(x => x.Key).ToList(), pointsInsideIsochrone, maxInnerDistance, maxInnerTime, out RouteModel resultRoute);

                    if (pointIds != null)
                    {
                        pointsInsideIsochrone.ForEach(i => mappedPointsIds.Add(i.PointId.Value));

                        // Create aggregated point
                        LocalizationPointDto aggregatedPoint = GetAggregatedPoint(pointIds, pointsWithoutParentPoint, resultRoute.Distance, resultRoute.Time);
                        LocalizationPointDto addedPoint      = repo.Add(aggregatedPoint);

                        // Update parentId for child points
                        List <LocalizationPointDto> updatedPoints = GetUpdatedChildPointsWithParentId(pointIds, points, addedPoint.PointId);
                        foreach (LocalizationPointDto point in updatedPoints)
                        {
                            repo.Update(point);
                        }
                    }
                }
            }
        }