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 winformsMap1_MapClick(object sender, MapClickWinformsMapEventArgs e) { if (isAddingRoadblocks) { featureSource.Open(); Collection <Feature> closestFeatures = featureSource.GetFeaturesNearestTo(e.WorldLocation, winformsMap1.MapUnit, 1, ReturningColumnsType.NoColumns); if (closestFeatures.Count > 0) { PointShape position = ((LineBaseShape)closestFeatures[0].GetShape()).GetCenterPoint(); Feature feature = new Feature(position.GetWellKnownBinary(), closestFeatures[0].Id); if (feature.Id != startFeature.Id && feature.Id != endFeature.Id) { roadblocksLayer.InternalFeatures.Add(feature); } LayerOverlay overlay = (LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]; winformsMap1.Refresh(overlay); } Route(); } }
private void winformsMap1_MapClick(object sender, MapClickWinformsMapEventArgs e) { // Select the nearest feature from route features LayerOverlay roadOverlay = (LayerOverlay)winformsMap1.Overlays["RoadsOverlay"]; if (isInEditMode) { featureSource.Open(); Collection <Feature> closestFeatures = featureSource.GetFeaturesNearestTo(e.WorldLocation, winformsMap1.MapUnit, 1, ReturningColumnsType.NoColumns); if (closestFeatures.Count > 0) { editFeature = closestFeatures[0]; routingSource.Open(); editRouteSegment = routingSource.GetRouteSegmentByFeatureId(editFeature.Id); RenderRouteSegmentInformation(roadOverlay); } } else if (routingSource.IsInTransaction) { EditRoutingData(e.WorldLocation, roadOverlay); } }
private void wpfMap1_MapClick(object sender, MapClickWpfMapEventArgs e) { try { //Uses the WrapDatelineProjection to create the target pointshape for GetFeatureNearestTo spatial query function. WrapDatelineProjection wrapDatelineProjection = new WrapDatelineProjection(); //Sets the HalfExtentWidth of the wrapdateline overlay we want to apply the projection on. //Here it is 180 because, the full extent width is 360. wrapDatelineProjection.HalfExtentWidth = wpfMap1.Overlays["WMK"].GetBoundingBox().Width / 2;//180; //Gets the valid world coordinate regardless to where the user click on the map wrapDatelineProjection.Open(); Vertex projVertex = wrapDatelineProjection.ConvertToExternalProjection(e.WorldX, e.WorldY); wrapDatelineProjection.Close(); //Here we just use the feature source of the shapefile because we don't display it, we just use it for doing the spatial query. ShapeFileFeatureSource shapeFileFeatureSource = new ShapeFileFeatureSource(@"../../data/countries02.shp"); shapeFileFeatureSource.Open(); //Uses the projected X and Y values for the Spatial Query. Collection <Feature> features = shapeFileFeatureSource.GetFeaturesNearestTo(new PointShape(projVertex), wpfMap1.MapUnit, 1, ReturningColumnsType.NoColumns); shapeFileFeatureSource.Close(); LayerOverlay dynamicOverlay = (LayerOverlay)wpfMap1.Overlays["DynamicOverlay"]; InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["SelectLayer"]; //Clears the InMemoryFeatureLayer and add the feature as the result of the spatial query. inMemoryFeatureLayer.Open(); inMemoryFeatureLayer.InternalFeatures.Clear(); inMemoryFeatureLayer.InternalFeatures.Add(features[0]); inMemoryFeatureLayer.Close(); //Refreshes only the overlay with the updated InMemoryFeatureLayer. wpfMap1.Refresh(dynamicOverlay); } catch { } }