コード例 #1
0
        /// <summary>
        /// Bootstraps this service.
        /// </summary>
        public static void Start(string dataPath)
        {
            Bootstrapper.DataPath = dataPath;

            Bootstrapper.GetData = (stream, box, file) =>
            {
                var fullFilePath = Path.Combine(dataPath, file);
                if (!File.Exists(fullFilePath))
                {
                    throw new FileNotFoundException();
                }
                using (var inputStream = File.Open(fullFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    OsmStreamSource source;
                    if (fullFilePath.EndsWith("osm"))
                    {
                        source = new XmlOsmStreamSource(inputStream);
                    }
                    else if (fullFilePath.EndsWith("osm.pbf"))
                    {
                        source = new PBFOsmStreamSource(inputStream);
                    }
                    else
                    {
                        throw new NotSupportedException("File need to be an OSM-XML or OSM-PBF file.");
                    }

                    var filtered = source.FilterBox(box.Left, box.Top, box.Right, box.Bottom, true);

                    var target = new XmlOsmStreamTarget(stream);
                    target.RegisterSource(filtered);
                    target.Pull();
                }
            };
        }
コード例 #2
0
ファイル: LoadMapNodes.cs プロジェクト: beniamingolda/GenAlg
        public List <Node> LoadTrafficLights()
        {
            var returningColection = new List <Node>();

            using (var fileStream = File.OpenRead(Variables.FILE_NAME))
            {
                var src   = new PBFOsmStreamSource(fileStream).FilterBox((float)minMapPoint.X, (float)maxMapPoint.Y, (float)maxMapPoint.X, (float)minMapPoint.Y);
                var nodes = from osmGeo in src
                            where osmGeo.Tags != null && (osmGeo.Tags.Contains("crossing", "traffic_signals") || osmGeo.Tags.Contains("highway", "traffic_signals"))
                            select osmGeo;
                foreach (var node in nodes)
                {
                    if (node.Type == OsmGeoType.Node)
                    {
                        returningColection.Add((Node)node);
                        if (!allNodes.ContainsKey((long)node.Id))
                        {
                            allNodes.Add((long)node.Id, (Node)node);
                        }

                        //SimulationManager.trafficSignalsIds.Add((long)node.Id);
                    }
                }
            }
            return(returningColection);
        }
コード例 #3
0
        public void AddLayerOsm(Stream stream, Stream cssStream)
        {
            if (stream == null)
            {
                return;
            }

            // Create the MapCSS image source, which is used as image source for areas of the map
            var imageSource = new MapCSSDictionaryImageSource();

            // Load mapcss style interpreter.
            var mapCSSInterpreter = new MapCSSInterpreter(cssStream, imageSource);

            // Load data from pbf file into a memory data source
            var input = new PBFOsmStreamSource(stream);
            //var filter = new OsmStreamFilterBoundingBox(mapView.MapBoundingBox);
            //filter.RegisterSource(input);
            //var source = MemoryDataSource.CreateFromPBFStream(input);
            var source = MemoryDataSource.CreateFrom(input);

            //var source = new MemoryDataSource();

            // If there is allready a layer with map, close it
            if (layerMap != null)
            {
                layerMap.Close();
            }

            tileUrl = "";

            // Add new map layer
            layerMap = map?.AddLayerOsm(source, mapCSSInterpreter);
        }
コード例 #4
0
        /// <summary>
        /// Tests read/write and actual data file.
        /// </summary>
        protected void TestReadWriteData()
        {
            this.NotifyEmptyExpected(); // empty test database.

            // create the target and pull the data from the test-file into the sqlite database.
            OsmStreamTarget    target = this.CreateDataStreamTarget();
            PBFOsmStreamSource source = new PBFOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Data.Test.Unittests.Data.Osm.test.osm.pbf"));

            target.RegisterSource(source);
            target.Pull();

            IDataSourceReadOnly dataSource   = this.CreateDataSource();
            MemoryDataSource    memorySource = MemoryDataSource.CreateFrom(source);

            foreach (Node node in memorySource.GetNodes())
            {
                Node dbNode = dataSource.GetNode(node.Id.Value);
                this.CompareNodes(node, dbNode);
            }
            foreach (Way way in memorySource.GetWays())
            {
                Way dbWay = dataSource.GetWay(way.Id.Value);
                this.CompareWays(way, dbWay);
            }
            foreach (Relation relation in memorySource.GetRelations())
            {
                Relation dbRelation = dataSource.GetRelation(relation.Id.Value);
                this.CompareRelations(relation, dbRelation);
            }
        }
コード例 #5
0
ファイル: Parser.cs プロジェクト: zlant/milestones-parser
        public void ReadPbfFile(string path)
        {
            FileInfo pbfile = new FileInfo(path);

            using (FileStream fileStream = pbfile.OpenRead())
                using (PBFOsmStreamSource reader = new PBFOsmStreamSource(fileStream))
                {
                    foreach (var geo in reader)
                    {
                        if (geo.Id.HasValue)
                        {
                            if (i++ == 1000000)
                            {
                                Console.Write(100 * fileStream.Position / fileStream.Length + " % ");
                                Console.CursorLeft = 0;
                                i = 0;
                            }

                            ParseOsmGeo(geo);
                        }
                    }
                }


            Validate();
        }
コード例 #6
0
        private async Task <IEnumerable <OsmGeo> > SeutMap()
        {
            var mapPath    = string.Format("{0}\\Maps\\sweden.osm.pbf", AppDomain.CurrentDomain.BaseDirectory);
            var returnList = new List <OsmGeo>();

            using (var fileStream = File.OpenRead(mapPath))
            {
                // create source stream.
                var source = new PBFOsmStreamSource(fileStream);

                // filter all powerlines and keep all nodes.
                var filtered = from osmGeo in source
                               where osmGeo.Type == OsmSharp.OsmGeoType.Node ||
                               (osmGeo.Type == OsmSharp.OsmGeoType.Way && osmGeo.Tags != null && osmGeo.Tags.Contains("power", "line"))
                               select osmGeo;

                // convert to complete stream.
                // WARNING: nodes that are partof powerlines will be kept in-memory.
                //          it's important to filter only the objects you need **before**
                //          you convert to a complete stream otherwise all objects will
                //          be kept in-memory.
                var complete = filtered.ToComplete();
                returnList = filtered as List <OsmGeo>;
            }
            return(returnList);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: OsmSharp/core
        static async Task Main(string[] args)
        {
            await Download.ToFile("http://planet.anyways.eu/planet/europe/luxembourg/luxembourg-latest.osm.pbf", "luxembourg-latest.osm.pbf");

            await using var fileStream = File.OpenRead("luxembourg-latest.osm.pbf");

            // create source stream.
            var source = new PBFOsmStreamSource(fileStream);

            // filter all power lines and keep all nodes.
            var filtered = from osmGeo in source
                           where osmGeo.Type == OsmSharp.OsmGeoType.Node ||
                           (osmGeo.Type == OsmSharp.OsmGeoType.Way && osmGeo.Tags != null && osmGeo.Tags.Contains("power", "line"))
                           select osmGeo;

            // convert to complete stream.
            // WARNING: nodes that are part of power lines will be kept in-memory.
            //          it's important to filter only the objects you need **before**
            //          you convert to a complete stream otherwise all objects will
            //          be kept in-memory.
            var complete = filtered.ToComplete();

            // enumerate result.
            foreach (var osmGeo in complete)
            {
                if (osmGeo.Type == OsmSharp.OsmGeoType.Way)
                { // the nodes are still in the stream, we need them to construct the 'complete' objects.
                    Console.WriteLine(osmGeo.ToString());
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// Tests interpreting all data from a given pbf source.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="scene"></param>
        /// <param name="interpreter"></param>
        /// <param name="pbfSource"></param>
        public static Stream TestInterpret(string name, MapCSSInterpreter interpreter, Scene2D scene, string pbfSource)
        {
            StyleOsmStreamSceneTarget target = new StyleOsmStreamSceneTarget(
                interpreter, scene, new WebMercator());
            FileInfo                testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfSource));
            Stream                  stream   = testFile.OpenRead();
            OsmStreamSource         source   = new PBFOsmStreamSource(stream);
            OsmStreamFilterProgress progress = new OsmStreamFilterProgress();

            progress.RegisterSource(source);
            target.RegisterSource(progress);

            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Add", name));

            performanceInfo.Start();
            performanceInfo.Report("Interpreting style with objects from {0}...", pbfSource.ToString());

            target.Pull();

            performanceInfo.Stop();

            Console.Write("", scene.BackColor);
            stream.Dispose();

            return(testFile.OpenRead());
        }
コード例 #9
0
        static void Main(string[] args)
        {
            // enable logging and use the console as output.
            OsmSharp.Logging.Log.Enable();
            OsmSharp.Logging.Log.RegisterListener(
                new OsmSharp.WinForms.UI.Logging.ConsoleTraceListener());

            // create router.
            using (var source = new FileInfo(@"kempen.osm.pbf").OpenRead())
            {
                var pbfSource = new PBFOsmStreamSource(source);
                var progress  = new OsmStreamFilterProgress();
                progress.RegisterSource(pbfSource);
                var router = Router.CreateCHFrom(progress, new OsmRoutingInterpreter(), Vehicle.Car);

                OsmSharp.Service.Routing.ApiBootstrapper.Add("default", router);
            }

            var uri = new Uri("http://*****:*****@ http://localhost:1234");
                System.Diagnostics.Process.Start("http://localhost:1234/default");

                Console.ReadLine();
            }
        }
コード例 #10
0
        /// <summary>
        /// Executes a test adding tags from a PBF file.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="index"></param>
        /// <param name="pbfFile"></param>
        public static void Test(string name, ITagsCollectionIndex index, string pbfFile)
        {
            FileInfo           testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile));
            Stream             stream   = testFile.OpenRead();
            PBFOsmStreamSource source   = new PBFOsmStreamSource(stream);

            ITagCollectionIndexTests.TestAdd(name, index, source);
        }
