protected override BaseShape CreateAccessibleAreaCore() { string rtgFilePathName = Path.ChangeExtension(StreetShapeFilePathName, ".rtg"); RtgRoutingSource routingSource = new RtgRoutingSource(rtgFilePathName); FeatureSource featureSource = new ShapeFileFeatureSource(StreetShapeFilePathName); RoutingEngine routingEngine = new RoutingEngine(routingSource, featureSource); if (!featureSource.IsOpen) { featureSource.Open(); } ManagedProj4Projection proj = new ManagedProj4Projection(); proj.InternalProjectionParametersString = ManagedProj4Projection.GetBingMapParametersString(); proj.ExternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(4326); proj.Open(); StartLocation = proj.ConvertToExternalProjection(StartLocation) as PointShape; Feature feature = featureSource.GetFeaturesNearestTo(StartLocation, GeographyUnit, 1, ReturningColumnsType.NoColumns)[0]; PolygonShape polygonShape = routingEngine.GenerateServiceArea(feature.Id, new TimeSpan(0, DrivingTimeInMinutes, 0), 100, GeographyUnit.Feet); polygonShape = proj.ConvertToInternalProjection(polygonShape) as PolygonShape; proj.Close(); return(polygonShape); }
private void btnRoute_Click(object sender, EventArgs e) { RtgRoutingSource routingSource = new RtgRoutingSource(@"..\..\SampleData\Austinstreets.rtg"); RoutingEngine routingEngine = new RoutingEngine(routingSource, featureSource); routingEngine.GeneratingServiceArea += new EventHandler <GeneratingServiceAreaRoutingEngineEventArgs>(routingEngine_GeneratingServiceArea); float averageSpeed = float.Parse(txtAverageSpeed.Text); int drivingMinutes = int.Parse(txtDrivingMinutes.Text); PolygonShape polygonShape = routingEngine.GenerateServiceArea(txtStartId.Text, new TimeSpan(0, drivingMinutes, 0), averageSpeed); InMemoryFeatureLayer routingLayer = (InMemoryFeatureLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"]; routingLayer.InternalFeatures.Remove("ServiceArea"); if (polygonShape.Validate(ShapeValidationMode.Simple).IsValid) { routingLayer.InternalFeatures.Add("ServiceArea", new Feature(polygonShape)); routingLayer.Open(); winformsMap1.CurrentExtent = routingLayer.GetBoundingBox(); routingLayer.Close(); } winformsMap1.Overlays["RoutingOverlay"].Lock.IsDirty = true; winformsMap1.Refresh(); }
private void Route() { RtgRoutingSource routingSource = new RtgRoutingSource(Path.Combine(rootPath, "DallasCounty-4326.shortest.rtg")); FeatureSource featureSource = new ShapeFileFeatureSource(Path.Combine(rootPath, "DallasCounty-4326.shp")); RoutingEngine routingEngine = new RoutingEngine(routingSource, featureSource); float averageSpeed = float.Parse(txtAverageSpeed.Text); int drivingMinutes = int.Parse(txtDrivingMinutes.Text); SpeedUnit speedUnit = GetSpeedUnit(); PolygonShape polygonShape = routingEngine.GenerateServiceArea(txtStartId.Text, new TimeSpan(0, drivingMinutes, 0), averageSpeed, speedUnit); InMemoryFeatureLayer routingLayer = (InMemoryFeatureLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"]; routingLayer.InternalFeatures.Remove("ServiceArea"); if (polygonShape.Validate(ShapeValidationMode.Simple).IsValid) { routingLayer.InternalFeatures.Add("ServiceArea", new Feature(polygonShape)); routingLayer.Open(); winformsMap1.CurrentExtent = routingLayer.GetBoundingBox(); routingLayer.Close(); } winformsMap1.Refresh(winformsMap1.Overlays["RoutingOverlay"]); }
public JsonResult SearchSimilarSites(Map map, GeoCollection <object> args) { string[] searchPointLatLng = args["searchPoint"].ToString().Split(','); PointShape searchPoint = new PointShape(double.Parse(searchPointLatLng[0]), double.Parse(searchPointLatLng[1])); object result = new { status = "2", message = "out of restriction area" }; Feature searchAreaFeature = null; // check if the clicked point is in valid area (Frisco City) FeatureLayer friscoLayer = (FeatureLayer)(map.CustomOverlays["RestrictOverlay"] as LayerOverlay).Layers["RestrictLayer"]; friscoLayer.Open(); if (friscoLayer.QueryTools.GetFeaturesContaining(searchPoint, ReturningColumnsType.NoColumns).Any()) { // Calculate the service area/buffer area and display it on the map if (args["searchMode"].ToString().Equals("serviceArea", StringComparison.InvariantCultureIgnoreCase)) { int drivingTimeInMinutes = Convert.ToInt32(args["driveTime"].ToString(), CultureInfo.InvariantCulture); searchAreaFeature = new Feature(routingEngine.GenerateServiceArea(searchPoint, new TimeSpan(0, drivingTimeInMinutes, 0), 100, GeographyUnit.Meter)); } else { DistanceUnit distanceUnit = args["distanceUnit"].ToString() == "Mile" ? DistanceUnit.Mile : DistanceUnit.Kilometer; double distanceBuffer = Convert.ToDouble(args["distanceBuffer"].ToString(), CultureInfo.InvariantCulture); searchAreaFeature = new Feature(searchPoint.Buffer(distanceBuffer, 40, GeographyUnit.Meter, distanceUnit)); } // Search the Pois in calculated service area and display them on map LayerOverlay poiOverlay = map.CustomOverlays["PoisOverlay"] as LayerOverlay; ShapeFileFeatureLayer poiLayer = (ShapeFileFeatureLayer)(poiOverlay.Layers[args["category"].ToString()]); poiLayer.Open(); Collection <Feature> featuresInServiceArea = poiLayer.QueryTools.GetFeaturesWithin(searchAreaFeature.GetShape(), ReturningColumnsType.AllColumns); List <Feature> filteredQueryFeatures = FilterFeaturesByQueryConfiguration(featuresInServiceArea, args["category"].ToString(), args["subCategory"].ToString().Replace(">~", ">=")); if (filteredQueryFeatures.Any()) { Collection <object> returnedJsonFeatures = new Collection <object>(); foreach (Feature feature in filteredQueryFeatures) { PointShape latlng = feature.GetShape() as PointShape; returnedJsonFeatures.Add(new { name = feature.ColumnValues["NAME"], point = string.Format("{0},{1}", latlng.Y, latlng.X) }); } // Add into plot marker overlay. InMemoryMarkerOverlay drawPointOverlay = map.CustomOverlays["DrawnPointOverlay"] as InMemoryMarkerOverlay; drawPointOverlay.FeatureSource.Clear(); drawPointOverlay.FeatureSource.BeginTransaction(); drawPointOverlay.FeatureSource.AddFeature(new Feature(searchPoint)); drawPointOverlay.FeatureSource.CommitTransaction(); // Add into markerOvelray. AddMarkers(filteredQueryFeatures, map); Feature wgs84Feature = new Feature(searchAreaFeature.GetShape()); // Add into queried overlay. LayerOverlay queriedOverlay = map.CustomOverlays["QueriedOverlay"] as LayerOverlay; InMemoryFeatureLayer serviceAreaLayer = (queriedOverlay.Layers["serviceArea"] as InMemoryFeatureLayer); serviceAreaLayer.Open(); serviceAreaLayer.InternalFeatures.Clear(); serviceAreaLayer.InternalFeatures.Add(wgs84Feature); result = new { status = "0", message = "has features", features = returnedJsonFeatures }; } else { result = new { status = "1", message = "without features" }; } } // return the search poi feature information to the client. return(Json(result)); }