NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Hi,

I've downloaded my regional map from http://download.geofabrik.de/ and now I only want to calculate distance between two point (coordinates) using C#

I've read about BruTile and OSM, but I've no found any piece of code which implements my needs.

Map Rendering is not necessary for me, duration either. I mean, input: two coordinates, output: XX KM. That's all.

Could anybody please help me?

Thanks in advance.

asked 29 Jun '15, 10:01

doShare's gravatar image

doShare
11112
accept rate: 0%

edited 29 Jun '15, 10:15

scai's gravatar image

scai ♦
33.3k21309459

Hi again,

I've found a solution consisting in import map to mySQL:

I also have installed: MySQL and PERL

The instructions are not clear for me...I dont know how to, import my .osm/.osm.bz2 maps into MySQL and, moreover, how to test distances/routes between two coordinates...

I have installed all the packages into Perl Package Manager, but i am not sure that my installation was fine.

Thanks in advance

(30 Jun '15, 16:33) doShare

That's a completely different question. And why would you want to use MySQL instead of PostgreSQL? There are dozens of instructions for how to import OSM data into a PostgreSQL database. Don't choose a different database unless you have very good reasons for this decision.

(30 Jun '15, 20:03) scai ♦

Thanks,

Maybe the question sounds different, but my goal is the same: Obtain real distance (route) between two points offline using OSM. Firstly, I've tried with .NET c# but, because the map size (arround 400MB) the solution doesnt work. So, I am trying to obtain results migrating the map into DataBase. I've tried with mySQL because my .NET application runs over MySQL but, if PostgreSQL is easier, I will look for information / how to. Any suggestion?

Thanks in advance

(01 Jul '15, 07:44) doShare
2

If OsmSharp can't handle large maps then you could think about installing a separate routing service, such as GraphHopper or OSRM.

(01 Jul '15, 08:02) scai ♦

I thought it was Postgis which is Postgres + a GIS extension. The latter provides functionality to work with point, lines and areas.

(01 Jul '15, 12:38) escada
2

Thanks for your help. I've implemented my .NET Solution with GraphHopper. Now, I'm looking for an option to avoid running Terminal Cygwin64 permanently (It starts a local map website)

(02 Jul '15, 12:27) doShare
showing 5 of 6 show 1 more comments

I was able to get a result in meters from the code below... however, it took 3.5 minutes to calculate the distance between two points that are 12357 meters apart.

I used the osm.pbf for Oklahoma that is 116mb.

Install VS 2012, Install NuGet Extension, Install OSMSharp via NuGet. Start a new windows app for C#:

using OsmSharp.Osm.PBF.Streams;
using OsmSharp.Routing.Osm.Interpreter;
using OsmSharp.Routing.TSP.Genetic;
using OsmSharp.Math.Geo;
using OsmSharp.Routing;

using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            var frCoord = new GeoCoordinate(35.5275684, -97.5691736);
            var toCoord = new GeoCoordinate(35.5575105, -97.6740397);
            var f = new FileInfo("C:\\OSM\\oklahoma-latest\\oklahoma-latest.osm.pbf").OpenRead();
            var p = new PBFOsmStreamSource(f);
            var ri = new OsmRoutingInterpreter();

            var router = Router.CreateLiveFrom(p, ri);

            var resolved1 = router.Resolve(Vehicle.Car, frCoord);
            var resolved2 = router.Resolve(Vehicle.Car, toCoord);

            var route = router.Calculate(Vehicle.Car, resolved1, resolved2);

            label1.Text= Convert.ToString(route.TotalDistance);
        }


    }
}
permanent link

answered 20 Apr '16, 19:22

kttii's gravatar image

kttii
161
accept rate: 0%

edited 20 Apr '16, 19:36

Did you already read the routing wiki page? It even mentions some tools for C#, for example OsmSharp.

permanent link

answered 29 Jun '15, 10:14

scai's gravatar image

scai ♦
33.3k21309459
accept rate: 23%

edited 29 Jun '15, 10:15

Hi,

Now, i am testing https://github.com/OsmSharp/OsmSharp/wiki/A-getting-started-example but, because my map size is about 500MB it fails (memory exception).

I am also trying "https://github.com/OsmSharp/OsmSharpDataProcessor/wiki" but I can't do anything with it...

(29 Jun '15, 11:02) doShare
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×305
×106
×63
×25
×8

question asked: 29 Jun '15, 10:01

question was seen: 15,026 times

last updated: 20 Apr '16, 19:36

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum