Example #1
0
        /// <summary>
        /// Fills the scene with objects from the given datasource that existing inside the given boundingbox with the given projection.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="box"></param>
        /// <param name="projection"></param>
        public void FillScene(IDataSourceReadOnly dataSource, GeoCoordinateBox box, IProjection projection)
        {
            foreach (var osmGeo in dataSource.Get(box, null))
            { // translate each object into scene object.
                LongIndex index = null;
                switch (osmGeo.Type)
                {
                case Osm.OsmGeoType.Node:
                    index = _interpretedNodes;
                    break;

                case Osm.OsmGeoType.Way:
                    index = _interpretedWays;
                    break;

                case Osm.OsmGeoType.Relation:
                    index = _interpretedRelations;
                    break;
                }
                if (!index.Contains(osmGeo.Id.Value))
                { // object was not yet interpreted.
                    index.Add(osmGeo.Id.Value);

                    _interpreter.Translate(_scene, projection, dataSource, osmGeo);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Adds a layer displaying osm data from a given data source using the given style.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="styleInterpreter"></param>
        /// <returns></returns>
        public LayerOsm AddLayerOsm(IDataSourceReadOnly dataSource, StyleInterpreter styleInterpreter)
        {
            LayerOsm layerOsm = new LayerOsm(dataSource, styleInterpreter, this.Projection);

            this.AddLayer(layerOsm);
            return(layerOsm);
        }
Example #3
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);
            }
        }
Example #4
0
        /// <summary>
        /// Creates a new datasource cache.
        /// </summary>
        /// <param name="source">The data source being wrapped and cached.</param>
        /// <param name="zoom_level">The zoom level to use as a caching structure.</param>
        public DataSourceCache(IDataSourceReadOnly source,int zoom_level)
        {
            _zoom_level = zoom_level;
            _source = source;
            _id = Guid.NewGuid();

            this.InitializeCache();
        }
Example #5
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);
                    }
                }
            }
        }
Example #6
0
        /// <summary>
        /// Creates a new OSM data layer.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="styleInterpreter"></param>
        /// <param name="projection"></param>
        public LayerOsm(IDataSourceReadOnly dataSource, StyleInterpreter styleInterpreter, IProjection projection)
        {
            // build the zoom-level cutoffs.
            List<float> zoomFactors = new List<float>();
            zoomFactors.Add(16);
            zoomFactors.Add(14);
            zoomFactors.Add(12);
            zoomFactors.Add(10);

            _dataSource = dataSource;
            _styleSceneManager = new StyleSceneManager(styleInterpreter, projection, zoomFactors);
        }
Example #7
0
        /// <summary>
        /// Creates a new OSM data layer.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="styleInterpreter"></param>
        /// <param name="projection"></param>
        public LayerOsm(IDataSourceReadOnly dataSource, StyleInterpreter styleInterpreter, IProjection projection)
        {
            // build the zoom-level cutoffs.
            List <float> zoomFactors = new List <float>();

            zoomFactors.Add(16);
            zoomFactors.Add(14);
            zoomFactors.Add(12);
            zoomFactors.Add(10);

            _dataSource        = dataSource;
            _styleSceneManager = new StyleSceneManager(styleInterpreter, projection, zoomFactors);
        }
Example #8
0
        /// <summary>
        /// Interprets an OSM-object and returns the correctponding geometry.
        /// </summary>
        /// <param name="simpleOsmGeo"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public virtual GeometryCollection Interpret(OsmGeo simpleOsmGeo, IDataSourceReadOnly data)
        {
            switch (simpleOsmGeo.Type)
            {
            case OsmGeoType.Node:
                return(this.Interpret(simpleOsmGeo as Node));

            case OsmGeoType.Way:
                return(this.Interpret(CompleteWay.CreateFrom(simpleOsmGeo as Way, data)));

            case OsmGeoType.Relation:
                return(this.Interpret(CompleteRelation.CreateFrom(simpleOsmGeo as Relation, data)));
            }
            throw new ArgumentOutOfRangeException();
        }
Example #9
0
        /// <summary>
        /// Creates a new OSM data layer.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="styleInterpreter"></param>
        public OsmLayer(IDataSourceReadOnly dataSource, StyleInterpreter styleInterpreter, IProjection projection)
        {
            // build the zoom-level cutoffs.
            List <float> zoomLevelCutoffs = new List <float>();

            zoomLevelCutoffs.Add((float)projection.ToZoomFactor(18));
            zoomLevelCutoffs.Add((float)projection.ToZoomFactor(16));
            zoomLevelCutoffs.Add((float)projection.ToZoomFactor(14));
            zoomLevelCutoffs.Add((float)projection.ToZoomFactor(12));
            zoomLevelCutoffs.Add((float)projection.ToZoomFactor(10));
            zoomLevelCutoffs.Add((float)projection.ToZoomFactor(8));

            _dataSource        = dataSource;
            _styleSceneManager = new StyleSceneManager(styleInterpreter, zoomLevelCutoffs);
        }
Example #10
0
        /// <summary>
        /// Creates a new data source.
        /// </summary>
        /// <param name="source"></param>
        public DataSourceLayer(IDataSourceReadOnly source)
        {
            this.Visible = true;
            this.Name = "Data Source Layer";

            _source = source;
            _id = Guid.NewGuid();

            // TODO: Add modification event.
            // _source.
            _default = Color.Blue;

            this.MinZoom = -1;
            this.MaxZoom = -1;
        }
 /// <summary>
 /// Translates the given OSM objects into corresponding geometries.
 /// </summary>
 /// <param name="scene"></param>
 /// <param name="projection"></param>
 /// <param name="source"></param>
 /// <param name="osmGeo"></param>
 public virtual void Translate(Scene2D scene, IProjection projection, IDataSourceReadOnly source, OsmGeo osmGeo)
 {
     switch (osmGeo.Type)
     {
         case OsmGeoType.Node:
             this.Translate(scene, projection, CompleteNode.CreateFrom(osmGeo as Node));
             break;
         case OsmGeoType.Way:
             this.Translate(scene, projection, CompleteWay.CreateFrom(osmGeo as Way, source));
             break;
         case OsmGeoType.Relation:
             this.Translate(scene, projection, CompleteRelation.CreateFrom(osmGeo as Relation, source));
             break;
     }
 }
Example #12
0
        /// <summary>
        /// Creates a new OSM data layer.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="styleInterpreter"></param>
        public LayerOsm(IDataSourceReadOnly dataSource, StyleInterpreter styleInterpreter, IProjection projection)
        {
            // build the zoom-level cutoffs.
            List<float> zoomLevelCutoffs = new List<float>();
            zoomLevelCutoffs.Add((float)projection.ToZoomFactor(18));
            //zoomLevelCutoffs.Add((float)projection.ToZoomFactor(16));
            //zoomLevelCutoffs.Add((float)projection.ToZoomFactor(14));
            //zoomLevelCutoffs.Add((float)projection.ToZoomFactor(12));
            //zoomLevelCutoffs.Add((float)projection.ToZoomFactor(10));
            //zoomLevelCutoffs.Add((float)projection.ToZoomFactor(8));
            zoomLevelCutoffs.Add((float)projection.ToZoomFactor(0));

            _dataSource = dataSource;
            _styleSceneManager = new StyleSceneManager(styleInterpreter, zoomLevelCutoffs);
            //_styleSceneManager = new StyleSceneManager(styleInterpreter);
        }
Example #13
0
        /// <summary>
        /// Creates a new way from a SimpleWay.
        /// </summary>
        /// <param name="simpleWay"></param>
        /// <param name="cache"></param>
        /// <returns></returns>
        public static CompleteWay CreateFrom(Way simpleWay, IDataSourceReadOnly cache)
        {
            if (simpleWay == null)
            {
                throw new ArgumentNullException("simpleWay");
            }
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (simpleWay.Id == null)
            {
                throw new Exception("simpleWay.id is null");
            }

            CompleteWay way = Create(simpleWay.Id.Value);

            way.ChangeSetId = simpleWay.ChangeSetId;
            if (simpleWay.Tags != null)
            {
                foreach (Tag pair in simpleWay.Tags)
                {
                    way.Tags.Add(pair);
                }
            }
            for (int idx = 0; idx < simpleWay.Nodes.Count; idx++)
            {
                long nodeId = simpleWay.Nodes[idx];
                Node node   = cache.GetNode(nodeId);
                if (node != null)
                {
                    way.Nodes.Add(CompleteNode.CreateFrom(node));
                }
                else
                {
                    return(null);
                }
            }
            way.TimeStamp = simpleWay.TimeStamp;
            way.User      = simpleWay.UserName;
            way.UserId    = simpleWay.UserId;
            way.Version   = simpleWay.Version.HasValue ? (long)simpleWay.Version.Value : (long?)null;
            way.Visible   = simpleWay.Visible.HasValue && simpleWay.Visible.Value;

            return(way);
        }
