public void TestRandomBlockTagSerializatonNonBeginPosition()
        {
            SimpleTagsIndex tagsIndex = new SimpleTagsIndex();

            SimpleTagsCollection tagsCollection = new SimpleTagsCollection();
            for (int i = 0; i < 100; i++)
            {
                int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10) + 1;
                for (int idx = 0; idx < tagCollectionSize; idx++)
                {
                    int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10);
                    tagsCollection.Add(
                        string.Format("key_{0}", tagValue),
                        string.Format("value_{0}", tagValue));
                }
                uint tagsId = tagsIndex.Add(tagsCollection);
            }

            ITagsIndexReadonly tagsIndexReadonly = this.SerializeDeserializeBlock(tagsIndex, 10, 123);
            Assert.AreEqual(tagsIndex.Max, tagsIndexReadonly.Max);
            for (uint idx = 0; idx < tagsIndex.Max; idx++)
            {
                this.CompareTagsCollections(tagsIndex.Get(idx),
                    tagsIndexReadonly.Get(idx));
            }
        }
Beispiel #2
0
        public void TestEdgeMatcher()
        {
            IEdgeMatcher matcher = new DefaultEdgeMatcher();

            // create edge tags.
            var edgeTags = new SimpleTagsCollection();
            //edge_tags["highway"] = "footway";

            // create point tags.
            var pointTags = new SimpleTagsCollection();
            //point_tags["highway"] = "footway";

            // test with empty point tags.
            Assert.IsTrue(matcher.MatchWithEdge(Vehicle.Car, null, null));
            Assert.IsTrue(matcher.MatchWithEdge(Vehicle.Car, pointTags, null));

            // test with empty edge tags.
            pointTags["name"] = "Ben Abelshausen Boulevard";
            Assert.IsFalse(matcher.MatchWithEdge(Vehicle.Car, pointTags, null));
            Assert.IsFalse(matcher.MatchWithEdge(Vehicle.Car, pointTags, edgeTags));

            // test with matching name.
            edgeTags["name"] = "Ben Abelshausen Boulevard";
            Assert.IsTrue(matcher.MatchWithEdge(Vehicle.Car, pointTags, edgeTags));

            // test with none-matching name.
            edgeTags["name"] = "Jorieke Vyncke Boulevard";
            Assert.IsFalse(matcher.MatchWithEdge(Vehicle.Car, pointTags, edgeTags));
        }
        public void MapCSSEvalTagTest()
        {
            string function = "tag('width')";
            TagsCollection tags = new SimpleTagsCollection();
            tags.Add("width", "2");

            Assert.AreEqual(2, EvalInterpreter.Instance.InterpretDouble(function, tags));
        }
        /// <summary>
        /// Tests an empty tags collection.
        /// </summary>
        protected void TestTagsCollectionSimple()
        {
            TagsCollection collection = new SimpleTagsCollection();

            collection["simple"] = "yes";

            Assert.IsTrue(collection.ContainsKey("simple"));
            Assert.IsTrue(collection.ContainsKeyValue("simple","yes"));
            Assert.AreEqual("yes", collection["simple"]);
            Assert.AreEqual(1, collection.Count);
        }
Beispiel #5
0
        /// <summary>
        /// Tests the probable speed.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="speed"></param>
        /// <param name="tags"></param>
        protected void TextProbableSpeed(Vehicle vehicle, double speed, params string[] tags)
        {
            // build tags collection.
            SimpleTagsCollection tagsCollection = new SimpleTagsCollection();
            for (int idx = 0; idx < tags.Length; idx = idx + 2)
            {
                tagsCollection.Add(tags[idx], tags[idx + 1]);
            }

            Assert.AreEqual(speed, vehicle.ProbableSpeed(tagsCollection).Value);
        }
        public void TestBooleanParsing()
        {
            // test IsTrue.
            TagsCollection tags = new SimpleTagsCollection();
            tags.Add("area", "yes");
            Assert.IsTrue(tags.IsTrue("area"));

            tags = new SimpleTagsCollection();
            tags.Add("area", "1");
            Assert.IsTrue(tags.IsTrue("area"));

            tags = new SimpleTagsCollection();
            tags.Add("area", "true");
            Assert.IsTrue(tags.IsTrue("area"));

            tags = new SimpleTagsCollection();
            tags.Add("area", "false");
            Assert.IsFalse(tags.IsTrue("area"));

            tags = new SimpleTagsCollection();
            tags.Add("area", "0");
            Assert.IsFalse(tags.IsTrue("area"));

            tags = new SimpleTagsCollection();
            tags.Add("area", "no");
            Assert.IsFalse(tags.IsTrue("area"));

            // test IsFalse.
            tags = new SimpleTagsCollection();
            tags.Add("area", "yes");
            Assert.IsFalse(tags.IsFalse("area"));

            tags = new SimpleTagsCollection();
            tags.Add("area", "1");
            Assert.IsFalse(tags.IsFalse("area"));

            tags = new SimpleTagsCollection();
            tags.Add("area", "true");
            Assert.IsFalse(tags.IsFalse("area"));

            tags = new SimpleTagsCollection();
            tags.Add("area", "false");
            Assert.IsTrue(tags.IsFalse("area"));

            tags = new SimpleTagsCollection();
            tags.Add("area", "0");
            Assert.IsTrue(tags.IsFalse("area"));

            tags = new SimpleTagsCollection();
            tags.Add("area", "no");
            Assert.IsTrue(tags.IsFalse("area"));
        }
        /// <summary>
        /// Returns the tags with the given id.
        /// </summary>
        /// <param name="tagsId"></param>
        /// <returns></returns>
        public TagsCollection Get(uint tagsId)
        {
            OsmTags osmTags = _tagsCollectionTable.Get(tagsId);

            if (osmTags != null)
            {
                SimpleTagsCollection collection = new SimpleTagsCollection();
                for (int idx = 0; idx < osmTags.Tags.Length; idx++)
                {
                    collection.Add(
                        _tagsTable.Get(osmTags.Tags[idx]));
                }
                return(collection);
            }
            return(null);
        }
