/// <summary>
        /// Compares what is in the complete list against the objects in the reference source.
        /// </summary>
        /// <param name="expected"></param>
        /// <param name="actual"></param>
        private void Compare(MemoryDataSource expected, List <ICompleteOsmGeo> actual)
        {
            var exectedList = new List <ICompleteOsmGeo>();

            foreach (var node in expected.GetNodes())
            {
                var completeNode = node;
                if (completeNode != null)
                {
                    exectedList.Add(completeNode);
                }
            }
            foreach (var way in expected.GetWays())
            {
                var completeWay = CompleteWay.CreateFrom(way, expected);
                if (completeWay != null)
                {
                    exectedList.Add(completeWay);
                }
            }
            foreach (var relation in expected.GetRelations())
            {
                var completeRelation = CompleteRelation.CreateFrom(relation, expected);
                if (completeRelation != null)
                {
                    exectedList.Add(completeRelation);
                }
            }

            ComparisonHelpers.CompareComplete(exectedList, actual);
        }
示例#2
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();
        }
示例#3
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();
            }
        }
示例#4
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;
            }
        }
示例#5
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;
            }
        }
        public void Scene2DSimpleSerializeDeserializeTest()
        {
            // create the MapCSS image source.
            var imageSource = new MapCSSDictionaryImageSource();

            // load mapcss style interpreter.
            var mapCSSInterpreter = new MapCSSInterpreter(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.UI.Test.Unittests.Data.MapCSS.test.mapcss"),
                imageSource);

            // initialize the data source.
            var xmlSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.UI.Test.Unittests.Data.test.osm"));
            IEnumerable <OsmGeo> dataSource = xmlSource;
            MemoryDataSource     source     = MemoryDataSource.CreateFrom(xmlSource);

            // get data.
            var scene            = new Scene2DSimple();
            var projection       = new WebMercator();
            GeoCoordinateBox box = null;

            foreach (var osmGeo in dataSource)
            {
                CompleteOsmGeo completeOsmGeo = null;
                switch (osmGeo.Type)
                {
                case OsmGeoType.Node:
                    completeOsmGeo = CompleteNode.CreateFrom(osmGeo as Node);
                    break;

                case OsmGeoType.Way:
                    completeOsmGeo = CompleteWay.CreateFrom(osmGeo as Way,
                                                            source);
                    break;

                case OsmGeoType.Relation:
                    completeOsmGeo = CompleteRelation.CreateFrom(osmGeo as Relation,
                                                                 source);
                    break;
                }

                // update box.
                if (completeOsmGeo != null)
                {
                    if (box == null)
                    {
                        box = completeOsmGeo.BoundingBox;
                    }
                    else if (completeOsmGeo.BoundingBox != null)
                    {
                        box = box + completeOsmGeo.BoundingBox;
                    }
                }

                // translate each object into scene object.
                mapCSSInterpreter.Translate(scene, projection, source, osmGeo as OsmGeo);
            }

            // create the stream.
            var stream = new MemoryStream();

            scene.Serialize(stream, false);

            // deserialize the stream.
            IScene2DPrimitivesSource sceneSource = Scene2DSimple.Deserialize(stream, false);

            if (box != null)
            {
                // query both and get the same results.
                int counter = 100;
                var rand    = new Random();
                while (counter > 0)
                {
                    var queryBox = new GeoCoordinateBox(
                        box.GenerateRandomIn(rand),
                        box.GenerateRandomIn(rand));
                    var    zoomFactor = (float)projection.ToZoomFactor(15);
                    View2D testView   = View2D.CreateFromBounds(
                        projection.LatitudeToY(queryBox.MaxLat),
                        projection.LongitudeToX(queryBox.MinLon),
                        projection.LatitudeToY(queryBox.MinLat),
                        projection.LongitudeToX(queryBox.MaxLon));
                    var testScene = new Scene2DSimple();
                    sceneSource.Get(testScene, testView, zoomFactor);

//                    var resultIndex = new HashSet<Scene2DPrimitive>(testScene.Get(testView, zoomFactor));
//                    var resultReference = new HashSet<Scene2DPrimitive>(scene.Get(testView, zoomFactor));

                    //Assert.AreEqual(resultReference.Count, resultIndex.Count);
                    //foreach (var data in resultIndex)
                    //{
                    //    Assert.IsTrue(resultReference.Contains(data));
                    //}
                    //foreach (var data in resultReference)
                    //{
                    //    Assert.IsTrue(resultIndex.Contains(data));
                    //}
                    counter--;
                }
            }
        }
        /// <summary>
        /// Moves to the next object.
        /// </summary>
        /// <returns></returns>
        public override bool MoveNext()
        {
            if (!_cachingDone)
            { // first seek & cache.
                this.Seek();
                _cachingDone = true;
            }

            while (_simpleSource.MoveNext())
            { // there is data.
                OsmGeo currentSimple = _simpleSource.Current();

                switch (currentSimple.Type)
                {
                case OsmGeoType.Node:
                    // create complete version.
                    _current = currentSimple as Node;

                    if (_current != null && _current.Tags == null)
                    {     // make sure nodes have a default tag collection that is empty not null.
                        _current.Tags = new OsmSharp.Collections.Tags.TagsCollection();
                    }
                    if (_nodesToInclude.Contains(currentSimple.Id.Value))
                    {     // node needs to be cached.
                        _dataCache.AddNode(currentSimple as Node);
                        _nodesToInclude.Remove(currentSimple.Id.Value);
                    }
                    break;

                case OsmGeoType.Way:
                    // create complete way.
                    _current = CompleteWay.CreateFrom(currentSimple as Way, _dataCache);

                    if (_waysToInclude.Contains(currentSimple.Id.Value))
                    {     // keep the way because it is needed later on.
                        _dataCache.AddWay(currentSimple as Way);
                        _waysToInclude.Remove(currentSimple.Id.Value);
                    }
                    else
                    {     // only report that the nodes have been used when the way can be let-go.
                        Way way = currentSimple as Way;
                        if (way.Nodes != null)
                        {     // report usage.
                            way.Nodes.ForEach(x => this.ReportNodeUsage(x));
                        }
                    }
                    break;

                case OsmGeoType.Relation:
                    // create complate relation.
                    _current = CompleteRelation.CreateFrom(currentSimple as Relation, _dataCache);

                    if (!_relationsToInclude.Contains(currentSimple.Id.Value))
                    {     // only report relation usage when the relation can be let go.
                        Relation relation = currentSimple as Relation;
                        if (relation.Members != null)
                        {
                            foreach (RelationMember member in relation.Members)
                            {
                                switch (member.MemberType.Value)
                                {
                                case OsmGeoType.Node:
                                    this.ReportNodeUsage(member.MemberId.Value);
                                    break;

                                case OsmGeoType.Way:
                                    this.ReportWayUsage(member.MemberId.Value);
                                    break;

                                case OsmGeoType.Relation:
                                    this.ReportRelationUsage(member.MemberId.Value);
                                    break;
                                }
                            }
                        }
                    }
                    break;
                }
                if (_current != null)
                { // only return complete objects.
                    return(true);
                }
            }
            return(false);
        }
