/// <summary>
 /// Preprocesses the data from the given OsmStreamReader and converts it directly to a routable data source.
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="tagsIndex"></param>
 /// <param name="interpreter"></param>
 /// <param name="vehicle"></param>
 /// <returns></returns>
 public static DynamicGraphRouterDataSource <CHEdgeData> Preprocess(OsmStreamSource reader,
                                                                    ITagsCollectionIndex tagsIndex,
                                                                    IOsmRoutingInterpreter interpreter,
                                                                    Vehicle vehicle)
 {
     return(CHEdgeGraphOsmStreamTarget.Preprocess(reader, tagsIndex, interpreter, vehicle, true));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Move to the next object.
        /// </summary>
        public override bool MoveNext(bool ignoreNodes, bool ignoreWays, bool ignoreRelations)
        {
            if (_mergedSource == null)
            {
                var mergedSource = new OsmStreamFilterMerge();
                mergedSource.RegisterSource(this.Source);
                mergedSource.RegisterSource(_creations);
                _mergedSource = mergedSource;
            }

            OsmGeo modified;

            while (_mergedSource.MoveNext(ignoreNodes, ignoreWays, ignoreRelations))
            {
                // returns the next out of the merged source of the creations and the source.
                _current = _mergedSource.Current();

                // check for deletions or modifications.
                var key = new OsmGeoKey(_current);
                if (_deletions.Contains(key))
                {
                    // move next.
                    _current = null;
                    continue;
                }
                else if (_modifications.TryGetValue(key, out modified))
                {
                    _current = modified;
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Tests adding simple tags to the given index.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="source"></param>
        public static void FillIndex(ITagsCollectionIndex index, OsmStreamSource source)
        {
            OsmStreamTargetTags tagsTarget = new OsmStreamTargetTags(index);

            tagsTarget.RegisterSource(source);
            tagsTarget.Pull();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Preprocesses the data from the given OsmStreamReader and converts it directly to a routable data source.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="tagsIndex"></param>
        /// <param name="interpreter"></param>
        /// <param name="vehicle"></param>
        /// <param name="leaveReverseEdges"></param>
        /// <returns></returns>
        public static DynamicGraphRouterDataSource <CHEdgeData> Preprocess(OsmStreamSource reader,
                                                                           ITagsIndex tagsIndex,
                                                                           IOsmRoutingInterpreter interpreter,
                                                                           Vehicle vehicle,
                                                                           bool leaveReverseEdges)
        {
            // pull in the data.
            var dynamicGraphRouterDataSource =
                new DynamicGraphRouterDataSource <CHEdgeData>(tagsIndex);
            var targetData = new CHEdgeGraphOsmStreamTarget(
                dynamicGraphRouterDataSource, interpreter, tagsIndex, vehicle);

            targetData.RegisterSource(reader);
            targetData.Pull();

            // compress the graph.
            INodeWitnessCalculator witnessCalculator = new DykstraWitnessCalculator();
            var edgeDifference = new EdgeDifference(
                dynamicGraphRouterDataSource, witnessCalculator);
            var preProcessor = new CHPreProcessor(
                dynamicGraphRouterDataSource, edgeDifference, witnessCalculator);

            preProcessor.Start();

            return(dynamicGraphRouterDataSource);
        }
 /// <summary>
 /// Preprocesses the data from the given OsmStreamReader and converts it directly to a routable data source.
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="tagsIndex"></param>
 /// <param name="interpreter"></param>
 /// <param name="vehicle"></param>
 /// <returns></returns>
 public static DynamicGraphRouterDataSource <CHEdgeData> Preprocess(OsmStreamSource reader,
                                                                    ITagsIndex tagsIndex,
                                                                    IRoutingInterpreter interpreter,
                                                                    Vehicle vehicle)
 {
     return(CHEdgeGraphOsmStreamWriter.Preprocess(reader, tagsIndex, interpreter, vehicle, false));
 }
Ejemplo n.º 6
0
        public static MemoryDataSource CreateFrom(OsmStreamSource sourceStream)
        {
            if (sourceStream.CanReset)
            {
                sourceStream.Reset();
            }
            MemoryDataSource memoryDataSource = new MemoryDataSource();

            foreach (OsmGeo osmGeo in sourceStream)
            {
                if (osmGeo != null)
                {
                    switch (osmGeo.Type)
                    {
                    case OsmGeoType.Node:
                        memoryDataSource.AddNode(osmGeo as Node);
                        continue;

                    case OsmGeoType.Way:
                        memoryDataSource.AddWay(osmGeo as Way);
                        continue;

                    case OsmGeoType.Relation:
                        memoryDataSource.AddRelation(osmGeo as Relation);
                        continue;

                    default:
                        continue;
                    }
                }
            }
            return(memoryDataSource);
        }
 /// <summary>
 /// Preprocesses the data from the given OsmStreamReader and converts it directly to a routable data source.
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="interpreter"></param>
 /// <param name="vehicle"></param>
 /// <param name="preProcessingPercentage"></param>
 /// <returns></returns>
 public static DynamicGraphRouterDataSource <CHEdgeData> Preprocess(OsmStreamSource reader,
                                                                    IOsmRoutingInterpreter interpreter,
                                                                    Vehicle vehicle,
                                                                    double preProcessingPercentage)
 {
     return(CHEdgeGraphOsmStreamTarget.Preprocess(reader, new TagsTableCollectionIndex(), interpreter, vehicle, true, preProcessingPercentage));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Registers the source for this target.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="filterTags">The filter tags flag.</param>
        public virtual void RegisterSource(OsmStreamSource source, bool filterTags)
        {
            if (filterTags)
            { // add filter to remove all irrelevant tags.
                var tagsFilter = new OsmStreamFilterTagsFilter((TagsCollectionBase tags) =>
                {
                    var tagsToRemove = new List <Tag>();
                    foreach (var tag in tags)
                    {
                        if (!_interpreter.IsRelevant(tag.Key, tag.Value) &&
                            !Vehicle.IsRelevantForOneOrMore(tag.Key, tag.Value))
                        { // not relevant for both interpreter and all registered vehicle profiles.
                            tagsToRemove.Add(tag);
                        }
                    }
                    foreach (Tag tag in tagsToRemove)
                    {
                        tags.RemoveKeyValue(tag.Key, tag.Value);
                    }
                });
                tagsFilter.RegisterSource(source);

                base.RegisterSource(tagsFilter);
            }
            else
            { // no filter!
                base.RegisterSource(source);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a new memory data source from all the data in the given osm-stream.
        /// </summary>
        /// <param name="sourceStream"></param>
        /// <returns></returns>
        public static MemoryDataSource CreateFrom(OsmStreamSource sourceStream)
        {
            // reset if possible.
            if (sourceStream.CanReset)
            {
                sourceStream.Reset();
            }

            // enumerate all objects and add them to a new datasource.
            MemoryDataSource dataSource = new MemoryDataSource();

            foreach (var osmGeo in sourceStream)
            {
                if (osmGeo != null)
                {
                    switch (osmGeo.Type)
                    {
                    case OsmGeoType.Node:
                        dataSource.AddNode(osmGeo as Node);
                        break;

                    case OsmGeoType.Way:
                        dataSource.AddWay(osmGeo as Way);
                        break;

                    case OsmGeoType.Relation:
                        dataSource.AddRelation(osmGeo as Relation);
                        break;
                    }
                }
            }
            return(dataSource);
        }
Ejemplo n.º 10
0
 public override void RegisterSource(OsmStreamSource reader)
 {
     if ((this._wayKeepNodes || this._relationKeepObjects) && !reader.CanReset)
     {
         throw new ArgumentException("The tags source cannot be reset!", "reader");
     }
     base.RegisterSource(reader);
 }
Ejemplo n.º 11
0
        // D:\Stefan.Steiger\Documents\Visual Studio 2017\Projects\Mapsui\Tests\Mapsui.Rendering.Xaml.Tests\MapRendererTests.cs

        public static void foo()
        {
            OsmStreamSource source = null;

            var merger = new OsmSharp.Streams.Filters.OsmStreamFilterMerge();

            merger.RegisterSource(source);
        }
 /// <summary>
 /// Registers a source.
 /// </summary>
 public override void RegisterSource(OsmStreamSource source)
 {
     if (_source1 == null)
     {
         _source1 = source;
         return;
     }
     _source2 = source;
 }
Ejemplo n.º 13
0
        public static RenderingInstance Build(OsmStreamSource streamSource, StyleInterpreter interpreter)
        {
            var instance = new RenderingInstance();

            MemoryDataSource dataSource = MemoryDataSource.CreateFrom(streamSource);

            instance.Map.AddLayer(new LayerOsm(dataSource, interpreter, instance.Map.Projection));

            return(instance);
        }
Ejemplo n.º 14
0
 public OsmStreamFilterBase(OsmStreamSource source, OsmDataCache cache)
 {
     this._dataCache                = cache;
     this._nodesToInclude           = new HashSet <long>();
     this._nodesUsedTwiceOrMore     = new Dictionary <long, int>();
     this._waysToInclude            = new HashSet <long>();
     this._waysUsedTwiceOrMore      = new Dictionary <long, int>();
     this._relationsToInclude       = new HashSet <long>();
     this._relationsUsedTwiceOrMore = new Dictionary <long, int>();
 }
Ejemplo n.º 15
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);
            }
        }
Ejemplo n.º 16
0
 public OsmSimpleCompleteStreamSource(OsmStreamSource source)
 {
     this._dataCache                = (OsmDataCache) new OsmDataCacheMemory();
     this._simpleSource             = source;
     this._nodesToInclude           = new HashSet <long>();
     this._nodesUsedTwiceOrMore     = new Dictionary <long, int>();
     this._waysToInclude            = new HashSet <long>();
     this._waysUsedTwiceOrMore      = new Dictionary <long, int>();
     this._relationsToInclude       = new HashSet <long>();
     this._relationsUsedTwiceOrMore = new Dictionary <long, int>();
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Preprocesses the data from the given OsmStreamReader and converts it directly to a routable data source.
        /// </summary>
        /// <param name="source">The source stream.</param>
        /// <param name="tagsIndex">The tags index.</param>
        /// <param name="interpreter">The routing interpreter.</param>
        /// <returns></returns>
        public static RouterDataSource <Edge> Preprocess(OsmStreamSource source, ITagsIndex tagsIndex, IOsmRoutingInterpreter interpreter)
        {
            var routerDataSource =
                new RouterDataSource <Edge>(new Graph <Edge>(), tagsIndex);
            var targetData = new GraphOsmStreamTarget(routerDataSource, interpreter,
                                                      tagsIndex);

            targetData.RegisterSource(source);
            targetData.Pull();

            return(routerDataSource);
        }
        /// <summary>
        /// Creates a new osm simple complete stream.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="cache"></param>
        public OsmSimpleCompleteStreamSource(OsmStreamSource source, OsmDataCache cache)
        {
            _dataCache    = cache;
            _simpleSource = source;

            _nodesToInclude           = new HashSet <long>();
            _nodesUsedTwiceOrMore     = new Dictionary <long, int>();
            _waysToInclude            = new HashSet <long>();
            _waysUsedTwiceOrMore      = new Dictionary <long, int>();
            _relationsToInclude       = new HashSet <long>();
            _relationsUsedTwiceOrMore = new Dictionary <long, int>();
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Registers a source.
 /// </summary>
 public override void RegisterSource(OsmStreamSource source)
 {
     if (_source1 == null)
     {
         _source1 = source;
         return;
     }
     if (_source2 != null)
     {
         throw new ArgumentException("Merge filter can only handle two streams, to merge in a third use a second merge filter.");
     }
     _source2 = source;
 }
        /// <summary>
        /// Creates a new osm simple complete stream.
        /// </summary>
        /// <param name="source"></param>
        public OsmSimpleCompleteStreamSource(OsmStreamSource source)
        {
            // create an in-memory cache by default.
            _dataCache    = new OsmDataCacheMemory();
            _simpleSource = source;

            _nodesToInclude           = new HashSet <long>();
            _nodesUsedTwiceOrMore     = new Dictionary <long, int>();
            _waysToInclude            = new HashSet <long>();
            _waysUsedTwiceOrMore      = new Dictionary <long, int>();
            _relationsToInclude       = new HashSet <long>();
            _relationsUsedTwiceOrMore = new Dictionary <long, int>();
        }
        /// <summary>
        /// Preprocesses the data from the given OsmStreamReader and converts it directly to a routable data source.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="tagsIndex"></param>
        /// <param name="interpreter"></param>
        /// <param name="vehicle"></param>
        /// <returns></returns>
        public static RouterDataSource <CHEdgeData> Preprocess(OsmStreamSource reader,
                                                               ITagsIndex tagsIndex, IOsmRoutingInterpreter interpreter, Vehicle vehicle)
        {
            // pull in the data.
            var graph      = new RouterDataSource <CHEdgeData>(new DirectedGraph <CHEdgeData>(), tagsIndex);
            var targetData = new CHEdgeGraphOsmStreamTarget(
                graph, interpreter, tagsIndex, vehicle);

            targetData.RegisterSource(reader);
            targetData.Pull();

            return(graph);
        }
Ejemplo n.º 22
0
        public static void LoadOsmData(this RouterDb db, OsmStreamSource source, bool allCore, params Vehicle[] vehicles)
        {
            if (!db.IsEmpty)
            {
                throw new ArgumentException("Can only load a new routing network into an empty router db.");
            }
            RouterDbStreamTarget routerDbStreamTarget = new RouterDbStreamTarget(db, vehicles, allCore, 1, true, (IEnumerable <ITwoPassProcessor>)null);
            OsmStreamSource      osmStreamSource      = source;

            ((OsmStreamTarget)routerDbStreamTarget).RegisterSource(osmStreamSource);
            routerDbStreamTarget.Pull();
            db.Network.Sort();
        }
        /// <summary>
        /// Preprocesses the data from the given OsmStreamReader and converts it directly to a routable data source.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="tagsIndex"></param>
        /// <param name="interpreter"></param>
        /// <returns></returns>
        public static DynamicGraphRouterDataSource <LiveEdge> Preprocess(OsmStreamSource reader,
                                                                         ITagsIndex tagsIndex,
                                                                         IRoutingInterpreter interpreter)
        {
            var dynamicGraphRouterDataSource =
                new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamWriter(dynamicGraphRouterDataSource, interpreter, dynamicGraphRouterDataSource.TagsIndex);

            targetData.RegisterSource(reader);
            targetData.Pull();

            return(dynamicGraphRouterDataSource);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Tests adding simple tags to the given index.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="index"></param>
        /// <param name="source"></param>
        public static void TestAdd(string name, ITagsCollectionIndex index,
                                   OsmStreamSource source)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Add", name));

            performanceInfo.Start();
            performanceInfo.Report("Adding tags from {0}...", source.ToString());

            ITagCollectionIndexTests.FillIndex(index, source);

            performanceInfo.Stop();

            Console.Write("", index.Max);
        }
Ejemplo n.º 25
0
        private static double ProcessWays(IEnumerable <Way> ways, OsmStreamSource source)
        {
            var nodesNeeded = ways
                              .SelectMany(w => w.Nodes)
                              .Distinct();
            var nodes = FindNodes(nodesNeeded, source);

            return(ways.Select(w =>
                               w.Nodes
                               .Select(id => nodes[id])
                               .Pairwise((from, to) => Distance(from, to))
                               .Sum()
                               ).Sum());
        }
Ejemplo n.º 26
0
        public void ImportWays(OsmStreamSource source, bool forceIfTableEmpty = false)
        {
            if (source is null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (_liteDB is null)
            {
                throw new ArgumentNullException(nameof(_liteDB));
            }
            var filteredWays = from osmGeo in source
                               where
                               osmGeo.Type == OsmGeoType.Way
                               let way = (Way)osmGeo
                                         where
                                         osmGeo.Tags.Contains("highway", "secondary") ||
                                         osmGeo.Tags.Contains("highway", "tertiary") ||
                                         osmGeo.Tags.Contains("highway", "unclassified") ||
                                         osmGeo.Tags.Contains("highway", "residential") ||
                                         osmGeo.Tags.Contains("highway", "service") ||
                                         osmGeo.Tags.Contains("highway", "cycleway") ||
                                         osmGeo.Tags.Contains("highway", "track") ||
                                         osmGeo.Tags.Contains("highway", "path") ||
                                         osmGeo.Tags.ContainsKey("footway") ||
                                         osmGeo.Tags.Contains("sidewalk", "both") ||
                                         osmGeo.Tags.Contains("sidewalk", "left") ||
                                         osmGeo.Tags.Contains("sidewalk", "right")
                                         //let nodes = from nd in way.Nodes
                                         //            select
                                         //            _liteDB.GetNodeByOSMID(nd)
                                         select
                                         new LinkedList <long>(way.Nodes)
            ;

            foreach (var nodes in filteredWays)
            {
                var curNode = nodes.First;
                while (curNode != null)
                {
                    var nextNode = curNode.Next;
                    if (nextNode == null)
                    {
                        break;
                    }
                    _liteDB.AddNodeToNeightbours(curNode.Value, nextNode.Value);
                    curNode = nextNode;
                }
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Creates a router using live interpreted edges.
        /// </summary>
        /// <param name="reader">The data to route on.</param>
        /// <param name="interpreter">The routing interpreter.</param>
        /// <param name="vehicle">The vehicle profile.</param>
        /// <returns></returns>
        public static Router CreateCHFrom(OsmStreamSource reader,
                                          IOsmRoutingInterpreter interpreter, Vehicle vehicle)
        {
            var tagsIndex = new TagsTableCollectionIndex(); // creates a tagged index.

            // read from the OSM-stream.
            DynamicGraphRouterDataSource <CHEdgeData> data = CHEdgeGraphOsmStreamTarget.Preprocess(
                reader, interpreter, vehicle);

            // creates the live edge router.
            var liveEdgeRouter = new TypedRouterCHEdge(
                data, interpreter, new CHRouter());

            return(new Router(liveEdgeRouter)); // create the actual router.
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Creates a router using interpreted edges.
        /// </summary>
        /// <param name="reader">The data to route on.</param>
        /// <param name="interpreter">The routing interpreter.</param>
        /// <param name="vehicle">The vehicle profile.</param>
        /// <returns></returns>
        public static Router CreateCHFrom(OsmStreamSource reader,
                                          IOsmRoutingInterpreter interpreter, Vehicle vehicle)
        {
            var tagsIndex = new TagsIndex(); // creates a tagged index.

            // read from the OSM-stream.
            var data = CHEdgeGraphOsmStreamTarget.Preprocess(
                reader, interpreter, vehicle);

            // creates the edge router.
            var typedRouter = new TypedRouterCHEdge(
                data, interpreter, new CHRouter());

            return(new Router(typedRouter)); // create the actual router.
        }
        /// <summary>
        /// Builds a rendering instance for a mapCSS file.
        /// </summary>
        /// <param name="streamSource"></param>
        /// <param name="mapCSSFile"></param>
        /// <returns></returns>
        public static RenderingInstance BuildForMapCSS(OsmStreamSource streamSource, Stream mapCSSFile)
        {
            var instance = new RenderingInstance();

            // load data into memory.
            var dataSource = MemoryDataSource.CreateFrom(streamSource);

            // create mapCSS interpreter.
            var interpreter = new MapCSSInterpreter(mapCSSFile, new MapCSSDictionaryImageSource());

            // add layer to map.
            instance.Map.AddLayer(new LayerOsm(dataSource, interpreter, instance.Map.Projection));

            return(instance);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Creates a router using interpreted edges.
        /// </summary>
        /// <param name="reader">The OSM-stream reader.</param>
        /// <param name="interpreter">The routing interpreter.</param>
        /// <returns></returns>
        public static Router CreateFrom(OsmStreamSource reader, IOsmRoutingInterpreter interpreter)
        {
            var tagsIndex = new TagsIndex(); // creates a tagged index.

            // read from the OSM-stream.
            var memoryData = new RouterDataSource<Edge>(new Graph<Edge>(), tagsIndex);
            var targetData = new GraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
            targetData.RegisterSource(reader);
            targetData.Pull();

            // creates the edge router.
            var typedRouter = new TypedRouterEdge(
                memoryData, interpreter, new Dykstra());

            return new Router(typedRouter); // create the actual router.
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Builds a new database and write the structure to the given path.
        /// </summary>
        public static void Build(OsmStreamSource source, string path, uint maxZoom = 12, bool compressed = false)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (!source.CanReset)
            {
                throw new ArgumentException("Source cannot be reset.");
            }
            if (!FileSystemFacade.FileSystem.DirectoryExists(path))
            {
                throw new ArgumentException("Output path does not exist.");
            }

            Log.Logger.Information("Building for tile {0}/{1}/{2}...", 0, 0, 0);
            var tiles = BuildInitial(source, path, maxZoom, new Tile(0, 0, 0), compressed);

            while (true)
            {
                var newTiles = new List <Tile>();

                for (var t = 0; t < tiles.Count; t++)
                //System.Threading.Tasks.Parallel.For(0, tiles.Count, (t) =>
                {
                    var subTile = tiles[t];
                    Log.Logger.Information($"Building for tile ({t + 1}/{tiles.Count}):{subTile.Zoom}/{subTile.X}/{subTile.Y}...");
                    var subTiles = Build(path, maxZoom, subTile, compressed);

                    lock (newTiles)
                    {
                        newTiles.AddRange(subTiles);
                    }
                }

                if (newTiles.Count == 0)
                {
                    break;
                }

                tiles = newTiles;
            }
        }
Ejemplo n.º 32
0
 /// <summary>
 /// Registers a simple source on this target.
 /// </summary>
 /// <param name="source"></param>
 public void RegisterSource(OsmStreamSource source)
 {
     _source = new OsmSimpleCompleteStreamSource(source);
 }
Ejemplo n.º 33
0
        private void StreamSourceToTargetThread(OsmStreamSource source, OsmStreamTarget target)
        {
            var concurrent_target = target.ConcurrentCopy();

            concurrent_target.Initialize();

            OsmGeo current;

            while (ConcurrentMoveNext(source, out current))
            {
                concurrent_target.Add(current);
            }

            concurrent_target.Flush();
            concurrent_target.Close();
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Registers the reader of this filter.
        /// </summary>
        /// <param name="reader"></param>
        public override void RegisterSource(OsmStreamSource reader)
        {
            if (_wayKeepNodes || _relationKeepObjects)
            {
                if (!reader.CanReset)
                {
                    throw new ArgumentException("The tags source cannot be reset!",
                        "reader");
                }
            }

            base.RegisterSource(reader);
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Creates a router using live interpreted edges.
        /// </summary>
        /// <param name="reader">The data to route on.</param>
        /// <param name="interpreter">The routing interpreter.</param>
        /// <param name="vehicle">The vehicle profile.</param>
        /// <returns></returns>
        public static Router CreateCHFrom(OsmStreamSource reader,
            IOsmRoutingInterpreter interpreter, Vehicle vehicle)
        {
            var tagsIndex = new TagsTableCollectionIndex(); // creates a tagged index.

            // read from the OSM-stream.
            DynamicGraphRouterDataSource<CHEdgeData> data = CHEdgeGraphOsmStreamTarget.Preprocess(
                reader, interpreter, vehicle);

            // creates the live edge router.
            var liveEdgeRouter = new TypedRouterCHEdge(
                data, interpreter, new CHRouter());

            return new Router(liveEdgeRouter); // create the actual router.
        }
 /// <summary>
 /// Creates a new processor source.
 /// </summary>
 /// <param name="source"></param>
 public ProcessorSource(OsmStreamSource source)
 {
     _source = source;
 }
Ejemplo n.º 37
0
        /// <summary>
        /// Creates a new osm simple complete stream.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="cache"></param>
        public OsmStreamFilterBase(OsmStreamSource source, OsmDataCache cache)
        {
            _dataCache = cache;

            _nodesToInclude = new HashSet<long>();
            _nodesUsedTwiceOrMore = new Dictionary<long, int>();
            _waysToInclude = new HashSet<long>();
            _waysUsedTwiceOrMore = new Dictionary<long, int>();
            _relationsToInclude = new HashSet<long>();
            _relationsUsedTwiceOrMore = new Dictionary<long, int>();
        }
        /// <summary>
        /// Builds a rendering instance for a mapCSS file.
        /// </summary>
        /// <param name="streamSource"></param>
        /// <param name="mapCSSFile"></param>
        /// <returns></returns>
        public static RenderingInstance BuildForMapCSS(OsmStreamSource streamSource, Stream mapCSSFile)
        {
            var instance = new RenderingInstance();

            // load data into memory.
            var dataSource = MemoryDataSource.CreateFrom(streamSource);

            // create mapCSS interpreter.
            var interpreter = new MapCSSInterpreter(mapCSSFile, new MapCSSDictionaryImageSource());

            // add layer to map.
            instance.Map.AddLayer(new LayerOsm(dataSource, interpreter, instance.Map.Projection));

            return instance;
        }
Ejemplo n.º 39
0
 /// <summary>
 /// Registers a reader as the source to filter.
 /// </summary>
 /// <param name="source"></param>
 public virtual void RegisterSource(IEnumerable<OsmGeo> source)
 {
     _source = source.ToOsmStreamSource();
 }
Ejemplo n.º 40
0
        /// <summary>
        /// Creates a new memory data source from all the data in the given osm-stream.
        /// </summary>
        /// <param name="sourceStream"></param>
        /// <returns></returns>
        public static MemoryDataSource CreateFrom(OsmStreamSource sourceStream)
        {
            // reset if possible.
            if (sourceStream.CanReset) { sourceStream.Reset(); }

            // enumerate all objects and add them to a new datasource.
            MemoryDataSource dataSource = new MemoryDataSource();
            foreach (var osmGeo in sourceStream)
            {
                if (osmGeo != null)
                {
                    switch(osmGeo.Type)
                    {
                        case OsmGeoType.Node:
                            dataSource.AddNode(osmGeo as Node);
                            break;
                        case OsmGeoType.Way:
                            dataSource.AddWay(osmGeo as Way);
                            break;
                        case OsmGeoType.Relation:
                            dataSource.AddRelation(osmGeo as Relation);
                            break;
                    }
                }
            }
            return dataSource;
        }
Ejemplo n.º 41
0
        /// <summary>
        /// Tests adding simple tags to the given index.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="index"></param>
        /// <param name="source"></param>
        public static void TestAdd(string name, ITagsCollectionIndex index,
            OsmStreamSource source)
        {
            PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Add", name));
            performanceInfo.Start();
            performanceInfo.Report("Adding tags from {0}...", source.ToString());

            ITagCollectionIndexTests.FillIndex(index, source);

            performanceInfo.Stop();

            Console.Write("", index.Max);
        }
Ejemplo n.º 42
0
 /// <summary>
 /// Tests adding simple tags to the given index.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="source"></param>
 public static void FillIndex(ITagsCollectionIndex index, OsmStreamSource source)
 {
     OsmStreamTargetTags tagsTarget = new OsmStreamTargetTags(index);
     tagsTarget.RegisterSource(source);
     tagsTarget.Pull();
 }
Ejemplo n.º 43
0
 /// <summary>
 /// Creates a new progress reporting source.
 /// </summary>
 /// <param name="reader"></param>
 public OsmStreamFilterProgress(OsmStreamSource reader)
 {
     _reader = reader;
 }
Ejemplo n.º 44
0
        /// <summary>
        /// Creates a router using live interpreted edges.
        /// </summary>
        /// <param name="reader">The OSM-stream reader.</param>
        /// <param name="interpreter">The routing interpreter.</param>
        /// <returns></returns>
        public static Router CreateLiveFrom(OsmStreamSource reader, IOsmRoutingInterpreter interpreter)
        {
            var tagsIndex = new TagsTableCollectionIndex(); // creates a tagged index.

            // read from the OSM-stream.
            var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            memoryData.DropVertexIndex();
            var targetData = new LiveGraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
            targetData.RegisterSource(reader);
            targetData.Pull();
            memoryData.RebuildVertexIndex();

            // creates the live edge router.
            var liveEdgeRouter = new TypedRouterLiveEdge(
                memoryData, interpreter, new Dykstra());

            return new Router(liveEdgeRouter); // create the actual router.
        }
Ejemplo n.º 45
0
 /// <summary>
 /// Registers a simple source on this target with a given cache.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="cache"></param>
 public void RegisterSource(OsmStreamSource source, OsmDataCache cache)
 {
     _source = new OsmSimpleCompleteStreamSource(source, cache);
 }
Ejemplo n.º 46
0
            private void transferData(OsmStreamSource src, OsmStreamTarget sqlTarget)
            {
                src.Initialize();
                sqlTarget.Initialize();

                while (src.MoveNext(false, false, false) && !_shouldStop)
                {

                    OsmGeo sourceObject = src.Current();

                    if (!typeCount.ContainsKey(sourceObject.Type))
                    {
                        typeCount.Add(sourceObject.Type, 0);
                    }

                    typeCount[sourceObject.Type] = 1 + typeCount[sourceObject.Type];

                    if (sourceObject is Node)
                    {
                        sqlTarget.AddNode(sourceObject as Node);
                    }
                    else if (sourceObject is Way)
                    {
                        sqlTarget.AddWay(sourceObject as Way);
                    }
                    else if (sourceObject is Relation)
                    {
                        sqlTarget.AddRelation(sourceObject as Relation);
                    }
                }

                try
                {

                    sqlTarget.Flush();
                    sqlTarget.Close();
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex);
                }
            }
        /// <summary>
        /// Creates a new osm simple complete stream.
        /// </summary>
        /// <param name="source"></param>
        public OsmSimpleCompleteStreamSource(OsmStreamSource source)
        {
            // create an in-memory cache by default.
            _dataCache = new OsmDataCacheMemory();
            _simpleSource = source;

            _nodesToInclude = new HashSet<long>();
            _nodesUsedTwiceOrMore = new Dictionary<long, int>();
            _waysToInclude = new HashSet<long>();
            _waysUsedTwiceOrMore = new Dictionary<long, int>();
            _relationsToInclude = new HashSet<long>();
            _relationsUsedTwiceOrMore = new Dictionary<long, int>();
        }
        /// <summary>
        /// Builds a rendering instance.
        /// </summary>
        /// <param name="streamSource">Source data.</param>
        /// <param name="interpreter">The style interpreter.</param>
        /// <returns></returns>
        public static RenderingInstance Build(OsmStreamSource streamSource, StyleInterpreter interpreter)
        {
            var instance = new RenderingInstance();

            // load data into memory.
            var dataSource = MemoryDataSource.CreateFrom(streamSource);

            // add layer to map.
            instance.Map.AddLayer(new LayerOsm(dataSource, interpreter, instance.Map.Projection));

            return instance;
        }
        /// <summary>
        /// Creates a new osm simple complete stream.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="cache"></param>
        public OsmSimpleCompleteStreamSource(OsmStreamSource source, OsmDataCache cache)
        {
            _dataCache = cache;
            _simpleSource = source;

            _nodesToInclude = new HashSet<long>();
            _nodesUsedTwiceOrMore = new Dictionary<long, int>();
            _waysToInclude = new HashSet<long>();
            _waysUsedTwiceOrMore = new Dictionary<long, int>();
            _relationsToInclude = new HashSet<long>();
            _relationsUsedTwiceOrMore = new Dictionary<long, int>();
        }
Ejemplo n.º 50
0
        /// <summary>
        /// Creates a router using interpreted edges.
        /// </summary>
        /// <param name="reader">The data to route on.</param>
        /// <param name="interpreter">The routing interpreter.</param>
        /// <param name="vehicle">The vehicle profile.</param>
        /// <returns></returns>
        public static Router CreateCHFrom(OsmStreamSource reader,
            IOsmRoutingInterpreter interpreter, Vehicle vehicle)
        {
            var tagsIndex = new TagsIndex(); // creates a tagged index.

            // read from the OSM-stream.
            var data = CHEdgeGraphOsmStreamTarget.Preprocess(
                reader, interpreter, vehicle);

            // creates the edge router.
            var typedRouter = new TypedRouterCHEdge(
                data, interpreter, new CHRouter());

            return new Router(typedRouter); // create the actual router.
        }
        /// <summary>
        /// Builds a tile server instance based on the given osm source and mapcss styles file.
        /// </summary>
        /// <param name="name">The name of the instance-to-be.</param>
        /// <param name="source">The osm source stream.</param>
        /// <param name="mapCSSfile">The stream containing the mapcss.</param>
        /// <param name="cacheFolder"></param>
        private static void BuildTileServer(string name, OsmStreamSource source, Stream mapCSSfile, string cacheFolder)
        {
            try
            {
                // initialize mapcss interpreter.
                var mapCSSInterpreter = new MapCSSInterpreter(mapCSSfile, 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());
                target.RegisterSource(source);
                target.Pull();

                //var merger = new Scene2DObjectMerger();
                //scene = merger.BuildMergedScene(scene);

                OsmSharp.Service.Tiles.RenderingInstance instance = null;
                if (string.IsNullOrWhiteSpace(cacheFolder))
                { // no cache.
                    instance = new OsmSharp.Service.Tiles.RenderingInstance();
                }
                else
                { // use cache.
                    var instanceCacheFolder = Path.Combine(cacheFolder, name);
                    var instanceCacheDirectoryInfo = new DirectoryInfo(instanceCacheFolder);
                    if (!instanceCacheDirectoryInfo.Exists)
                    { // create the directory if it doesn't exists.
                        instanceCacheDirectoryInfo.Create();
                    }
                    var instanceCache = new OsmSharp.Service.Tiles.Cache.TileCache(new DirectoryInfo(instanceCacheFolder));
                    instanceCache.Clear();
                    instance = new OsmSharp.Service.Tiles.RenderingInstance(instanceCache);
                }
                instance.Map.AddLayer(new LayerScene(scene));

                // add a default test instance.
                OsmSharp.Service.Tiles.ApiBootstrapper.AddInstance(name, instance);
            }
            catch (Exception ex)
            {
                OsmSharp.Logging.Log.TraceEvent("Bootstrapper.BuildTileServer", OsmSharp.Logging.TraceEventType.Error,
                    "Failed to setup tile service: " + ex.Message);
            }
        }
Ejemplo n.º 52
0
 /// <summary>
 /// Registers a reader on this writer.
 /// </summary>
 /// <param name="source"></param>
 public virtual void RegisterSource(OsmStreamSource source)
 {
     _source = source;
 }
Ejemplo n.º 53
0
        private bool ConcurrentMoveNext(OsmStreamSource source, out OsmGeo current,
                                        bool ignore_nodes = false, bool igonre_ways = false,
                                        bool ignore_relations = false)
        {
            bool available = false;

            current = null;

            lock (_source_lock)
            {
                if (_cancel_pull)
                {
                    return false;
                }

                available = source.MoveNext();

                if (available)
                {
                    current = source.Current();
                    _pull_progress++;
                }
            }

            return available;
        }
Ejemplo n.º 54
0
 /// <summary>
 /// Registers another source.
 /// </summary>
 /// <param name="source"></param>
 public override void RegisterSource(OsmStreamSource source)
 {
     _sources.Add(source);
 }
Ejemplo n.º 55
0
        /// <summary>
        /// Creates a router using live interpreted edges.
        /// </summary>
        /// <param name="reader">The OSM-stream reader.</param>
        /// <param name="interpreter">The routing interpreter.</param>
        /// <returns></returns>
        public static Router CreateLiveFrom(OsmStreamSource reader, IOsmRoutingInterpreter interpreter)
        {
            var tagsIndex = new SimpleTagsIndex(); // creates a tagged index.

            // read from the OSM-stream.
            var memoryData = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            var targetData = new LiveGraphOsmStreamTarget(memoryData, interpreter, tagsIndex);
            var sorter = new OsmStreamFilterSort();
            sorter.RegisterSource(reader);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            // creates the live edge router.
            var liveEdgeRouter = new TypedRouterLiveEdge(
                memoryData, interpreter, new DykstraRoutingLive(tagsIndex));

            return new Router(liveEdgeRouter); // create the actual router.
        }