Beispiel #8
0
        /// <summary>
        /// Tests the can traverse functionality.
        /// </summary>
        protected void TestVehicleCanTranverse(Vehicle vehicle, bool result, params string[] tags)
        {
            // build tags collection.
            SimpleTagsCollection tagsCollection = new SimpleTagsCollection();
            for (int idx = 0; idx < tags.Length; idx = idx + 2)
            {
                tagsCollection.Add(tags[idx], tags[idx + 1]);
            }

            if (result)
            { // assume the result is true.
                Assert.IsTrue(vehicle.CanTraverse(tagsCollection));
            }
            else
            { // assume the result is false.
                Assert.IsFalse(vehicle.CanTraverse(tagsCollection));
            }
        }
        /// <summary>
        /// Creates the tags in the given table.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="new_tags"></param>
        /// <param name="table"></param>
        /// <param name="ref_column"></param>
        public void CreateTags(long id, TagsCollection new_tags, string table, string ref_column)
        {
            OracleCommand command;

            // copy the source tags dictionary.
            TagsCollection tagsToInsert;
            if (new_tags == null)
            {
                tagsToInsert = new SimpleTagsCollection();
            }
            else
            {
                tagsToInsert = new SimpleTagsCollection(new_tags);
            }

            // insert tags.
            foreach (Tag pair in tagsToInsert)
            {
                command = this.CreateCommand(string.Format("insert into {0} ({1},key,value) values (:{1},:key,:value)", table, ref_column));
                command.Parameters.Add(new OracleParameter("ref_column", id));
                command.Parameters.Add(new OracleParameter("key", pair.Key));
                command.Parameters.Add(new OracleParameter("value", pair.Value));

                command.ExecuteNonQuery();
                command.Dispose();
            }
        }
        /// <summary>
        /// Tests an empty tags collection.
        /// </summary>
        protected void TestTagsCollectionEmpty()
        {
            TagsCollection collection = new SimpleTagsCollection();

            Assert.AreEqual(0, collection.Count);
        }
        /// <summary>
        /// Converts the given tagscollection from a tags list.
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        public static TagsCollection ConvertFrom(List<RedisTag> tags)
        {
            TagsCollection redisTags = null;
            if (tags != null)
            {
                redisTags = new SimpleTagsCollection();
                if (tags != null)
                {
                    foreach (RedisTag redisTag in tags)
                    {
                        Tag tag = new Tag();
                        tag.Key = redisTag.Key;
                        tag.Value = redisTag.Value;

                        redisTags.Add(tag);
                    }
                }
            }
            return redisTags;
        }