Example #14
0
        public virtual FeatureCollection Interpret(OsmGeo simpleOsmGeo, IDataSourceReadOnly data)
        {
            switch (simpleOsmGeo.Type)
            {
            case OsmGeoType.Node:
                return(this.Interpret((ICompleteOsmGeo)(simpleOsmGeo as Node)));

            case OsmGeoType.Way:
                return(this.Interpret((ICompleteOsmGeo)CompleteWay.CreateFrom(simpleOsmGeo as Way, (INodeSource)data)));

            case OsmGeoType.Relation:
                return(this.Interpret((ICompleteOsmGeo)CompleteRelation.CreateFrom(simpleOsmGeo as Relation, (IOsmGeoSource)data)));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #15
0
        /// <summary>
        /// Tests a few boundingbox queries.
        /// </summary>
        protected void TestBoundingBoxQueries()
        {
            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);

            // get reference data and compare to the real thing!
            GeoCoordinateBox box = memorySource.BoundingBox;
            IList <OsmGeo>   referenceBoxData = memorySource.Get(box, null);
            IList <OsmGeo>   boxData          = dataSource.Get(box, null);

            this.CompareResults(referenceBoxData, boxData);

            // increase box size and compare again.
            box = memorySource.BoundingBox.Resize(0.1);
            referenceBoxData = memorySource.Get(box, null);
            boxData          = dataSource.Get(box, null);
            this.CompareResults(referenceBoxData, boxData);

            // descrese box size and compare again.
            box = memorySource.BoundingBox.Scale(0.5);
            referenceBoxData = memorySource.Get(box, null);
            boxData          = dataSource.Get(box, null);
            this.CompareResults(referenceBoxData, boxData);

            // descrese box size and compare again.
            box = memorySource.BoundingBox.Scale(0.25);
            referenceBoxData = memorySource.Get(box, null);
            boxData          = dataSource.Get(box, null);
            this.CompareResults(referenceBoxData, boxData);

            // descrese box size and compare again.
            box = memorySource.BoundingBox.Scale(0.1);
            referenceBoxData = memorySource.Get(box, null);
            boxData          = dataSource.Get(box, null);
            this.CompareResults(referenceBoxData, boxData);
        }
Example #16
0
        /// <summary>
        /// Translates the given OSM objects into corresponding geometries.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="projection"></param>
        /// <param name="source"></param>
        /// <param name="osmGeo"></param>
        public virtual void Translate(Scene2D scene, IProjection projection, IDataSourceReadOnly source, OsmGeo osmGeo)
        {
            switch (osmGeo.Type)
            {
            case OsmGeoType.Node:
                this.Translate(scene, projection, CompleteNode.CreateFrom(osmGeo as Node));
                break;

            case OsmGeoType.Way:
                this.Translate(scene, projection, CompleteWay.CreateFrom(osmGeo as Way, source));
                break;

            case OsmGeoType.Relation:
                this.Translate(scene, projection, CompleteRelation.CreateFrom(osmGeo as Relation, source));
                break;
            }
        }
Example #17
0
        /// <summary>
        /// Tests if the data present is the data from api.osm.
        /// </summary>
        private void TestData(IDataSourceReadOnly data)
        {
            // test what data is present in the datasource.
            Node node_291738780 = data.GetNode(291738780);
            Assert.IsNotNull(node_291738780);
            Assert.AreEqual(291738780, node_291738780.Id);

            Node node_1727654333 = data.GetNode(1727654333);
            Assert.IsNotNull(node_1727654333);
            Assert.AreEqual(1727654333, node_1727654333.Id);

            Way way_87281441 = data.GetWay(87281441);
            Assert.IsNotNull(way_87281441);
            Assert.AreEqual(87281441, way_87281441.Id);

            Way way_76705106 = data.GetWay(76705106);
            Assert.IsNotNull(way_76705106);
            Assert.AreEqual(76705106, way_76705106.Id);
        }
Example #18
0
 /// <summary>
 /// Translates the given OSM objects into corresponding geometries.
 /// </summary>
 /// <param name="scene"></param>
 /// <param name="projection"></param>
 /// <param name="source"></param>
 /// <param name="osmGeo"></param>
 public virtual void Translate(Scene2D scene, IProjection projection, IDataSourceReadOnly source, OsmGeo osmGeo)
 {
     switch (osmGeo.Type)
     {
         case OsmGeoType.Node:
             var node = osmGeo as Node;
             if(node.Tags == null)
             { // make sure that a node has a tag collection by default.
                 node.Tags= new TagsCollection();
             }
             this.Translate(scene, projection, node);
             break;
         case OsmGeoType.Way:
             this.Translate(scene, projection, CompleteWay.CreateFrom(osmGeo as Way, source));
             break;
         case OsmGeoType.Relation:
             this.Translate(scene, projection, CompleteRelation.CreateFrom(osmGeo as Relation, source));
             break;
     }
 }
Example #19
0
        /// <summary>
        /// Translates the given OSM objects into corresponding geometries.
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="projection"></param>
        /// <param name="source"></param>
        /// <param name="osmGeo"></param>
        public virtual void Translate(Scene2D scene, IProjection projection, IDataSourceReadOnly source, OsmGeo osmGeo)
        {
            switch (osmGeo.Type)
            {
            case OsmGeoType.Node:
                var node = osmGeo as Node;
                if (node.Tags == null)
                {     // make sure that a node has a tag collection by default.
                    node.Tags = new TagsCollection();
                }
                this.Translate(scene, projection, node);
                break;

            case OsmGeoType.Way:
                this.Translate(scene, projection, CompleteWay.CreateFrom(osmGeo as Way, source));
                break;

            case OsmGeoType.Relation:
                this.Translate(scene, projection, CompleteRelation.CreateFrom(osmGeo as Relation, source));
                break;
            }
        }
Example #20
0
        /// <summary>
        /// Renders the given data onto a 100x100 image using bounds around null-island (1,1,-1,-1) and the MapCSS definition.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="mapCSS"></param>
        /// <returns></returns>
        private Bitmap Render(IDataSourceReadOnly dataSource, string mapCSS)
        {
            // create projection.
            WebMercator projection = new WebMercator();

            double[] topLeft     = projection.ToPixel(new Math.Geo.GeoCoordinate(1, 1));
            double[] bottomRight = projection.ToPixel(new Math.Geo.GeoCoordinate(-1, -1));

            // create view (this comes down to (1,1,-1,-1) for a size of 100x100).
            View2D view = View2D.CreateFromBounds(bottomRight[1], topLeft[0], topLeft[1], bottomRight[0]);
            //View2D view = View2D.CreateFrom(0, 0, 100, 100, 1.0 / 200.0, false, true);

            // create graphics
            Bitmap   rendering         = new Bitmap(100, 100);
            Graphics renderingGraphics = Graphics.FromImage(rendering);

            renderingGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            renderingGraphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            renderingGraphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            renderingGraphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            // create renderer.
            GraphicsRenderer2D     graphicsRenderer = new GraphicsRenderer2D();
            MapRenderer <Graphics> renderer         = new MapRenderer <Graphics>(graphicsRenderer);

            // create map.
            OsmSharp.UI.Map.Map map = new OsmSharp.UI.Map.Map();
            map.AddLayer(new LayerOsm(dataSource, new MapCSSInterpreter(mapCSS), projection));

            // notify the map that there was a view change!
            map.ViewChanged((float)view.CalculateZoom(100, 100), new Math.Geo.GeoCoordinate(0, 0), view);

            // ... and finally do the actual rendering.
            renderer.Render(Graphics.FromImage(rendering), map, view);

            //rendering.Save(@"c:\temp\rendering.bmp");

            return(rendering);
        }
        /// <summary>
        /// Renders the given data onto a 100x100 image using bounds around null-island (1,1,-1,-1) and the MapCSS definition.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="mapCSS"></param>
        /// <returns></returns>
        private Bitmap Render(IDataSourceReadOnly dataSource, string mapCSS)
        {
            // create projection.
            WebMercator projection = new WebMercator();
            double[] topLeft = projection.ToPixel(new Math.Geo.GeoCoordinate(1, 1));
            double[] bottomRight = projection.ToPixel(new Math.Geo.GeoCoordinate(-1, -1));

            // create view (this comes down to (1,1,-1,-1) for a size of 100x100).
            View2D view = View2D.CreateFromBounds(bottomRight[1], topLeft[0], topLeft[1], bottomRight[0]);
            //View2D view = View2D.CreateFrom(0, 0, 100, 100, 1.0 / 200.0, false, true);

            // create graphics
            Bitmap rendering = new Bitmap(100, 100);
            Graphics renderingGraphics = Graphics.FromImage(rendering);
            renderingGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            renderingGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            renderingGraphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            renderingGraphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

            // create renderer.
            GraphicsRenderer2D graphicsRenderer = new GraphicsRenderer2D();
            MapRenderer<Graphics> renderer = new MapRenderer<Graphics>(graphicsRenderer);

            // create map.
            OsmSharp.UI.Map.Map map = new OsmSharp.UI.Map.Map();
            map.AddLayer(new LayerOsm(dataSource, new MapCSSInterpreter(mapCSS), projection));

            // notify the map that there was a view change!
            map.ViewChanged((float)view.CalculateZoom(100, 100), new Math.Geo.GeoCoordinate(0, 0), view);

            // ... and finally do the actual rendering.
            renderer.Render(Graphics.FromImage(rendering), map, view);

            //rendering.Save(@"c:\temp\rendering.bmp");

            return rendering;
        }
Example #22
0
        /// <summary>
        /// Tests writing data and getting relations using it's members.
        /// </summary>
        protected void TestGetRelationsForMember()
        {
            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.Relation:
                    Relation relation = (source.Current() as Relation);
                    target.AddRelation(relation);
                    target.Flush();

                    if (relation.Members != null)
                    {
                        foreach (var member in relation.Members)
                        {
                            OsmGeoType type = OsmGeoType.Node;
                            switch (member.MemberType.Value)
                            {
                            case OsmGeoType.Node:
                                type = OsmGeoType.Node;
                                break;

                            case OsmGeoType.Way:
                                type = OsmGeoType.Way;
                                break;

                            case OsmGeoType.Relation:
                                type = OsmGeoType.Relation;
                                break;
                            }
                            IList <Relation> relations = dataSource.GetRelationsFor(type, member.MemberId.Value);
                            Assert.IsNotNull(relations);
                            Assert.IsTrue(relations.Count > 0);
                            List <Relation> foundRelations = new List <Relation>(relations.Where <Relation>(x => x.Id == relation.Id));
                            Assert.AreEqual(1, foundRelations.Count);
                        }
                    }
                    break;
                }
            }

            MemoryDataSource memorySource = MemoryDataSource.CreateFrom(source);

            foreach (Relation relation in memorySource.GetRelations())
            {
                if (relation.Members != null)
                {
                    foreach (var member in relation.Members)
                    {
                        OsmGeoType type = OsmGeoType.Node;
                        switch (member.MemberType.Value)
                        {
                        case OsmGeoType.Node:
                            type = OsmGeoType.Node;
                            break;

                        case OsmGeoType.Way:
                            type = OsmGeoType.Way;
                            break;

                        case OsmGeoType.Relation:
                            type = OsmGeoType.Relation;
                            break;
                        }
                        IList <Relation> relations = dataSource.GetRelationsFor(type, member.MemberId.Value);
                        Assert.IsNotNull(relations);
                        Assert.IsTrue(relations.Count > 0);
                        List <Relation> foundRelations = new List <Relation>(relations.Where <Relation>(x => x.Id == relation.Id));
                        Assert.AreEqual(1, foundRelations.Count);
                    }
                }
                break;
            }
        }
 /// <summary>
 /// Creates a new named source.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="dataSourceReadOnly"></param>
 public NamedSource(string name, IDataSourceReadOnly dataSourceReadOnly)
 {
     _name = name;
     _dataSourceReadOnly = dataSourceReadOnly;
 }
