Hi,
Is it possible to calculate Driving distance between two points when Latitude longitude of two points are provided?
thanks in advance
Regards,
Govind M. Kotkundwar
Hi,
Is it possible to calculate Driving distance between two points when Latitude longitude of two points are provided?
thanks in advance
Regards,
Govind M. Kotkundwar
govind,
Thank you using the Routing product, if you have installed routing How Do I Samples, you can find a sample named Get Shortest Path By Coordinates.
How Do I Samples-->Get Shortest Path By Coordinates.
If not, please have a look at the code below, I hope it can resolve your problem:
using System;
using System.Globalization;
using System.Windows.Forms;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.DesktopEdition;
using ThinkGeo.MapSuite.Routing;
namespace HowDoISamples
{
public class GetShortestPathByCoordinates : UserControl
{
public GetShortestPathByCoordinates()
{
InitializeComponent();
}
private void UserControl_Load(object sender, EventArgs e)
{
RenderMap();
}
private void btnRoute_Click(object sender, EventArgs e)
{
RoutingSource routingSource = new RtgRoutingSource(@"..\..\..\SampleData\Austinstreets.rtg");
ShapeFileFeatureSource featureSource = new ShapeFileFeatureSource(@"..\..\..\SampleData\Austinstreets.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 RenderMap()
{
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#e6e5d1"));
winformsMap1.CurrentExtent = new RectangleShape(-97.7489551588135, 30.3043988996582, -97.6854404493408, 30.2590802961426);
WorldMapKitWmsDesktopOverlay worldMapKitsOverlay = new WorldMapKitWmsDesktopOverlay();
winformsMap1.Overlays.Add(worldMapKitsOverlay);
ShapeFileFeatureLayer austinstreetsLayer = new ShapeFileFeatureLayer(@"..\..\..\SampleData\Austinstreets.shp");
austinstreetsLayer.Open();
string[] startCoordinates = txtStartCoordinate.Text.Split(',');
PointShape startPoint = new PointShape(double.Parse(startCoordinates[0], CultureInfo.InvariantCulture), double.Parse(startCoordinates[1], CultureInfo.InvariantCulture));
string[] endCoordinates = txtEndCoordinate.Text.Split(',');
PointShape endPoint = new PointShape(double.Parse(endCoordinates[0], CultureInfo.InvariantCulture), double.Parse(endCoordinates[1], CultureInfo.InvariantCulture));
RoutingLayer routingLayer = new RoutingLayer();
routingLayer.StartPoint = startPoint;
routingLayer.EndPoint = endPoint;
LayerOverlay routingOverlay = new LayerOverlay();
routingOverlay.Layers.Add("RoutingLayer", routingLayer);
winformsMap1.Overlays.Add("RoutingOverlay", routingOverlay);
InMemoryFeatureLayer routingExtentLayer = new InMemoryFeatureLayer();
routingExtentLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.SimpleColors.Green));
routingExtentLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
routingExtentLayer.InternalFeatures.Add(new Feature(new RectangleShape(-97.815409, 30.369949, -97.657999, 30.217922)));
routingOverlay.Layers.Add("RoutingExtentLayer", routingExtentLayer);
winformsMap1.Refresh();
}
}
}
Any more questions please feel free to let me know.
Regards,
Gary
Hi Gary,
where can i get the shape as well as rtg files for route throughout whole of America continent?
Because I have got a situation where the route have to be drawn in any part of The America and when ever the coordinate values exceeds i get an error saying out of bounds.
Regards,
Govind M. Koktundwar
govind,
You can build the rtg file of American, please see How Do I Samples–>Building Routing Data.
Regards,
Gary