コード例 #11
0
ファイル: LoadMapNodes.cs プロジェクト: beniamingolda/GenAlg
        public List <Node> LoadCity(string cityName)
        {
            var nodes        = new List <Node>();
            var src          = new PBFOsmStreamSource(fileStream);
            var cityBoundary = from osmGeo in src
                               where osmGeo.Type == OsmGeoType.Relation && osmGeo.Tags != null && osmGeo.Tags.Contains("boundary", "administrative") && osmGeo.Tags.Contains("name", cityName) && osmGeo.Tags.Contains("name:prefix", "miasto")
                               select osmGeo;
            var waysIds = new List <long>();

            foreach (var element in cityBoundary)
            {
                if (element.Type == OsmGeoType.Relation)
                {
                    var relationTmp = (Relation)element;
                    foreach (var member in relationTmp.Members)
                    {
                        if (member.Type == OsmGeoType.Way)
                        {
                            waysIds.Add(member.Id);
                        }
                    }
                }
            }
            var nodesIds         = new List <long>();
            var waysCityBoundary = from osmGeo in src
                                   where osmGeo.Type == OsmGeoType.Way && waysIds.Contains((long)osmGeo.Id)
                                   select osmGeo;

            foreach (var way in waysCityBoundary)
            {
                if (way.Type == OsmGeoType.Way)
                {
                    var wayTmp = (Way)way;
                    foreach (var node in wayTmp.Nodes)
                    {
                        nodesIds.Add(node);
                    }
                }
            }
            var nodesCityBoundary = from osmGeo in src
                                    where osmGeo.Type == OsmGeoType.Node && nodesIds.Contains((long)osmGeo.Id)
                                    select osmGeo;

            foreach (var node in nodesCityBoundary)
            {
                if (node.Type == OsmGeoType.Node)
                {
                    Node nodeTmp = (Node)node;
                    if (!allNodes.ContainsKey((long)node.Id))
                    {
                        allNodes.Add((long)node.Id, (Node)node);
                    }
                    nodes.Add(nodeTmp);
                }
            }
            return(nodes);
        }
