This project has moved and is read-only. For the latest updates, please go here.

Distance between two cities using maps

Topics: Algorithms, CompactFramework, Data Access, Español, General Topics, Italiano, SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0, Web Controls, WinForms Controls
Mar 11, 2015 at 11:40 AM

Is it possible to calculate distance between two cities using Sharpmap?

I am trying to find a solution (using .NET/WPF) and Sharpmap that can calculate distance between point A and point B, but including information about country's border. I need this information in order to calculate the price of trip, as price per km in one country might be different from price per km in other country.

I want to calculate the number of miles a vehicles travel in each country over a period of time. For trips taken over the period, the user will create routes on the map, and the program should be able to generate some output like: Country A: 100 miles, Country B: 200 miles and Country C: 150 miles etc.

Mar 20, 2015 at 4:11 PM
Do you want the straight line distance? or the distance if travelled by road?
Mar 22, 2015 at 3:44 AM
I need distance travelled by road i.e. distance travelled on a road that lies in two different countries separated by a boundary line.
Mar 23, 2015 at 1:14 PM
Edited Mar 23, 2015 at 1:15 PM
Sth along these lines.
public System.Collections.Generic.IEnumerable<System.Tuple<SharpMap.Data.FeatureDataRow, double>> LengthInPolygon(
    GeoAPI.Geometries.IGeometry geom, 
    SharpMap.Data.Providers.IProvider provider)
    if (!geom == null)
        throw new System.ArgumentNullException("geom")
    if (!geom is GeoAPI.Geometries.ILineal)
        throw new System.ArgumentException("geom")
    if (provider == null)
        throw new System.ArgumentNullException("provider")
    var ds = new SharpMap.Data.FeatureDataSet();
    provider.ExecuteIntersectionQuery(geom, ds);

    if (ds.Tables.Count == 0)
        yield break;

    foreach(SharpMap.Data.FeatureDataRow row in ds.Tables.Rows) {
        var intGeom = geom.Intersection(row.Geometry);
        yield return System.Tuple.Create(row, intGeom.Length);