示例#8
0
        public override bool MoveNext()
        {
            if (!this._cachingDone)
            {
                this.Seek();
                this._cachingDone = true;
            }
            while (this._simpleSource.MoveNext())
            {
                OsmGeo osmGeo = this._simpleSource.Current();
                long?  nullable;
                switch (osmGeo.Type)
                {
                case OsmGeoType.Node:
                    this._current = (ICompleteOsmGeo)(osmGeo as Node);
                    if (this._current != null && this._current.Tags == null)
                    {
                        this._current.Tags = (TagsCollectionBase) new TagsCollection();
                    }
                    HashSet <long> nodesToInclude1 = this._nodesToInclude;
                    nullable = osmGeo.Id;
                    long num1 = nullable.Value;
                    if (nodesToInclude1.Contains(num1))
                    {
                        this._dataCache.AddNode(osmGeo as Node);
                        HashSet <long> nodesToInclude2 = this._nodesToInclude;
                        nullable = osmGeo.Id;
                        long num2 = nullable.Value;
                        nodesToInclude2.Remove(num2);
                        break;
                    }
                    break;

                case OsmGeoType.Way:
                    this._current = (ICompleteOsmGeo)CompleteWay.CreateFrom(osmGeo as Way, (INodeSource)this._dataCache);
                    HashSet <long> waysToInclude1 = this._waysToInclude;
                    nullable = osmGeo.Id;
                    long num3 = nullable.Value;
                    if (waysToInclude1.Contains(num3))
                    {
                        this._dataCache.AddWay(osmGeo as Way);
                        HashSet <long> waysToInclude2 = this._waysToInclude;
                        nullable = osmGeo.Id;
                        long num2 = nullable.Value;
                        waysToInclude2.Remove(num2);
                        break;
                    }
                    Way way = osmGeo as Way;
                    if (way.Nodes != null)
                    {
                        way.Nodes.ForEach <long>((Action <long>)(x => this.ReportNodeUsage(x)));
                        break;
                    }
                    break;

                case OsmGeoType.Relation:
                    this._current = (ICompleteOsmGeo)CompleteRelation.CreateFrom(osmGeo as Relation, (IOsmGeoSource)this._dataCache);
                    HashSet <long> relationsToInclude = this._relationsToInclude;
                    nullable = osmGeo.Id;
                    long num4 = nullable.Value;
                    if (!relationsToInclude.Contains(num4))
                    {
                        Relation relation = osmGeo as Relation;
                        if (relation.Members != null)
                        {
                            using (List <RelationMember> .Enumerator enumerator = relation.Members.GetEnumerator())
                            {
                                while (enumerator.MoveNext())
                                {
                                    RelationMember current = enumerator.Current;
                                    switch (current.MemberType.Value)
                                    {
                                    case OsmGeoType.Node:
                                        nullable = current.MemberId;
                                        this.ReportNodeUsage(nullable.Value);
                                        continue;

                                    case OsmGeoType.Way:
                                        nullable = current.MemberId;
                                        this.ReportWayUsage(nullable.Value);
                                        continue;

                                    case OsmGeoType.Relation:
                                        nullable = current.MemberId;
                                        this.ReportRelationUsage(nullable.Value);
                                        continue;

                                    default:
                                        continue;
                                    }
                                }
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (this._current != null)
                {
                    return(true);
                }
            }
            return(false);
        }
        /// <summary>
        /// Moves to the next object.
        /// </summary>
        /// <returns></returns>
        public override bool MoveNext()
        {
            if (!_cachingDone)
            { // first seek & cache.
                this.Seek();
                this.CacheRelations();
                _cachingDone = true;
            }

            while (_simpleSource.MoveNext())
            { // there is data.
                OsmGeo currentSimple = _simpleSource.Current();

                if (currentSimple.Id == 198214128 || currentSimple.Id == 1014892489)
                {
                    System.Diagnostics.Debug.WriteLine("");
                }

                switch (currentSimple.Type)
                {
                case OsmGeoType.Node:
                    // create complete version.
                    _current = CompleteNode.CreateFrom(currentSimple as Node);
                    if (_nodesToInclude.Contains(currentSimple.Id.Value))
                    {     // node needs to be cached.
                        _dataCache.AddNode(currentSimple as Node);
                        _nodesToInclude.Remove(currentSimple.Id.Value);
                    }
                    break;

                case OsmGeoType.Way:
                    // create complete way.
                    _current = CompleteWay.CreateFrom(currentSimple as Way, _dataCache);

                    if (_waysToInclude.Contains(currentSimple.Id.Value))
                    {     // keep the way because it is needed later on.
                        _dataCache.AddWay(currentSimple as Way);
                        _waysToInclude.Remove(currentSimple.Id.Value);
                    }
                    else
                    {     // only report that the nodes have been used when the way can be let-go.
                        Way way = currentSimple as Way;
                        if (way.Nodes != null)
                        {     // report usage.
                            way.Nodes.ForEach(x => this.ReportNodeUsage(x));
                        }
                    }
                    break;

                case OsmGeoType.Relation:
                    // create complate relation.
                    _current = CompleteRelation.CreateFrom(currentSimple as Relation, _dataCache);

                    if (!_relationsToInclude.Contains(currentSimple.Id.Value))
                    {     // only report relation usage when the relation can be let go.
                        Relation relation = currentSimple as Relation;
                        if (relation.Members != null)
                        {
                            foreach (RelationMember member in relation.Members)
                            {
                                switch (member.MemberType.Value)
                                {
                                case OsmGeoType.Node:
                                    this.ReportNodeUsage(member.MemberId.Value);
                                    break;

                                case OsmGeoType.Way:
                                    this.ReportWayUsage(member.MemberId.Value);
                                    break;

                                case OsmGeoType.Relation:
                                    this.ReportRelationUsage(member.MemberId.Value);
                                    break;
                                }
                            }
                        }
                    }
                    break;
                }
                if (_current != null)
                { // only return complete objects.
                    return(true);
                }
            }
            return(false);
        }