コード例 #12
0
        public static void LoadOsmData(this RouterDb db, Stream data, bool allCore, params Vehicle[] vehicles)
        {
            if (!db.IsEmpty)
            {
                throw new ArgumentException("Can only load a new routing network into an empty router db.");
            }
            PBFOsmStreamSource pbfOsmStreamSource = new PBFOsmStreamSource(data);

            db.LoadOsmData((OsmStreamSource)pbfOsmStreamSource, vehicles);
        }
コード例 #13
0
        static void ReadGeometryStream()
        {
            // let's show you what's going on.
            OsmSharp.Logging.Logger.LogAction = (origin, level, message, parameters) =>
            {
                System.Console.WriteLine(string.Format("[{0}] {1} - {2}", origin, level, message));
            };

            // Download.ToFile("http://files.itinero.tech/data/OSM/planet/europe/luxembourg-latest.osm.pbf", "luxembourg-latest.osm.pbf").Wait();

            using (System.IO.FileStream fileStream = System.IO.File.OpenRead(@"D:\username\Documents\Visual Studio 2017\Projects\OsmTilePrerenderer\OsmTilePrerenderer\Data\monaco-latest.osm.pbf"))
            {
                // create source stream.
                OsmStreamSource source = new PBFOsmStreamSource(fileStream);

                // show progress.
                OsmStreamSource progress = source.ShowProgress();

                // filter all powerlines and keep all nodes.
                System.Collections.Generic.IEnumerable <OsmGeo> filtered =
                    from osmGeo in progress
                    where osmGeo.Type == OsmSharp.OsmGeoType.Node ||
                    (osmGeo.Type == OsmSharp.OsmGeoType.Way && osmGeo.Tags != null && osmGeo.Tags.Contains("power", "line"))
                    select osmGeo;

                // convert to a feature stream.
                // WARNING: nodes that are partof powerlines will be kept in-memory.
                //          it's important to filter only the objects you need **before**
                //          you convert to a feature stream otherwise all objects will
                //          be kept in-memory.

                OsmSharp.Geo.Streams.IFeatureStreamSource features = filtered.ToFeatureSource();

                // filter out only linestrings.
                System.Collections.Generic.IEnumerable <NetTopologySuite.Features.IFeature> lineStrings = from feature in features
                                                                                                          where feature.Geometry is LineString
                                                                                                          select feature;

                // build feature collection.
                NetTopologySuite.Features.FeatureCollection featureCollection = new NetTopologySuite.Features.FeatureCollection();
                foreach (NetTopologySuite.Features.IFeature feature in lineStrings)
                {
                    featureCollection.Add(feature);
                }


                // convert to geojson.
                string json = ToJson(featureCollection);



                // var st = new Mapsui.Providers.MemoryProvider(json);
                System.IO.File.WriteAllText("output.geojson", json);
            }
        }