Example #24
0
 /// <summary>
 /// Adds a layer displaying osm data from a given data source using the given style.
 /// </summary>
 /// <param name="dataSource"></param>
 /// <param name="styleInterpreter"></param>
 /// <returns></returns>
 public LayerOsm AddLayerOsm(IDataSourceReadOnly dataSource, StyleInterpreter styleInterpreter)
 {
     LayerOsm layerOsm = new LayerOsm(dataSource, styleInterpreter, this.Projection);
     this.AddLayer(layerOsm);
     return layerOsm;
 }
Example #25
0
 /// <summary>
 /// Creates a new datasource cache.
 /// </summary>
 /// <param name="source"></param>
 public DataSourceCache(IDataSourceReadOnly source)
 {
     _source = source;
 }
Example #26
0
 /// <summary>
 /// Creates a new data source.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="default_color"></param>
 public DataSourceLayer(
     IDataSourceReadOnly source,
     Color default_color)
     : this(source)
 {
     _default = default_color;
 }
Example #27
0
        internal LayerOsm AddLayerOsm(IDataSourceReadOnly dataSource, StyleInterpreter interpreter = null)
        {
            var osmLayer = _map.AddLayerOsm(dataSource, interpreter ?? DefaultInterpreter);

            if (Center == null && dataSource.BoundingBox != null)
            {
                Center = dataSource.BoundingBox.Center;
            }

            return osmLayer;
        }
 /// <summary>
 /// Creates a new named source.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="dataSourceReadOnly"></param>
 public NamedSource(string name, IDataSourceReadOnly dataSourceReadOnly)
 {
     _name = name;
     _dataSourceReadOnly = dataSourceReadOnly;
 }
        /// <summary>
        /// Fills the scene with objects from the given datasource that existing inside the given boundingbox with the given projection.
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="box"></param>
        /// <param name="projection"></param>
        public void FillScene(IDataSourceReadOnly dataSource, GeoCoordinateBox box, IProjection projection)
        {
            IList<Osm.OsmGeo> osmGeos = dataSource.Get(box, null);
            foreach (var osmGeo in osmGeos)
            { // translate each object into scene object.
                LongIndex index = null;
                switch (osmGeo.Type)
                {
                    case Osm.OsmGeoType.Node:
                        index = _interpretedNodes;
                        break;
                    case Osm.OsmGeoType.Way:
                        index = _interpretedWays;
                        break;
                    case Osm.OsmGeoType.Relation:
                        index = _interpretedRelations;
                        break;
                }
                if (!index.Contains(osmGeo.Id.Value))
                { // object was not yet interpreted.
                    index.Add(osmGeo.Id.Value);

                    _interpreter.Translate(_scene, projection, dataSource, osmGeo);
                }
            }
        }
 /// <summary>
 /// Interprets an OSM-object and returns the correctponding geometry.
 /// </summary>
 /// <param name="simpleOsmGeo"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public virtual GeometryCollection Interpret(OsmGeo simpleOsmGeo, IDataSourceReadOnly data)
 {
     switch (simpleOsmGeo.Type)
     {
         case OsmGeoType.Node:
             return this.Interpret(simpleOsmGeo as Node);
         case OsmGeoType.Way:
             return this.Interpret(CompleteWay.CreateFrom(simpleOsmGeo as Way, data));
         case OsmGeoType.Relation:
             return this.Interpret(CompleteRelation.CreateFrom(simpleOsmGeo as Relation, data));
     }
     throw new ArgumentOutOfRangeException();
 }
