public void TestUpdate_OsmChangeFileWithModification_ShouldUpdateDatabase()
        {
            var way = new CompleteWay()
            {
                Id   = 1,
                Tags = new TagsCollection {
                    { "highway", "track" }, { "route", "bicycle" }
                },
                Nodes = new Node[0]
            };
            var changes = new OsmChange
            {
                Create = new OsmGeo[0],
                Modify = new OsmGeo[] { way.ToSimple() },
                Delete = new OsmGeo[0]
            };
            var list = new List <Feature> {
                new Feature(new LineString(new Coordinate[0]), new AttributesTable())
            };

            _geoJsonPreprocessorExecutor
            .Preprocess(Arg.Is <Dictionary <string, List <ICompleteOsmGeo> > >(x => x.Values.Count == 1))
            .Returns(list);
            _geoJsonPreprocessorExecutor
            .Preprocess(Arg.Is <List <CompleteWay> >(x => x.Count == 1))
            .Returns(list);
            _osmGateway.GetCompleteWay(1).Returns(way);

            _service.Update(changes).Wait();

            _elasticSearchGateway.Received(1).UpdatePointsOfInterestData(Arg.Is <List <Feature> >(x => x.Count == 1));
            _elasticSearchGateway.Received(1).UpdateHighwaysData(Arg.Is <List <Feature> >(x => x.Count == 1));
        }
示例#2
0
        public void TestToSimple()
        {
            var completeWay = new CompleteWay()
            {
                ChangeSetId = 1,
                Id          = 10,
                Nodes       = new Node[]
                {
                    new Node()
                    {
                        Id = 1
                    },
                    new Node()
                    {
                        Id = 2
                    },
                    new Node()
                    {
                        Id = 3
                    }
                },
                Tags = new Tags.TagsCollection(
                    new Tags.Tag("tag1", "value1"),
                    new Tags.Tag("tag2", "value2")),
                TimeStamp = DateTime.Now,
                UserName  = "******",
                UserId    = 1,
                Version   = 23,
                Visible   = true
            };

            var osmGeo = completeWay.ToSimple();

            Assert.IsNotNull(osmGeo);
            Assert.IsInstanceOf <Way>(osmGeo);

            var way = osmGeo as Way;

            Assert.AreEqual(completeWay.Id, way.Id);
            Assert.AreEqual(completeWay.ChangeSetId, way.ChangeSetId);
            Assert.AreEqual(completeWay.TimeStamp, way.TimeStamp);
            Assert.AreEqual(completeWay.UserName, way.UserName);
            Assert.AreEqual(completeWay.UserId, way.UserId);
            Assert.AreEqual(completeWay.Version, way.Version);
            Assert.AreEqual(completeWay.Visible, way.Visible);
            Assert.IsNotNull(way.Nodes);
            Assert.AreEqual(completeWay.Nodes.Length, way.Nodes.Length);
            for (var i = 0; i < completeWay.Nodes.Length; i++)
            {
                Assert.AreEqual(completeWay.Nodes[i].Id, way.Nodes[i]);
            }
        }
        public void TestUpdate_OsmChangeFileWithModification_ShouldUpdateDatabaseUsingPoiPrefixFromDatabase()
        {
            var way = new CompleteWay()
            {
                Id   = 1,
                Tags = new TagsCollection {
                    { "highway", "track" }, { "route", "bicycle" }
                },
                Nodes = new Node[0]
            };
            var changes = new OsmChange
            {
                Create = new OsmGeo[0],
                Modify = new OsmGeo[] { way.ToSimple() },
                Delete = new OsmGeo[0]
            };
            var wayFeature = new Feature(new LineString(new Coordinate[0]), new AttributesTable {
                { FeatureAttributes.ID, "1" },
                { FeatureAttributes.POI_SOURCE, Sources.OSM }
            });

            wayFeature.SetId();
            var wayFeatureInDatabase = new Feature(new LineString(new Coordinate[0]), new AttributesTable {
                { FeatureAttributes.ID, "1" },
                { FeatureAttributes.POI_CATEGORY, Categories.HISTORIC },
                { FeatureAttributes.POI_SOURCE, Sources.OSM }
            });

            wayFeatureInDatabase.SetId();
            var list = new List <Feature> {
                wayFeature
            };

            _geoJsonPreprocessorExecutor
            .Preprocess(Arg.Is <Dictionary <string, List <ICompleteOsmGeo> > >(x => x.Values.Count == 1))
            .Returns(list);
            _geoJsonPreprocessorExecutor
            .Preprocess(Arg.Is <List <CompleteWay> >(x => x.Count == 1))
            .Returns(list);
            _osmGateway.GetCompleteWay(1).Returns(way);
            _elasticSearchGateway.GetPointOfInterestById("way_1", Sources.OSM).Returns(wayFeatureInDatabase);

            _service.Update(changes).Wait();

            _elasticSearchGateway.Received(1).UpdatePointsOfInterestData(Arg.Is <List <Feature> >(x => x.Count == 1 && x.First().Attributes.Exists(FeatureAttributes.POI_CATEGORY)));
        }
示例#4
0
        private Way AddNewNodeToExistingWay(string nodeId, CompleteWay closestCompleteWay, LineString closestItmHighway, int indexOnWay, Point itmPoint)
        {
            var indexToInsert = indexOnWay;

            if (indexOnWay != closestItmHighway.Coordinates.Length - 1)
            {
                // HM TODO: fix this using projection
                var postItmLine = new LineString(new [] { closestItmHighway.Coordinates[indexOnWay], closestItmHighway.Coordinates[indexOnWay + 1] });
                if (postItmLine.Distance(itmPoint) <= _options.DistanceToExisitngLineMergeThreshold)
                {
                    indexToInsert = indexOnWay + 1;
                }
            }

            var simpleWay   = (Way)closestCompleteWay.ToSimple();
            var updatedList = simpleWay.Nodes.ToList();

            updatedList.Insert(indexToInsert, long.Parse(nodeId));
            simpleWay.Nodes = updatedList.ToArray();
            return(simpleWay);
        }
示例#5
0
        private void SetupHighway(int wayId, Coordinate[] coordinates, IAuthClient osmGateway)
        {
            var osmCompleteWay = new CompleteWay {
                Id = wayId
            };
            var id = 1;

            osmCompleteWay.Nodes = coordinates.Select(coordinate => new Node {
                Id = id++, Latitude = coordinate.Y, Longitude = coordinate.X
            }).ToArray();
            osmGateway.GetCompleteWay(wayId).Returns(osmCompleteWay);
            osmGateway.GetWay(wayId).Returns(osmCompleteWay.ToSimple() as Way);
            var table = new AttributesTable
            {
                { FeatureAttributes.ID, wayId.ToString() },
                { FeatureAttributes.POI_OSM_NODES, osmCompleteWay.Nodes.Select(n => n.Id.Value).Cast <object>().ToList() }
            };

            _elasticSearchGateway.GetHighways(Arg.Any <Coordinate>(), Arg.Any <Coordinate>()).Returns(new List <Feature>
            {
                new Feature(new LineString(coordinates), table)
            });
        }