コード例 #14
0
        static void Main(string[] args)
        {
            // let's show you what's going on.
            OsmSharp.Logging.Logger.LogAction = (origin, level, message, parameters) =>
            {
                Console.WriteLine(string.Format("[{0}] {1} - {2}", origin, level, message));
            };

            Download.ToFile("http://files.itinero.tech/data/OSM/planet/europe/luxembourg-latest.osm.pbf", "luxembourg-latest.osm.pbf").Wait();

            using (var fileStream = File.OpenRead("luxembourg-latest.osm.pbf"))
            {
                // create source stream.
                var source = new PBFOsmStreamSource(fileStream);

                // show progress.
                var progress = source.ShowProgress();

                // filter all powerlines and keep all nodes.
                var filtered = from osmGeo in progress
                               where osmGeo.Type == OsmSharp.OsmGeoType.Node ||
                               (osmGeo.Type == OsmSharp.OsmGeoType.Way && osmGeo.Tags != null && osmGeo.Tags.Contains("power", "line"))
                               select osmGeo;

                // convert to a feature stream.
                // WARNING: nodes that are partof powerlines will be kept in-memory.
                //          it's important to filter only the objects you need **before**
                //          you convert to a feature stream otherwise all objects will
                //          be kept in-memory.
                var features = filtered.ToFeatureSource();

                // filter out only linestrings.
                var lineStrings = from feature in features
                                  where feature.Geometry is LineString
                                  select feature;

                // build feature collection.
                var featureCollection = new FeatureCollection();
                var attributesTable   = new AttributesTable {
                    { "type", "powerline" }
                };
                foreach (var feature in lineStrings)
                { // make sure there is a constant # of attributes with the same names before writing the shapefile.
                    featureCollection.Add(new Feature(feature.Geometry, attributesTable));
                }

                // convert to shape.
                var header      = ShapefileDataWriter.GetHeader(featureCollection.Features.First(), featureCollection.Features.Count);
                var shapeWriter = new ShapefileDataWriter("luxembourg.shp", new GeometryFactory())
                {
                    Header = header
                };
                shapeWriter.Write(featureCollection.Features);
            }
        }