Beispiel #12
0
 /// <summary>
 /// Converts a RouteTags array to a list of KeyValuePairs.
 /// </summary>
 /// <param name="tags"></param>
 /// <returns></returns>
 public static TagsCollection ConvertToTagsCollection(this RouteTags[] tags)
 {
     var tagsList = new SimpleTagsCollection();
     if (tags != null)
     {
         foreach (RouteTags pair in tags)
         {
             tagsList.Add(new Tag(pair.Key, pair.Value));
         }
     }
     return tagsList;
 }
        public void TestOsmRoutingInterpreterCanBeTraversedBy()
        {
            var interpreter = new OsmRoutingInterpreter();

            TagsCollection tags = new SimpleTagsCollection();
            tags["highway"] = "footway";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "cycleway";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "bridleway";
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "path";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "pedestrian";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "road";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "living_street";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "residential";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "unclassified";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "tertiary";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "secondary";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "primary";
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "trunk";
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));

            tags["highway"] = "motorway";
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle));
            Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck));
            Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus));
        }
        private void ModifyTags(long id, TagsCollection neTags, string table, string refColumn)
        {
            OracleCommand command;

            TagsCollection tagsToInsert = null;
            if (neTags == null)
            {
                tagsToInsert = new SimpleTagsCollection();
            }
            else
            {
                tagsToInsert = new SimpleTagsCollection(neTags);
            }

            // suppose there are no tags present yet.
            TagsCollection tags_to_update = new SimpleTagsCollection();
            TagsCollection tags_to_delete = new SimpleTagsCollection();

            // adjust the data based on the tags already present.
            command = this.CreateCommand(string.Format("select * from {0} where {1}=:{1}",table,refColumn));
            command.Parameters.Add(refColumn, id);

            OracleDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                string k = reader["key"].ToStringEmptyWhenNull();
                string v = reader["value"].ToStringEmptyWhenNull();

                if (tagsToInsert.ContainsKey(k))
                {
                    // there is at least an update or no insert.
                    string new_value = tagsToInsert[k];
                    tagsToInsert.RemoveKeyValue(new Tag(k, v));

                    // see if there is an update needed.
                    if (new_value != v)
                    {
                        // tags need to be updated.
                        tags_to_update.Add(k, new_value);
                    }
                }
                else
                {
                    // tags are not found; delete them!
                    tags_to_delete.Add(k, v);
                }
            }
            reader.Close();

            // delete old tags.
            foreach(Tag tag in tags_to_delete)
            {
                command = this.CreateCommand(string.Format("delete from {0} where {1}=:{1} and key=:key", table, refColumn));
                command.Parameters.Add(new OracleParameter(refColumn, id));
                command.Parameters.Add(new OracleParameter("key", tag.Key));

                command.ExecuteNonQuery();
                command.Dispose();
            }

            // update tags.
            foreach (Tag pair in tags_to_update)
            {
                command = this.CreateCommand(string.Format("update {0} set value=:value where {1}=:{1} and key=:key", table, refColumn));
                command.Parameters.Add(new OracleParameter("value", pair.Value));
                command.Parameters.Add(new OracleParameter(refColumn, id));
                command.Parameters.Add(new OracleParameter("key", pair.Key));

                command.ExecuteNonQuery();
                command.Dispose();
            }

            // insert tags.
            foreach (Tag pair in tagsToInsert)
            {
                command = this.CreateCommand(string.Format("insert into {0} ({1},key,value) values (:{1},:key,:value)",table,refColumn));
                command.Parameters.Add(new OracleParameter(refColumn, id));
                command.Parameters.Add(new OracleParameter("key", pair.Key));
                command.Parameters.Add(new OracleParameter("value", pair.Value));

                command.ExecuteNonQuery();
                command.Dispose();
            }
        }
