示例#1
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();
        }
示例#2
0
        private void LoadData()
        {
            var amsterdamTile = "./testfixtures/12-2103-1346.";

            var geometryStream     = File.OpenRead(amsterdamTile + "geometry.6.pbf");
            var intersectionStream = File.OpenRead(amsterdamTile + "intersection.6.pbf");
            var metadataStream     = File.OpenRead(amsterdamTile + "metadata.6.pbf");
            var referenceStream    = File.OpenRead(amsterdamTile + "reference.6.pbf");

            geometries    = SharedStreetsTileParser.Parse <SharedStreetsGeometry>(geometryStream);
            intersections = SharedStreetsTileParser.Parse <SharedStreetsIntersection>(intersectionStream);
            metadata      = SharedStreetsTileParser.Parse <SharedStreetsMetadata>(metadataStream);
            references    = SharedStreetsTileParser.Parse <SharedStreetsReference>(referenceStream);
        }
        public void ReadAndWriteTests()
        {
            var geometryStream     = TileReader.GetGeometryTile();
            var intersectionStream = TileReader.GetIntersectionTile();
            var referenceStream    = TileReader.GetReferenceTile();
            var metadataStream     = TileReader.GetMetadataTile();

            var geometries    = SharedStreetsTileParser.Parse <SharedStreetsGeometry>(geometryStream);
            var intersections = SharedStreetsTileParser.Parse <SharedStreetsIntersection>(intersectionStream);
            var metadata      = SharedStreetsTileParser.Parse <SharedStreetsMetadata>(metadataStream);
            var references    = SharedStreetsTileParser.Parse <SharedStreetsReference>(referenceStream);

            /// check read/write geometries
            var stream = SharedStreetsTileWriter.Write(geometries);

            Assert.IsTrue(geometryStream.Length == stream.Length);
            stream.Position = 0;
            var newgeometries = SharedStreetsTileParser.Parse <SharedStreetsGeometry>(stream);

            Assert.IsTrue(newgeometries.Count == geometries.Count);

            // check read/write intersections
            stream = SharedStreetsTileWriter.Write(intersections);
            Assert.IsTrue(intersectionStream.Length == stream.Length);
            stream.Position = 0;
            var newintersection = SharedStreetsTileParser.Parse <SharedStreetsIntersection>(stream);

            Assert.IsTrue(newintersection.Count == intersections.Count);

            // check read/write reference
            stream = SharedStreetsTileWriter.Write(references);
            Assert.IsTrue(referenceStream.Length == stream.Length);
            stream.Position = 0;
            var newreference = SharedStreetsTileParser.Parse <SharedStreetsReference>(stream);

            Assert.IsTrue(newreference.Count == references.Count);

            // check read/write metadata
            stream = SharedStreetsTileWriter.Write(metadata);
            Assert.IsTrue(metadataStream.Length == stream.Length);
            stream.Position = 0;
            var newmetadata = SharedStreetsTileParser.Parse <SharedStreetsMetadata>(stream);

            Assert.IsTrue(newmetadata.Count == metadata.Count);
        }
        public void PbfParsingTest()
        {
            var geometryStream     = TileReader.GetGeometryTile();
            var intersectionStream = TileReader.GetIntersectionTile();
            var referenceStream    = TileReader.GetReferenceTile();
            var metadataStream     = TileReader.GetMetadataTile();

            var geometries = SharedStreetsTileParser.Parse <SharedStreetsGeometry>(geometryStream);

            Assert.IsTrue(geometries.Count == 6202);
            var intersections = SharedStreetsTileParser.Parse <SharedStreetsIntersection>(intersectionStream);

            Assert.IsTrue(intersections.Count == 4031);
            var metadata = SharedStreetsTileParser.Parse <SharedStreetsMetadata>(metadataStream);

            Assert.IsTrue(metadata.Count == 6202);
            var references = SharedStreetsTileParser.Parse <SharedStreetsReference>(referenceStream);

            Assert.IsTrue(references.Count == 8691);
            // round test
            var lonlats = geometries[0].Lonlats;

            Assert.IsTrue(SharedStreets.GeometryId(lonlats) == geometries[0].Id);
        }