コード例 #15
0
        /// <summary>
        /// Tests writing data and getting ways using it's nodes.
        /// </summary>
        protected void TestGetWaysForNode()
        {
            this.NotifyEmptyExpected(); // empty test database.

            // create the target and pull the data from the test-file into the sqlite database.
            OsmStreamTarget target = this.CreateDataStreamTarget();

            target.Initialize();
            PBFOsmStreamSource source = new PBFOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Data.Test.Unittests.Data.Osm.test.osm.pbf"));
            IDataSourceReadOnly dataSource = this.CreateDataSource();

            source.Initialize();
            while (source.MoveNext())
            {
                switch (source.Current().Type)
                {
                case OsmGeoType.Way:
                    Way way = (source.Current() as Way);
                    target.AddWay(way);
                    target.Flush();

                    if (way.Nodes != null)
                    {
                        foreach (long nodeId in way.Nodes)
                        {
                            IList <Way> ways = dataSource.GetWaysFor(nodeId);
                            Assert.IsNotNull(ways);
                            Assert.IsTrue(ways.Count > 0);
                            List <Way> foundWays = new List <Way>(ways.Where <Way>(x => x.Id == way.Id));
                            Assert.AreEqual(1, foundWays.Count);
                        }
                    }
                    break;
                }
            }

            MemoryDataSource memorySource = MemoryDataSource.CreateFrom(source);

            foreach (Way way in memorySource.GetWays())
            {
                if (way.Nodes != null)
                {
                    foreach (long nodeId in way.Nodes)
                    {
                        IList <Way> ways = dataSource.GetWaysFor(nodeId);
                        Assert.IsNotNull(ways);
                        Assert.IsTrue(ways.Count > 0);
                        List <Way> foundWays = new List <Way>(ways.Where <Way>(x => x.Id == way.Id));
                        Assert.AreEqual(1, foundWays.Count);
                    }
                }
            }
        }
コード例 #16
0
ファイル: Program.cs プロジェクト: fieldsofview/ProtoWorld
        static void CreateMSSqlData(string pbffile)
        {
            string connMSSQL2012 = "Server=localhost\\SQLEXPRESS;Database=GIS_Paris;Trusted_Connection=True;";
            var    source        = new PBFOsmStreamSource(new FileInfo(pbffile).OpenRead());
            var    target        = new OsmSharp.Data.SQLServer.Osm.Streams.SQLServerOsmStreamTarget(connMSSQL2012, true);

            target.RegisterSource(source);
            target.Pull();
            Console.WriteLine("It's done");
            Console.ReadKey();
        }
コード例 #17
0
 public static IEnumerable<string> ViewAllFileData(string osm_pbf_filename)
 {
     using(var fileStream = File.OpenRead(osm_pbf_filename))
     {
         var source = new PBFOsmStreamSource(fileStream);
         foreach (var element in source)
         {
             yield return element.ToString();
         }
     }
 }
コード例 #18
0
        /// <summary>
        /// Loads a routing network created from OSM data.
        /// </summary>
        public static void LoadOsmData(this RouterDb db, Stream data, bool allCore = false, bool processRestrictions = false, params Itinero.Osm.Vehicles.Vehicle[] vehicles)
        {
            if (!db.IsEmpty)
            {
                throw new ArgumentException("Can only load a new routing network into an empty router db.");
            }

            // load the data.
            var source = new PBFOsmStreamSource(data);

            db.LoadOsmData(source, allCore, processRestrictions, true, new DefaultTagNormalizer(), null, vehicles);
        }
コード例 #19
0
        /// <summary>
        /// Loads a routing network created from OSM data.
        /// </summary>
        public static void LoadOsmData(this RouterDb db, Stream data, bool allCore = false, params Itinero.Osm.Vehicles.Vehicle[] vehicles)
        {
            if (!db.IsEmpty)
            {
                throw new ArgumentException("Can only load a new routing network into an empty router db.");
            }

            // load the data.
            var source = new PBFOsmStreamSource(data);

            db.LoadOsmData(source, allCore, false, vehicles);
        }