Example #31
0
        /// <summary>
        /// Completes the collection, fetching optional missing elements
        /// </summary>
        /// <param name="source">The source to search for missing elements from</param>
        /// <param name="relation_nodes">Find missing nodes from relations?</param>
        /// <param name="relation_ways">Find missing ways from relations?</param>
        /// <param name="relation_relations">Find missing relations from relations?</param>
        public OsmGeoCollection Complete(IDataSourceReadOnly source,
                                         bool relation_nodes     = false,
                                         bool relation_ways      = false,
                                         bool relation_relations = false)
        {
            var missing_node_ids = new List <long>();
            var missing_way_ids  = new List <long>();

            // search relations for missing relations
            if (relation_relations)
            {
                var missing_relation_ids = new List <long>();

                do
                {
                    foreach (var relation in Relations)
                    {
                        foreach (var member in relation.Value.Members)
                        {
                            if (member.MemberType.Value == OsmGeoType.Relation)
                            {
                                if (!Relations.ContainsKey(member.MemberId.Value))
                                {
                                    missing_relation_ids.Add(member.MemberId.Value);
                                }
                            }
                        }
                    }

                    var found_relations = source.GetRelations(missing_relation_ids);

                    foreach (var found_relation in found_relations)
                    {
                        if (!Relations.ContainsKey(found_relation.Id.Value))
                        {
                            Relations.Add(found_relation.Id.Value, found_relation);
                        }
                    }
                } while (missing_relation_ids.Count > 0);
            }

            // search relations for missing ways and nodes
            if (relation_ways || relation_nodes)
            {
                foreach (var relation in Relations)
                {
                    foreach (var member in relation.Value.Members)
                    {
                        if (member.MemberType.Value == OsmGeoType.Node)
                        {
                            if (relation_nodes)
                            {
                                if (!Nodes.ContainsKey(member.MemberId.Value))
                                {
                                    missing_node_ids.Add(member.MemberId.Value);
                                }
                            }
                        }
                        else if (member.MemberType.Value == OsmGeoType.Way)
                        {
                            if (relation_ways)
                            {
                                if (!Ways.ContainsKey(member.MemberId.Value))
                                {
                                    missing_way_ids.Add(member.MemberId.Value);
                                }
                            }
                        }
                        else if (member.MemberType.Value == OsmGeoType.Relation)
                        {
                            if (relation_relations)
                            {
                                if (!Relations.ContainsKey(member.MemberId.Value))
                                {
                                    throw new NotImplementedException();
                                }
                            }
                        }
                    }
                }
            }

            // fetch missing ways
            var found_ways = source.GetWays(missing_way_ids);

            foreach (var found_way in found_ways)
            {
                Ways.Add(found_way.Id.Value, found_way);
            }

            // search ways for missing nodes
            foreach (var way in Ways)
            {
                foreach (var node_id in way.Value.Nodes)
                {
                    if (!Nodes.ContainsKey(node_id))
                    {
                        missing_node_ids.Add(node_id);
                    }
                }
            }

            // fetch missing nodes
            var found_nodes = source.GetNodes(missing_node_ids);

            foreach (var found_node in found_nodes)
            {
                Nodes.Add(found_node.Id.Value, found_node);
            }

            return(this);
        }
