public void RoadTypeMatchReturnsFalseForMissingTag()
        {
            RoadType target = new RoadType();
            target.RequiredTags.Add(new OSMTag("highway", "residental"));

            OSMWay testObject = new OSMWay(1);

            Assert.False(target.Match(testObject));
        }
        public void RoadTypeMatchReturnsFalseForTagWithDifferentValue()
        {
            RoadType target = new RoadType();
            target.RequiredTags.Add(new OSMTag("highway", "residental"));

            OSMWay testObject = new OSMWay(1);
            testObject.Tags.Add(new OSMTag("highway", "primary"));

            Assert.False(target.Match(testObject));
        }
        public void OSMRouteConstructorSetsSpeedPropertyFromMaxSpeedTag()
        {
            OSMWay source = new OSMWay(11);
            source.Tags.Add(new OSMTag("maxspeed", "50"));

            RoadType sourceType = new RoadType();

            OSMRoad target = new OSMRoad(source, sourceType);

            Assert.Equal(50, target.Speed);
        }
        public void OSMRouteConstructorCopiesDataFromWay()
        {
            OSMWay source = new OSMWay(11);
            source.Nodes.Add(1);
            source.Nodes.Add(2);
            source.Tags.Add(new OSMTag("highway", "track"));

            RoadType sourceType = new RoadType();
            sourceType.RequiredTags.Add(new OSMTag("highway", "track"));

            OSMRoad target = new OSMRoad(source, sourceType);

            Assert.Equal(source.Nodes.Count, target.Nodes.Count);
            Assert.Equal(source.Tags.First(), target.Tags.First());
            Assert.Equal(sourceType, target.RoadType);
        }
        public void RoadTypeMatchReturnsFalseForMultipleTagsWithDifferentValues()
        {
            RoadType target = new RoadType();
            target.RequiredTags.Add(new OSMTag("highway", "track"));
            target.RequiredTags.Add(new OSMTag("grade", "1"));

            OSMWay testObject1 = new OSMWay(1);
            testObject1.Tags.Add(new OSMTag("highway", "primary"));
            target.RequiredTags.Add(new OSMTag("grade", "1"));

            OSMWay testObject2 = new OSMWay(1);
            testObject2.Tags.Add(new OSMTag("highway", "track"));
            target.RequiredTags.Add(new OSMTag("grade", "2"));

            OSMWay testObject3 = new OSMWay(1);
            testObject3.Tags.Add(new OSMTag("highway", "track"));

            Assert.False(target.Match(testObject1));
            Assert.False(target.Match(testObject2));
            Assert.False(target.Match(testObject3));
        }
Beispiel #6
0
        /// <summary>
        /// Creates a new instance of OSMRoute based on specific OSMWay
        /// </summary>
        /// <param name="way">The way that defines geomery and tags</param>
        /// <param name="roadType">The RoadType of this OSMRoute</param>
        public OSMRoad(OSMWay way, RoadType roadType)
            : base(way.ID)
        {
            _tags = way.Tags;
            _nodes = new List<int>(way.Nodes);

            RoadType = roadType;

            Speed = RoadType.Speed;

            if (Tags.ContainsTag("maxspeed")) {
                string[] chunks = Tags["maxspeed"].Value.Split(' ');
                double numericSpeed = 0;
                if (double.TryParse(chunks[0], out numericSpeed)) {
                    if (chunks.Length == 2 && chunks[1] == "mph") {
                        Speed = numericSpeed * MphConversionFactor;
                    }
                    else {
                        Speed = numericSpeed;
                    }
                }
            }
        }
        /// <summary>
        /// Loads config data from the stream
        /// </summary>
        /// <param name="input">Input stream with config data</param>
        public void Load(Stream input)
        {
            XDocument doc = XDocument.Load(new StreamReader(input));
            XElement root = doc.Root;

            if (root.Name != "routing-config") {
                throw new XmlException("Wrong root element, expected <routing-config>");
            }

            if(root.Attribute("version") == null || root.Attribute("version").Value != "1.0") {
                throw new XmlException("Wrong root element, expected <routing-config>");
            }

            // Parses route-type element
            foreach (var roadTypeElement in root.Elements("route-type")) {
                RoadType parsedType = new RoadType();
                parsedType.Name = roadTypeElement.Attribute("name").Value;
                parsedType.Speed = double.Parse(roadTypeElement.Attribute("speed").Value, System.Globalization.CultureInfo.InvariantCulture);
                if (roadTypeElement.Attribute("oneway") != null) {
                    parsedType.Oneway = roadTypeElement.Attribute("oneway").Value == "yes";
                }

                foreach (var tagElement in roadTypeElement.Elements("required-tag")) {
                    parsedType.RequiredTags.Add(new OSMTag(tagElement.Attribute("key").Value, tagElement.Attribute("value").Value));
                }

                RoadTypes.Add(parsedType);
            }
        }
        public void RoadTypeMatchReturnsTrueForTheSameMultipleTags()
        {
            RoadType target = new RoadType();
            target.RequiredTags.Add(new OSMTag("highway", "track"));
            target.RequiredTags.Add(new OSMTag("grade", "1"));

            OSMWay testObject = new OSMWay(1);
            testObject.Tags.Add(new OSMTag("grade", "1"));
            testObject.Tags.Add(new OSMTag("highway", "track"));

            Assert.True(target.Match(testObject));
        }
        public void RoadTypeConstructorInitializesProperties()
        {
            RoadType target = new RoadType();

            Assert.NotNull(target.RequiredTags);
        }
        public void RoadTypeMatchReturnsTrueForTheSameTags()
        {
            RoadType target = new RoadType();
            target.RequiredTags.Add(new OSMTag("highway", "residental"));

            OSMWay testObject = new OSMWay(1);
            testObject.Tags.Add(new OSMTag("highway", "residental"));

            Assert.True(target.Match(testObject));
        }
