Skip to content

Instantly share code, notes, and snippets.

@xivk
xivk / map.geojson
Created August 12, 2013 15:47
via:geojson.io
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xivk
xivk / gist:5e8b05ac5b303df04688
Created May 8, 2014 08:18
OsmSharp - Loading a routing flatfile
// for contracted files:
TagsCollectionBase metaTags;
var serializer = new OsmSharp.Routing.CH.Serialization.CHEdgeFlatfileSerializer();
var data = serializer.Deserialize(
new FileInfo(file_name_string_here).OpenRead(), out metaTags, false);
var router = Router.CreateCHFrom(data, new CHRouter(), interpreter);
// for regular files:
TagsCollectionBase metaTags;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
using Newtonsoft.Json;
using OsmSharp.Math.Geo;
using OsmSharp.Routing;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Newtonsoft.Json;
using OsmSharp.Math.Geo;
using OsmSharp.Routing;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Newtonsoft.Json;
using OsmSharp.Math.Geo;
using OsmSharp.Routing;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
Vehicle.RegisterVehicles();
var result = RoutingFacade.Calculate(Vehicle.Car,
new GeoCoordinate(-22.60101626185221, 17.081937789916992), new GeoCoordinate(-22.574389321905667, 17.07901954650879));
Console.WriteLine(result);
//var metrics = new TimeCalculator(new OsmRoutingInterpreter());
//metrics.Calculate(result);
var instructions = InstructionGenerator.Generate(result, new OsmRoutingInterpreter());
using OsmSharp.Collections.Tags;
using OsmSharp.Routing;
using OsmSharp.Routing.CH;
using OsmSharp.Routing.Osm.Interpreter;
using System.IO;
namespace ConsoleApplication2
{
class Program
{
var sourceStream = new PBFOsmStreamSource(
new FileInfo(@"path\to\file.osm.pbf").OpenRead());
var completeStreamSource = new OsmSimpleCompleteStreamSource(sourceStream);
foreach(var osmGeoComplete in completeStreamSource)
{
if(osmGeoComplete.Type == Osm.CompleteOsmType.Way &&
osmGeoComplete.Tags != null &&
osmGeoComplete.Tags.ContainsKey("highway"))
var sourceStream = new PBFOsmStreamSource(
new FileInfo(@"path\to\file.osm.pbf").OpenRead());
foreach(var osmGeo in sourceStream)
{
if(osmGeo.Type == Osm.OsmGeoType.Way &&
osmGeo.Tags != null &&
osmGeo.Tags.ContainsKey("highway"))
{
// do something with the road here.