Esempio n. 1
0
        static void Main(string[] args)
        {
            var pos    = new GeoJSON.Net.Geometry.Position(59.264577437894914, 15.27211594029649);
            var kommun = WhereIsPoint(pos);

            Console.WriteLine($"{kommun.Name}, {kommun.Code}");
            Console.WriteLine("Done");
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
 private static GeoJSON.Net.Geometry.Position[] GetCoordinatesFromWarszawaToMlawa()
 {
     GeoJSON.Net.Geometry.Position   mlawa       = new GeoJSON.Net.Geometry.Position(53.112128, 20.383661);
     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);
     GeoJSON.Net.Geometry.Position[] coordinates = new GeoJSON.Net.Geometry.Position[3];
     coordinates[0] = warszawa;
     coordinates[1] = mlawa;
     coordinates[2] = szczecin;
     return(coordinates);
 }
Esempio n. 5
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);
        }
Esempio n. 6
0
        private static GeoJSON.Net.Geometry.Position[] GetManyCoordinatesForOptimalRoute()
        {
            List <GeoJSON.Net.Geometry.Position> coordinates = new List <GeoJSON.Net.Geometry.Position>();

            GeoJSON.Net.Geometry.Position bydgoszcz = new GeoJSON.Net.Geometry.Position(53.114519, 18.008936);
            GeoJSON.Net.Geometry.Position lodz      = new GeoJSON.Net.Geometry.Position(51.785124, 19.462234);
            GeoJSON.Net.Geometry.Position poznan    = new GeoJSON.Net.Geometry.Position(52.398515, 16.938702);
            GeoJSON.Net.Geometry.Position mlawa     = new GeoJSON.Net.Geometry.Position(53.112128, 20.383661);

            coordinates.Add(bydgoszcz);
            coordinates.Add(lodz);
            coordinates.Add(poznan);
            coordinates.Add(mlawa);

            return(coordinates.ToArray());
        }
Esempio n. 7
0
        private static GeoJSON.Net.Geometry.Position[] GetManyCoordinatesForNormalRoute()
        {
            List <GeoJSON.Net.Geometry.Position> coordinates = new List <GeoJSON.Net.Geometry.Position>();

            GeoJSON.Net.Geometry.Position warszawa  = new GeoJSON.Net.Geometry.Position(52.230320, 21.011132);
            GeoJSON.Net.Geometry.Position bydgoszcz = new GeoJSON.Net.Geometry.Position(53.114519, 18.008936);
            GeoJSON.Net.Geometry.Position lodz      = new GeoJSON.Net.Geometry.Position(51.785124, 19.462234);
            GeoJSON.Net.Geometry.Position poznan    = new GeoJSON.Net.Geometry.Position(52.398515, 16.938702);
            GeoJSON.Net.Geometry.Position mlawa     = new GeoJSON.Net.Geometry.Position(53.112128, 20.383661);
            GeoJSON.Net.Geometry.Position szczecin  = new GeoJSON.Net.Geometry.Position(53.421684, 14.561405);

            coordinates.Add(warszawa);
            coordinates.Add(bydgoszcz);
            coordinates.Add(lodz);
            coordinates.Add(poznan);
            coordinates.Add(mlawa);
            coordinates.Add(szczecin);

            return(coordinates.ToArray());
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
 /// <summary>
 /// Determines whether the specified <see cref="Position" />, is equal to this instance.
 /// </summary>
 /// <param name="other">The <see cref="Position" /> to compare with this instance.</param>
 /// <returns>
 ///   <c>true</c> if the specified <see cref="Position" /> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 protected bool Equals(Position other)
 {
     return Coordinates.SequenceEqual(other.Coordinates, DoubleComparer);
 }