コード例 #1
0
        private IFeature BuildFeature(int index)
        {
            if (((index - 1) % 10000) == 0)
            {
                Itinero.Logging.Logger.Log("FeatureList", TraceEventType.Information,
                                           "Building feature {0}/{1}.", index - 1, this.Count);
            }

            var edge = _routerDb.Network.GetEdge((uint)index);

            var vertexLocation1 = _routerDb.Network.GeometricGraph.GetVertex(edge.From);
            var coordinates     = new List <Coordinate>();

            coordinates.Add(new Coordinate(vertexLocation1.Longitude, vertexLocation1.Latitude));
            var shape = edge.Shape;

            if (shape != null)
            {
                var shapeEnumerable = shape.GetEnumerator();
                shapeEnumerable.Reset();
                while (shapeEnumerable.MoveNext())
                {
                    coordinates.Add(new Coordinate(shapeEnumerable.Current.Longitude,
                                                   shapeEnumerable.Current.Latitude));
                }
            }
            var vertexLocation2 = _routerDb.Network.GeometricGraph.GetVertex(edge.To);

            coordinates.Add(new Coordinate(vertexLocation2.Longitude, vertexLocation2.Latitude));
            var geometry = new LineString(coordinates.ToArray());

            var length = 0.0f;

            for (var i = 0; i < coordinates.Count - 1; i++)
            {
                length += Itinero.LocalGeo.Coordinate.DistanceEstimateInMeter((float)coordinates[i + 0].Y, (float)coordinates[i + 0].X,
                                                                              (float)coordinates[i + 1].Y, (float)coordinates[i + 1].X);
            }

            var tags = new Itinero.Attributes.AttributeCollection(_routerDb.EdgeProfiles.Get(edge.Data.Profile));

            foreach (var tag in _routerDb.EdgeMeta.Get(edge.Data.MetaId))
            {
                tags.AddOrReplace(tag.Key, tag.Value);
            }

            var attributes = new AttributesTable();

            attributes.AddFrom("highway", tags);
            attributes.AddFrom("route", tags);

            foreach (var p in _profiles)
            {
                var vehicleShortName = p.Parent.Name;
                if (vehicleShortName.Length > 4)
                {
                    vehicleShortName = vehicleShortName.Substring(0, 4);
                }

                var profileShortName = p.Name;
                if (profileShortName == null)
                {
                    profileShortName = string.Empty;
                }
                if (profileShortName.Length > 2)
                {
                    profileShortName = profileShortName.Substring(0, 3);
                }

                var profileName = $"{vehicleShortName}_{profileShortName}";

                var factor = p.FactorAndSpeed(tags);
                attributes.Add(profileName.ToLower(), factor.Value != 0);
                attributes.Add(profileName + "_dir", factor.Direction);
                var speed = 1 / factor.SpeedFactor * 3.6;
                if (factor.SpeedFactor <= 0)
                {
                    speed = 65536;
                }
                attributes.Add(profileName + "_sp", System.Math.Round(speed, 2));
                speed = 1 / factor.Value * 3.6;
                if (factor.Value <= 0)
                {
                    speed = 65536;
                }
                attributes.Add(profileName + "_spc", System.Math.Round(speed, 2));
            }

            attributes.Add("length", System.Math.Round(length, 3));

            string lanesString;
            var    lanes         = 1;
            var    lanesVerified = false;

            if (tags.TryGetValue("lanes", out lanesString))
            {
                lanesVerified = true;
                if (!int.TryParse(lanesString, out lanes))
                {
                    lanes         = 1;
                    lanesVerified = false;
                }
            }
            attributes.Add("lanes", lanes);
            attributes.Add("lanes_ve", lanesVerified);

            var name = tags.ExtractName();

            attributes.Add("name", name);

            attributes.AddFrom("way_id", tags);
            attributes.AddFrom("tunnel", tags);
            attributes.AddFrom("bridge", tags);

            attributes.Add("from", edge.From);
            attributes.Add("to", edge.To);

            return(new Feature(geometry, attributes));
        }
コード例 #2
0
 /// <summary>
 /// Adds the given attributes.
 /// </summary>
 public static void AddFrom(this AttributesTable table, string name, Itinero.Attributes.AttributeCollection tags)
 {
     table.AddFrom(name, tags, string.Empty);
 }