コード例 #20
0
        private static void Go(string scopeName, long relationId)
        {
            if (!Directory.Exists(scopeName))
            {
                Directory.CreateDirectory(scopeName);
            }
            //NetTopologySuite.Algorithm.Match.HausdorffSimilarityMeasure
            //Geometry.DistanceMeters(
            //	new NetTopologySuite.Geometries.Coordinate(scope.MinLongitude.Value, scope.MinLatitude.Value),
            //	new NetTopologySuite.Geometries.Coordinate(scope.MaxLongitude.Value, scope.MaxLatitude.Value));

            var scope     = scopeName == null ? null : LoadBounds(scopeName, relationId);
            var reference = Reference.Generate("ReferenceRawSimplified.osm", $"{scopeName}\\Reference.osm", scope);
            Osm subject;

            using (var stream = File.OpenRead("Subject.pbf"))
            {
                subject = new PBFOsmStreamSource(stream).AsOsm();
            }

            var missingPublic = Conflate.FindMissingRoads(subject, reference.Where(w => !w.Tags.Contains("ownership", "private")).ToArray());

            FileSerializer.WriteXml($"{scopeName}\\MissingPublic.osm", missingPublic);
            JOSM.MarkAsNeverUpload($"{scopeName}\\MissingPublic.osm");

            var missingPrivate = Conflate.FindMissingRoads(subject, reference.Where(w => w.Tags.Contains("ownership", "private")).ToArray());

            FileSerializer.WriteXml($"{scopeName}\\MissingPrivate.osm", missingPrivate);
            JOSM.MarkAsNeverUpload($"{scopeName}\\MissingPrivate.osm");

            //int i = 0;
            //var referenceSlices = BoundsExtentions.SliceRecusive(reference, 200);

            //foreach (var referenceSlice in referenceSlices)
            //{
            //	var directory = i.ToString("0000");
            //	Directory.CreateDirectory(directory);
            //	FileSerializer.WriteXml($"{directory}\\Reference.osm", referenceSlice.Value.AsOsm());
            //	JOSM.MarkAsNeverUpload($"{directory}\\Reference.osm");

            //	//var subjectSlice = subject.FilterBox(bounds.MinLongitude.Value, bounds.MaxLatitude.Value,
            //	//		bounds.MaxLongitude.Value, bounds.MinLatitude.Value, true)
            //	//	.AsOsm();
            //	//FileSerializer.WriteXml($"{i}\\Subject.osm", subjectSlice);
            //	//var missing = Conflate.FindMissingPublicRoads(subjectSlice, referenceSlice);
            //	//FileSerializer.WriteXml($"{i}\\MissingPublicRoads.osm", missing);
            //	//var session = File.ReadAllText("Session.jos");
            //	// Transform session
            //	//File.WriteAllText($"{i}\\Session.jos", session);
            //	i++;
            //}
        }
