Exemple #1
0
        //private static System.Windows.Shapes.Polyline GetPolyline()
        //{
        //	string text = File.ReadAllText(@"C:\OSM\route.geojson");
        //	GeoJsonModel parsed = JsonConvert.DeserializeObject<GeoJsonModel>(text);
        //	var polyline = new System.Windows.Shapes.Polyline();
        //	foreach (Feature feature in parsed.features)
        //	{
        //		var startingCoordinates = feature.geometry.coordinates[0] as Newtonsoft.Json.Linq.JArray;
        //		//
        //		var startingPoint = new Point((float)startingCoordinates.Last(), (float)startingCoordinates.First());

        //		var endingCoordinates = feature.geometry.coordinates[1] as Newtonsoft.Json.Linq.JArray;
        //		//
        //		var endingPoint = new Point((float)endingCoordinates.Last(), (float)endingCoordinates.First());

        //		polyline.Points.Add(startingPoint);
        //		polyline.Points.Add(endingPoint);
        //	}

        //	return polyline;
        //}

        private static ViewModel.Polyline GetMapControlPolyLine()
        {
            string       text     = File.ReadAllText(@"C:\OSM\route.geojson");
            GeoJsonModel parsed   = JsonConvert.DeserializeObject <GeoJsonModel>(text);
            var          polyline = new ViewModel.Polyline();

            polyline.Locations = new MapControl.LocationCollection();
            foreach (Feature feature in parsed.features)
            {
                if (feature.geometry.coordinates[0] is Newtonsoft.Json.Linq.JArray startingCoordinates)
                {
                    polyline.Locations.Add(new MapControl.Location((float)startingCoordinates.Last(), (float)startingCoordinates.First()));
                }

                if (feature.geometry.coordinates[1] is Newtonsoft.Json.Linq.JArray endingCoordinates)
                {
                    polyline.Locations.Add(new MapControl.Location((float)endingCoordinates.Last(), (float)endingCoordinates.First()));
                }

                //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);
        }
Exemple #2
0
        private ViewModel.Polyline GetFromSqlGeometry(Microsoft.SqlServer.Types.SqlGeometry multiPoint)
        {
            var result = new ViewModel.Polyline()
            {
                Locations = new LocationCollection()
            };

            for (int i = 1; i <= multiPoint.STNumPoints(); i++)
            {
                Microsoft.SqlServer.Types.SqlGeometry point = multiPoint.STPointN(i);
                result.Locations.Add(new Location((double)point.STY, (double)point.STX));
            }
            return(result);
        }
Exemple #3
0
        private List <ViewModel.Polyline> GetFromSqlGeographies(Microsoft.SqlServer.Types.SqlGeography sqlGeography)
        {
            var result = new List <ViewModel.Polyline>();

            for (int i = 1; i <= (int)sqlGeography.STNumGeometries(); i++)
            {
                Microsoft.SqlServer.Types.SqlGeography geography = sqlGeography.STGeometryN(i);
                var polyline = new ViewModel.Polyline()
                {
                    Locations = new LocationCollection()
                };

                for (int j = 1; j <= geography.STNumPoints(); j++)
                {
                    Microsoft.SqlServer.Types.SqlGeography point = geography.STPointN(j);
                    polyline.Locations.Add(new Location((double)point.Lat, (double)point.Long));
                }
                result.Add(polyline);
            }

            return(result);
        }
Exemple #4
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);
        }
Exemple #5
0
 private void AddPolylineToMap(ViewModel.Polyline polyline)
 {
     (this.DataContext as MapViewModel).Polylines.Add(polyline);
 }