Beispiel #15
0
        /// <summary>
        /// Tests the edge matcher in combination with dykstra routing.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="highway"></param>
        /// <param name="vehicle"></param>
        /// <param name="matcher"></param>
        /// <param name="pointName"></param>
        /// <param name="notFound"></param>
        private void TestResolveOnEdgeSingle(string name, string highway, 
            Vehicle vehicle, IEdgeMatcher matcher, 
            string pointName, bool notFound)
        {
            var fromName = new GeoCoordinate(51.0003, 4.0007);
            var toName = new GeoCoordinate(51.0003, 4.0008);

            var fromNoname = new GeoCoordinate(51.0, 4.0007);
            var toNoname = new GeoCoordinate(51.0, 4.0008);

            TagsCollection pointTags = new SimpleTagsCollection();
            pointTags["name"] = pointName;

            TagsCollection tags = new SimpleTagsCollection();
            tags["highway"] = highway;
            //tags["name"] = name;

            var tagsIndex = new SimpleTagsIndex();

            // do the data processing.
            var data = new DynamicGraphRouterDataSource<LiveEdge>(tagsIndex);
            uint vertexNoname1 = data.AddVertex((float)fromNoname.Latitude, (float)fromNoname.Longitude);
            uint vertexNoname2 = data.AddVertex((float)toNoname.Latitude, (float)toNoname.Longitude);
            data.AddArc(vertexNoname1, vertexNoname2, new LiveEdge()
            {
                Forward = true,
                Tags = tagsIndex.Add(tags)
            }, null);
            tags = new SimpleTagsCollection();
            tags["highway"] = highway;
            tags["name"] = name;
            uint vertexName1 = data.AddVertex((float)fromName.Latitude, (float)fromName.Longitude);
            uint vertexName2 = data.AddVertex((float)toName.Latitude, (float)toName.Longitude);
            data.AddArc(vertexName1, vertexName2, new LiveEdge()
            {
                Forward = true,
                Tags = tagsIndex.Add(tags)
            }, null);

            IRoutingInterpreter interpreter = new OsmRoutingInterpreter();

            // creates the data.
            IBasicRouter<LiveEdge> router = new DykstraRoutingLive();

            var nonameLocation = new GeoCoordinate(
                (fromNoname.Latitude + toNoname.Latitude) / 2.0,
                (fromNoname.Longitude + toNoname.Longitude) / 2.0);
            //            var nameLocation = new GeoCoordinate(
            //                (fromName.Latitude + toName.Latitude) / 2.0,
            //                (fromName.Longitude + toName.Longitude) / 2.0);

            const float delta = 0.01f;
            SearchClosestResult result = router.SearchClosest(data, interpreter, vehicle, nonameLocation, delta, matcher, pointTags);
            if (result.Distance < double.MaxValue)
            { // there is a result.
                Assert.IsFalse(notFound, "A result was found but was supposed not to  be found!");

                if (name == pointName)
                { // the name location was supposed to be found!
                    Assert.IsTrue(result.Vertex1 == vertexName1 || result.Vertex1 == vertexName2);
                    Assert.IsTrue(result.Vertex2 == vertexName1 || result.Vertex2 == vertexName2);
                }
                else
                { // the noname location was supposed to be found!
                    Assert.IsTrue(result.Vertex1 == vertexNoname1 || result.Vertex1 == vertexNoname2);
                    Assert.IsTrue(result.Vertex2 == vertexNoname1 || result.Vertex2 == vertexNoname2);
                }
                return;
            }
            Assert.IsTrue(notFound, "A result was not found but was supposed to be found!");
        }
 private static TagsCollection ConvertToTags(Osm.Xml.v0_6.tag[] tag)
 {
     TagsCollection tags = null;
     if (tag != null && tag.Length > 0)
     {
         tags = new SimpleTagsCollection();
         foreach (Osm.Xml.v0_6.tag t in tag)
         {
             tags.Add(t.k, t.v);
         }
     }
     return tags;
 }
        public void TestRandomPartialTagSerializaton()
        {
            SimpleTagsIndex tagsIndex = new SimpleTagsIndex();

            SimpleTagsCollection tagsCollection = new SimpleTagsCollection();
            for (int i = 0; i < 100; i++)
            {
                int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10) + 1;
                for (int idx = 0; idx < tagCollectionSize; idx++)
                {
                    int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10);
                    tagsCollection.Add(
                        string.Format("key_{0}", tagValue),
                        string.Format("value_{0}", tagValue));
                }
                uint tagsId = tagsIndex.Add(tagsCollection);
            }

            uint from = 40;
            uint to = 50;

            ITagsIndexReadonly tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to);
            Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max);
            for (uint idx = 0; idx < tagsIndex.Max; idx++)
            {
                if (idx >= from && idx < to)
                {
                    this.CompareTagsCollections(tagsIndex.Get(idx),
                        tagsIndexReadonly.Get(idx));
                }
                else
                {
                    Assert.IsNull(tagsIndexReadonly.Get(idx));
                }
            }

            from = 0;
            to = 100;

            tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to);
            Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max);
            for (uint idx = 0; idx < tagsIndex.Max; idx++)
            {
                if (idx >= from && idx < to)
                {
                    this.CompareTagsCollections(tagsIndex.Get(idx),
                        tagsIndexReadonly.Get(idx));
                }
                else
                {
                    Assert.IsNull(tagsIndexReadonly.Get(idx));
                }
            }

            from = 10;
            to = 1000;

            tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to);
            Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max);
            for (uint idx = 0; idx < tagsIndex.Max; idx++)
            {
                if (idx >= from && idx < to)
                {
                    this.CompareTagsCollections(tagsIndex.Get(idx),
                        tagsIndexReadonly.Get(idx));
                }
                else
                {
                    Assert.IsNull(tagsIndexReadonly.Get(idx));
                }
            }
        }
        public void TestSimpleTagSerializatonNonBeginPosition()
        {
            SimpleTagsIndex tagsIndex = new SimpleTagsIndex();

            SimpleTagsCollection tagsCollection = new SimpleTagsCollection();
            tagsCollection.Add("key1", "value1");

            uint tagsId = tagsIndex.Add(tagsCollection);

            ITagsIndexReadonly tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, 1201);
            Assert.AreEqual(tagsIndex.Max, tagsIndexReadonly.Max);
            for (uint idx = 0; idx < tagsIndex.Max; idx++)
            {
                this.CompareTagsCollections(tagsIndex.Get(idx),
                    tagsIndexReadonly.Get(idx));
            }
        }