コード例 #21
0
        private static bool ContainsCoast(ISector s)
        {
            var source = new PBFOsmStreamSource(new FileInfo(OSMPaths.GetSectorPath(s)).OpenRead());

            foreach (var element in source)
            {
                if (element.Tags.Contains("natural", "coastline"))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #22
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var osmpbf = "./data/utrecht-latest.osm.pbf";
            // https://tiles.sharedstreets.io/12-2106-1351.intersection.pbf
            var intersectionStream = File.OpenRead("./data/12-2106-1351.intersection.pbf");
            var intersections      = SharedStreetsTileParser.Parse <SharedStreetsIntersection>(intersectionStream);

            // 5099
            Console.WriteLine("Number of intersections:" + intersections.Count);

            var tile   = new Tile(2106, 1351, 12);
            var bounds = tile.Bounds();

            // read osm pbf
            var source   = new PBFOsmStreamSource(new FileInfo(osmpbf).OpenRead());
            var filtered = source.FilterBox((float)bounds[0], (float)bounds[3], (float)bounds[2], (float)bounds[1]); // left, top, right, bottom
            var i        = 0;

            //grab all way segments for road name A
            //grab all way segments for road named B
            //compare both list of nodes
            //return equal nodes


            // filter intersections, geometries
            // todo: improve perf
            foreach (var element in filtered)
            {
                if (element.Type == OsmGeoType.Way)
                {
                    var way   = (Way)element;
                    var nodes = way.Nodes;
                    foreach (var node in nodes)
                    {
                        var otherway = GetOtherWay(source, way, node);

                        if (otherway != null)
                        {
                            Console.WriteLine(node);
                            i++;
                        }
                    }
                }
            }

            //  533926
            Console.WriteLine("Number of nodes: " + i);
            Console.ReadKey();
        }
コード例 #23
0
        public void Load(string file)
        {
            using (var stream = File.OpenRead(file))
            {
                using (var source = new PBFOsmStreamSource(stream))
                {
                    //foreach (var t in source.SelectMany(i => i.Tags).Select(t => t.Key).Distinct().OrderBy(k => k))
                    //    Console.WriteLine(t);

                    var roads = source.Where(t => t.Tags.Any(k => k.Key == "road"));
                }
            }
            Console.ReadLine();
        }
コード例 #24
0
        /// <summary>
        /// Builds or loads a routerdb.
        /// </summary>
        /// <returns>The loaded routerdb.</returns>
        public static RouterDb BuildOrLoad()
        {
            RouterDb routerDb = null;

            try
            {
                if (File.Exists(LocalBelgiumRouterDb))
                {
                    using (var stream = File.OpenRead(LocalBelgiumRouterDb))
                    {
                        routerDb = RouterDb.Deserialize(stream);
                    }

                    if (routerDb != null &&
                        routerDb.AddVelo())
                    {
                        using (var outputStream = File.Open(LocalBelgiumRouterDb, FileMode.Create))
                        {
                            routerDb.Serialize(outputStream);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error("Existing RouterDb failed to load.", e);
            }

            if (routerDb != null)
            {
                return(routerDb);
            }

            Download.DownloadBelgiumAll();

            var pedestrian = Itinero.Profiles.DynamicVehicle.Load(File.ReadAllText("./data/pedestrian.lua"));

            Log.Information("RouterDb doesn't exist yet or failed to load, building...");
            routerDb = new RouterDb();
            using (var stream = File.OpenRead(Download.BelgiumLocal))
                using (var outputStream = File.Open(LocalBelgiumRouterDb, FileMode.Create))
                {
                    var source = new PBFOsmStreamSource(stream);
                    routerDb.LoadOsmDataAndShortcuts(source, new LoadSettings(), Vehicle.Bicycle, pedestrian);

                    routerDb.Serialize(outputStream);
                }

            return(routerDb);
        }
コード例 #25
0
        public void ReadRealPBF()
        {
            using (var fileStream = this.GetType().Assembly.GetManifestResourceStream(
                       "OsmSharp.Test.data.pbf.wechel.osm.pbf"))
            {
                var wechel = new List <OsmGeo>();
                using (var reader = new PBFOsmStreamSource(fileStream))
                {
                    wechel.AddRange(reader);
                }

                Assert.AreEqual(13978, wechel.Count);
            }
        }
コード例 #26
0
        /// <summary>
        /// Loads a routing network created from OSM data.
        /// </summary>
        public static void LoadOsmData(this RouterDb db, Stream data, bool allCore = false, bool processRestrictions = true, params Itinero.Profiles.Vehicle[] vehicles)
        {
            if (!db.IsEmpty)
            {
                throw new ArgumentException("Can only load a new routing network into an empty router db, add multiple streams at once to load multiple files.");
            }

            // load the data.
            var source   = new PBFOsmStreamSource(data);
            var progress = new OsmSharp.Streams.Filters.OsmStreamFilterProgress();

            progress.RegisterSource(source);
            db.LoadOsmData(progress, allCore, processRestrictions, vehicles);
        }
コード例 #27
0
        public void PBFOsmStreamSource_ShouldBeAbleToReadFromStreamWithPositionNotAvailable()
        {
            using (var fileStream = new DeflateMockStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(
                                                              "OsmSharp.Test.data.pbf.wechel.osm.pbf")))
            {
                var wechel = new List <OsmGeo>();
                using (var reader = new PBFOsmStreamSource(fileStream))
                {
                    wechel.AddRange(reader);
                }

                Assert.AreEqual(13978, wechel.Count);
            }
        }
コード例 #28
0
        public IActionResult Get(int x, int y, int z, string file)
        {
            var completeFilePath = Path.Combine(Startup.DataFolder, file);
            var fileInfo         = new FileInfo(completeFilePath);

            if (!fileInfo.Exists)
            {
                return(new NotFoundResult());
            }

            var resultStream = new MemoryStream();

            using (var stream = fileInfo.OpenRead())
            {
                OsmStreamSource source;
                if (fileInfo.Name.EndsWith(".osm.pbf"))
                {
                    source = new PBFOsmStreamSource(stream);
                }
                else if (fileInfo.Name.EndsWith(".osm"))
                {
                    source = new XmlOsmStreamSource(stream);
                }
                else
                {
                    return(new NotFoundResult());
                }

                // parse the zoom, x and y.
                var tile = new Tile(x, y, z);
                tile = tile.InvertY();
                var filter = source.FilterBox(tile.Left, tile.Top, tile.Right, tile.Bottom,
                                              true);

                var target = new XmlOsmStreamTarget(resultStream);
                target.ExtraRootAttributes.Add(new System.Tuple <string, string>("upload", "never"));
                target.Bounds = new OsmSharp.API.Bounds()
                {
                    MaxLatitude  = tile.Top,
                    MaxLongitude = tile.Right,
                    MinLatitude  = tile.Bottom,
                    MinLongitude = tile.Left
                };
                target.RegisterSource(filter);
                target.Pull();

                resultStream.Seek(0, SeekOrigin.Begin);
            }
            return(new FileStreamResult(resultStream, "text/xml"));
        }
コード例 #29
0
        public static void Main(string[] args)
        {
            Native.Initialize();

            // enable logging and use the console as output.
            OsmSharp.Logging.Log.Enable();
            OsmSharp.Logging.Log.RegisterListener(
                new OsmSharp.WinForms.UI.Logging.ConsoleTraceListener());

            // initialize mapcss interpreter.
            var mapCSSInterpreter = new MapCSSInterpreter(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Service.Tiles.Sample.SelfHost.custom.mapcss"),
                new MapCSSDictionaryImageSource());

            var scene = new Scene2D(new OsmSharp.Math.Geo.Projections.WebMercator(), new List <float>(new float[] {
                16, 14, 12, 10
            }));
            var target = new StyleOsmStreamSceneTarget(
                mapCSSInterpreter, scene, new WebMercator());
            var source = new PBFOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Service.Tiles.Sample.SelfHost.kempen.osm.pbf"));
            var progress = new OsmStreamFilterProgress();

            progress.RegisterSource(source);
            target.RegisterSource(progress);
            target.Pull();

            var merger = new Scene2DObjectMerger();

            scene = merger.BuildMergedScene(scene);

            // create a new instance (with a cache).
            var instance = new RenderingInstance();

            instance.Map.AddLayer(new LayerScene(scene));

            // add a default test instance.
            ApiBootstrapper.AddInstance("default", instance);

            // start hosting this!
            using (var host = new NancyHost(new Uri("http://*****:*****@ http://localhost:1234");
                System.Diagnostics.Process.Start("http://localhost:1234/default");
                Console.ReadLine();
            }
        }
コード例 #30
0
        // est: since going from 6 to 10 took 1 minute, we might expect doing all 256 would take 256 minutes
        // if we break it up into quadrants using the same library, maybe it'll only take (4+1+1/16...) roughly 5.33 minutes?
        // actually took 8.673 mins (went from 450MB to 455MB)
        // estimated time to segment the whole 43.1 GB planet? 12/28/2018 = 8.673 * 43.1 / 8.05 * 47.7833 = 36.98 hours
        public static void BreakupFile(string filePath, ISector sector, int targetZoom)
        {
            if (sector.Zoom == targetZoom)
            {
                return;
            }
            List <ISector> quadrants = sector.GetChildrenAtLevel(sector.Zoom + 1);

            if (READ_BREAKUP_STEP <= CURRENT_BREAKUP_STEP)
            {
                foreach (var quadrant in quadrants)
                {
                    String quadrantPath = OSMPaths.GetSectorPath(quadrant);
                    if (File.Exists(quadrantPath))
                    {
                        File.Delete(quadrantPath);                            // we're assuming it's corrupted
                    }
                    if (!Directory.Exists(Path.GetDirectoryName(quadrantPath)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(quadrantPath));
                    }
                    var fInfo = new FileInfo(filePath);
                    using (var fileInfoStream = fInfo.OpenRead())
                    {
                        using (var source = new PBFOsmStreamSource(fileInfoStream))
                        {
                            var filtered = source.FilterNodes(x => x.Longitude.HasValue && x.Latitude.HasValue && quadrant.ContainsLongLat(new LongLat(x.Longitude.Value * Math.PI / 180, x.Latitude.Value * Math.PI / 180)), true);
                            using (var stream = new FileInfo(quadrantPath).Open(FileMode.Create, FileAccess.ReadWrite))
                            {
                                var target = new PBFOsmStreamTarget(stream, true);
                                target.RegisterSource(filtered);
                                target.Pull();
                                target.Close();
                            }
                        }
                    }
                }
                if (Path.GetFileName(filePath).ToLower() != Path.GetFileName(OSMPaths.GetPlanetPath()).ToLower())
                {
                    File.Delete(filePath);
                }
            }
            BreakupStepDone();
            foreach (var quadrant in quadrants)
            {
                String quadrantPath = OSMPaths.GetSectorPath(quadrant);
                BreakupFile(quadrantPath, quadrant, targetZoom);
            }
        }