Example #32
0
        /// <summary>
        /// Creates a relation from a SimpleRelation.
        /// </summary>
        /// <param name="simpleRelation"></param>
        /// <param name="cache"></param>
        /// <returns></returns>
        public static CompleteRelation CreateFrom(Relation simpleRelation, IDataSourceReadOnly cache)
        {
            if (simpleRelation == null)
            {
                throw new ArgumentNullException("simpleRelation");
            }
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (simpleRelation.Id == null)
            {
                throw new Exception("simpleRelation.Id is null");
            }

            CompleteRelation relation = Create(simpleRelation.Id.Value);

            relation.ChangeSetId = simpleRelation.ChangeSetId;
            foreach (Tag pair in simpleRelation.Tags)
            {
                relation.Tags.Add(pair);
            }
            for (int idx = 0; idx < simpleRelation.Members.Count; idx++)
            {
                long   memberId = simpleRelation.Members[idx].MemberId.Value;
                string role     = simpleRelation.Members[idx].MemberRole;

                var member = new CompleteRelationMember();
                member.Role = role;
                switch (simpleRelation.Members[idx].MemberType.Value)
                {
                case OsmGeoType.Node:
                    Node simpleNode = cache.GetNode(memberId);
                    if (simpleNode != null)
                    {
                        member.Member = CompleteNode.CreateFrom(simpleNode);
                    }
                    else
                    {
                        return(null);
                    }
                    break;

                case OsmGeoType.Way:
                    Way simpleWay = cache.GetWay(memberId);
                    if (simpleWay != null)
                    {
                        member.Member = CompleteWay.CreateFrom(simpleWay, cache);
                    }
                    else
                    {
                        return(null);
                    }
                    break;

                case OsmGeoType.Relation:
                    Relation simpleRelationMember = cache.GetRelation(memberId);
                    if (simpleRelationMember != null)
                    {
                        member.Member = CompleteRelation.CreateFrom(simpleRelationMember, cache);
                    }
                    else
                    {
                        return(null);
                    }
                    break;
                }
                relation.Members.Add(member);
            }
            relation.TimeStamp = simpleRelation.TimeStamp;
            relation.User      = simpleRelation.UserName;
            relation.UserId    = simpleRelation.UserId;
            relation.Version   = simpleRelation.Version.HasValue ? (long)simpleRelation.Version.Value : (long?)null;
            relation.Visible   = simpleRelation.Visible.HasValue && simpleRelation.Visible.Value;

            return(relation);
        }
Example #33
0
 public DataSourceCache(IDataSourceReadOnly source)
 {
     this._source = source;
 }