Beispiel #11
0
        public void OSMRouteConstructorSetsSpeedPropertyFromRoadTypeSpeed()
        {
            OSMWay source = new OSMWay(11);

            RoadType sourceType = new RoadType();
            sourceType.Speed = 60;

            OSMRoad target = new OSMRoad(source, sourceType);

            Assert.Equal(60, target.Speed);
        }
Beispiel #12
0
        public void RoadTypeIsAccessibleReverseAppliesOnewayTagOverridesDefaultValueForRoadType2()
        {
            RoadType roadType = new RoadType();
            roadType.Oneway = false;

            OSMWay way = new OSMWay(0);
            way.Tags.Add(new OSMTag("oneway", "yes"));

            OSMRoad target = new OSMRoad(way, roadType);

            Assert.Equal(true, target.IsAccessible());
            Assert.Equal(false, target.IsAccessibleReverse());
        }
Beispiel #13
0
        public void RoadTypeIsAccessibleReverseAppliesDefaultOnewayValueFromRoadType()
        {
            RoadType roadType = new RoadType();
            roadType.Oneway = true;

            OSMWay oneWay = new OSMWay(0);
            OSMRoad target = new OSMRoad(oneWay, roadType);

            Assert.Equal(true, target.IsAccessible());
            Assert.Equal(false, target.IsAccessibleReverse());
        }
Beispiel #14
0
        public void RoadTypeIsAccessibleAndIsAccessibleReturnsCorrectValuesForReverseOnewayRoads()
        {
            RoadType roadType = new RoadType();
            roadType.RequiredTags.Add(new OSMTag("highway", "*"));

            OSMWay oneWay1 = new OSMWay(0);
            oneWay1.Tags.Add(new OSMTag("oneway", "-1"));
            OSMRoad target1 = new OSMRoad(oneWay1, roadType);

            OSMWay oneWay2 = new OSMWay(0);
            oneWay2.Tags.Add(new OSMTag("oneway", "reverse"));
            OSMRoad target2 = new OSMRoad(oneWay2, roadType);

            Assert.False(target1.IsAccessible());
            Assert.True(target1.IsAccessibleReverse());

            Assert.False(target2.IsAccessible());
            Assert.True(target2.IsAccessibleReverse());
        }
Beispiel #15
0
        public void OSMRouteConstructorSetsSpeedPropertyMaxspeedTagTakesPrecedenceOverRoadTypeSpeed()
        {
            OSMWay source = new OSMWay(11);
            source.Tags.Add(new OSMTag("maxspeed", "50"));

            RoadType sourceType = new RoadType();
            sourceType.Speed = 60;

            OSMRoad target = new OSMRoad(source, sourceType);

            Assert.Equal(50, target.Speed);
        }
Beispiel #16
0
        public void OSMRouteConstructorSetsSpeedPropertyIgnoresInvalidMaxspeedTags()
        {
            OSMWay source = new OSMWay(11);
            source.Tags.Add(new OSMTag("maxspeed", "some value"));

            RoadType sourceType = new RoadType();
            sourceType.Speed = 60;

            OSMRoad target = new OSMRoad(source, sourceType);

            Assert.Equal(60, target.Speed);
        }