private void Route() { FeatureSource featureSource = new ShapeFileFeatureSource(Path.Combine(rootPath, "DallasCounty-4326.shp")); RoutingSource routingSource = new RtgRoutingSource(Path.Combine(rootPath, "DallasCounty-4326.shortest.rtg")); RoutingEngine routingEngine = new RoutingEngine(routingSource, featureSource); RoutingLayer routingLayer = (RoutingLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"]; Collection <LineShape> paths = new Collection <LineShape>(); if (cbxAddStop.Checked) { paths.Add(routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.StopPoints[0]).Route); paths.Add(routingEngine.GetRoute(routingLayer.StopPoints[0], routingLayer.EndPoint).Route); } else { paths.Add(routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.EndPoint).Route); } RoutingLayer inmemoryLayer = (RoutingLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"]; inmemoryLayer.Routes.Clear(); foreach (LineShape item in paths) { inmemoryLayer.Routes.Add(item); } }
private void MapViewMapSingleTap(object sender, UIGestureRecognizer e) { CGPoint location = e.LocationInView(View); PointShape position = ExtentHelper.ToWorldCoordinate(mapView.CurrentExtent, (float)location.X, (float)location.Y, (float)View.Frame.Width, (float)View.Frame.Height); routingLayer.Routes.Clear(); if (firstClick) { routingLayer.StartPoint = position; firstClick = false; } else { routingLayer.EndPoint = position; firstClick = true; } routingLayer.Routes.Clear(); if (routingLayer.StartPoint != null && routingLayer.EndPoint != null) { RoutingResult routingResult = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.EndPoint); routingLayer.Routes.Add(routingResult.Route); ShowTurnByTurnDirections(routingResult.RouteSegments, routingResult.Features); } layerOverlay.Refresh(); }
private void btnFindBestRoute_Click(object sender, EventArgs e) { LayerOverlay overlay = (LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]; RoutingLayer routingLayer = (RoutingLayer)overlay.Layers["RoutingLayer"]; Stopwatch watch = new Stopwatch(); watch.Start(); RoutingResult routingResult = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.StopPoints, int.Parse(txtIterations.Text)); watch.Stop(); // Render the route routingLayer.Routes.Clear(); routingLayer.Routes.Add(routingResult.Route); winformsMap1.Refresh(winformsMap1.Overlays["RoutingOverlay"]); routingLayer.StopPoints.Clear(); foreach (PointShape stop in routingResult.OrderedStops) { routingLayer.StopPoints.Add(stop); } routingLayer.ShowStopOrder = true; txtTimeUsed.Text = watch.ElapsedMilliseconds.ToString(CultureInfo.InvariantCulture) + " ms"; txtDistance.Text = routingResult.Distance.ToString(CultureInfo.InvariantCulture); winformsMap1.Refresh(overlay); }
private void FindPath() { RoutingLayer routingLayer = (RoutingLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"]; routingLayer.Routes.Clear(); routingLayer.Routes.Add(routingEngine.GetRoute(txtStartId.Text, txtEndId.Text).Route); winformsMap1.Refresh(winformsMap1.Overlays["RoutingOverlay"]); }
private void ShowTheShortestPath(RoutingLayer routingLayer) { RoutingSource routingSource = new RtgRoutingSource(Path.Combine(rootPath, "DallasWithOneWayRoad.rtg")); RoutingEngine routingEngine = new RoutingEngine(routingSource, featureSource); RoutingResult routingResult = routingEngine.GetRoute(txtStartId.Text, txtEndId.Text); routingLayer.Routes.Clear(); routingLayer.Routes.Add(routingResult.Route); }
private void RenderPathBetweenPoints() { FeatureSource featureSource = new ShapeFileFeatureSource(@"..\..\SampleData\Austinstreets.shp"); RoutingSource routingSource = new RtgRoutingSource(@"..\..\SampleData\Austinstreets.rtg"); RoutingEngine routingEngine = new RoutingEngine(routingSource, featureSource); RoutingResult routingResult = null; InMemoryFeatureLayer stopLayer = (InMemoryFeatureLayer)((LayerOverlay)winformsMap1.Overlays["StopOverlay"]).Layers["StopLayer"]; if (stopLayer.InternalFeatures.Count > 2) { string startId = stopLayer.InternalFeatures[0].Id; string stopId = stopLayer.InternalFeatures[1].Id; string endId = stopLayer.InternalFeatures[2].Id; routingResult = routingEngine.GetRoute(startId, stopId); RoutingResult secondRoutingResult = routingEngine.GetRoute(stopId, endId); foreach (Feature item in secondRoutingResult.Features) { routingResult.Features.Add(item); } } else { routingResult = routingEngine.GetRoute("4716", "9638"); } //winformsMap1.Overlays["RoutingOverlay"].Lock.EnterWriteLock(); //try //{ InMemoryFeatureLayer inmemoryLayer = (InMemoryFeatureLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"]; inmemoryLayer.InternalFeatures.Clear(); foreach (Feature feature in routingResult.Features) { inmemoryLayer.InternalFeatures.Add(feature); } //} //finally //{ // winformsMap1.Overlays["RoutingOverlay"].Lock.ExitWriteLock(); //} winformsMap1.Overlays["RoutingOverlay"].Lock.IsDirty = true; winformsMap1.Refresh(); }
private void btnFindPath_Click(object sender, EventArgs e) { routingEngine.RoutingSource = routingSource; routingLayer.Routes.Clear(); routingEngine.RoutingSource.Open(); routingResult = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.EndPoint); routingLayer.Routes.Add(routingResult.Route); winformsMap1.Refresh(winformsMap1.Overlays["RoutingOverlay"]); }
void cbmPrioritiy_SelectedIndexChanged(object sender, EventArgs e) { RoutingResult routingResult = routingEngine.GetRoute(txtStartId.Text, txtEndId.Text); RoutingLayer routingLayer = (RoutingLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"]; routingLayer.Routes.Clear(); routingLayer.Routes.Add(routingResult.Route); winformsMap1.CurrentExtent = new RectangleShape(-96.905564, 32.926216, -96.651506, 32.744942); winformsMap1.Refresh(winformsMap1.Overlays["RoutingOverlay"]); }
void cbmAlgorithm_SelectedIndexChanged(object sender, EventArgs e) { FeatureSource featureSource = new ShapeFileFeatureSource(Path.Combine(rootPath, "DallasCounty-4326.shp")); RoutingSource routingSource = new RtgRoutingSource(Path.Combine(rootPath, "DallasCounty-4326.shortest.rtg")); RoutingEngine routingEngine = new RoutingEngine(routingSource, GetAlgorithm(), featureSource); RoutingResult routingResult = routingEngine.GetRoute(txtStartId.Text, txtEndId.Text); RoutingLayer routingLayer = (RoutingLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"]; routingLayer.Routes.Clear(); routingLayer.Routes.Add(routingResult.Route); winformsMap1.Refresh(winformsMap1.Overlays["RoutingOverlay"]); }
private void btnRoute_Click(object sender, EventArgs e) { RoutingSource routingSource = new RtgRoutingSource(Path.Combine(rootPath, "DallasCounty-4326.shortest.rtg")); ShapeFileFeatureSource featureSource = new ShapeFileFeatureSource(Path.Combine(rootPath, "DallasCounty-4326.shp")); RoutingEngine routingEngine = new RoutingEngine(routingSource, featureSource); RoutingLayer routingLayer = (RoutingLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"]; RoutingResult routingResult = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.EndPoint); routingLayer.Routes.Clear(); routingLayer.Routes.Add(routingResult.Route); winformsMap1.Refresh(winformsMap1.Overlays["RoutingOverlay"]); }
private void btnRoute_Click(object sender, EventArgs e) { ShapeFileFeatureSource featureSource = new ShapeFileFeatureSource(Path.Combine(rootPath, "DallasCounty-4326.shp")); RoutingSource routingSource = new CustomRoutingSource(featureSource); RoutingEngine routingEngine = new RoutingEngine(routingSource, featureSource); RoutingResult routingResult = routingEngine.GetRoute(txtStartId.Text, txtEndId.Text); RoutingLayer routingLayer = (RoutingLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"]; routingLayer.Routes.Clear(); routingLayer.Routes.Add(routingResult.Route); winformsMap1.Refresh(winformsMap1.Overlays["RoutingOverlay"]); }
private void btnRoute_Click(object sender, EventArgs e) { RoutingSource routingSource = new RtgRoutingSource(@"..\..\SampleData\AustinStreetFromOleDb.rtg"); RoutingEngine routingEngine = new RoutingEngine(routingSource, new DijkstraRoutingAlgorithm(), featureSource); RoutingResult routingResult = routingEngine.GetRoute(txtStartId.Text, txtEndId.Text); RoutingLayer routingLayer = (RoutingLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"]; winformsMap1.Overlays["RoutingOverlay"].Lock.EnterWriteLock(); try { routingLayer.Routes.Clear(); routingLayer.Routes.Add(routingResult.Route); } finally { winformsMap1.Overlays["RoutingOverlay"].Lock.ExitWriteLock(); } winformsMap1.Refresh(); }
private void btnRoute_Click(object sender, EventArgs e) { RoutingLayer routingLayer = (RoutingLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"]; routingLayer.Routes.Clear(); routingLayer.Routes.Add(routingEngine.GetRoute(txtStartId.Text, txtEndId.Text).Route); InMemoryFeatureLayer POIsOnRouteLayer = new InMemoryFeatureLayer(); MemoryStream stream = new MemoryStream(); Properties.Resources.Gas_Station.Save(stream, ImageFormat.Png); POIsOnRouteLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(new GeoImage(stream)); POIsOnRouteLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; LayerOverlay POIsOnRouteOverlay = new LayerOverlay(); POIsOnRouteOverlay.Layers.Add(POIsOnRouteLayer); winformsMap1.Overlays.Add(POIsOnRouteOverlay); ShapeFileFeatureLayer poiLayer = (ShapeFileFeatureLayer)((LayerOverlay)winformsMap1.Overlays["POIoverlay"]).Layers["POIlayer"]; poiLayer.Open(); Collection <Feature> features = poiLayer.QueryTools.GetFeaturesWithinDistanceOf(routingLayer.Routes[0], GeographyUnit.DecimalDegree, DistanceUnit.Meter, 100, ReturningColumnsType.NoColumns); poiLayer.Close(); POIsOnRouteLayer.Open(); POIsOnRouteLayer.EditTools.BeginTransaction(); foreach (Feature feature in features) { POIsOnRouteLayer.EditTools.Add(feature); } POIsOnRouteLayer.EditTools.CommitTransaction(); POIsOnRouteLayer.Close(); winformsMap1.Refresh(winformsMap1.Overlays["RoutingOverlay"]); }
private void MapView_SingleTap(object sender, SingleTapMapViewEventArgs e) { routingLayer.Routes.Clear(); if (firstClick) { routingLayer.StartPoint = e.WorldPoint; firstClick = false; } else { routingLayer.EndPoint = e.WorldPoint; firstClick = true; } routingLayer.Routes.Clear(); if (routingLayer.StartPoint != null && routingLayer.EndPoint != null) { RoutingResult routingResult = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.EndPoint); routingLayer.Routes.Add(routingResult.Route); ShowTurnByTurnDirections(routingResult.RouteSegments, routingResult.Features); } layerOverlay.Refresh(); }
private void Route() { RoutingLayer routingLayer = (RoutingLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"]; avoidableFeatureIds.Clear(); foreach (Feature feature in roadblocksLayer.InternalFeatures) { avoidableFeatureIds.Add(feature.Id); } routingLayer.Routes.Clear(); RoutingResult routingResult = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.EndPoint); if (routingResult.Features.Count == 0) { MessageBox.Show("No route exists!"); } else { routingLayer.Routes.Add(routingResult.Route); } winformsMap1.Refresh(winformsMap1.Overlays["RoutingOverlay"]); }