Beispiel #1
0
        /// <summary>
        /// Converts this line location to features.
        /// </summary>
        public static FeatureCollection ToFeatures(this ReferencedLine line, RouterDb routerDb)
        {
            var featureCollection = new FeatureCollection();

            // build coordinates list.
            var coordinates = new List <Itinero.LocalGeo.Coordinate>();

            for (var i = 0; i < line.Edges.Length; i++)
            {
                var edge = routerDb.Network.GetEdge(line.Edges[i]);

                List <Itinero.LocalGeo.Coordinate> shape = null;
                if (i == 0 && line.Vertices[0] == Itinero.Constants.NO_VERTEX)
                {     // shape from startlocation -> vertex1.
                    if (line.Edges.Length == 1)
                    { // only 1 edge, shape from startLocation -> endLocation.
                        shape = line.StartLocation.ShapePointsTo(routerDb, line.EndLocation);
                        shape.Insert(0, line.StartLocation.LocationOnNetwork(routerDb));
                        shape.Add(line.EndLocation.LocationOnNetwork(routerDb));
                    }
                    else
                    { // just get shape to first vertex.
                        shape = line.StartLocation.ShapePointsTo(routerDb, line.Vertices[1]);
                        shape.Insert(0, line.StartLocation.LocationOnNetwork(routerDb));
                        shape.Add(routerDb.Network.GetVertex(line.Vertices[1]));
                    }
                }
                else if (i == line.Edges.Length - 1 && line.Vertices[line.Vertices.Length - 1] == Itinero.Constants.NO_VERTEX)
                { // shape from second last vertex -> endlocation.
                    shape = line.EndLocation.ShapePointsTo(routerDb, line.Vertices[line.Vertices.Length - 2]);
                    shape.Reverse();
                    shape.Insert(0, routerDb.Network.GetVertex(line.Vertices[line.Vertices.Length - 2]));
                    shape.Add(line.EndLocation.LocationOnNetwork(routerDb));
                }
                else
                { // regular 2 vertices and edge.
                    shape = routerDb.Network.GetShape(routerDb.Network.GetEdge(line.Edges[i]));
                    if (line.Edges[i] < 0)
                    {
                        shape.Reverse();
                    }
                }
                if (shape != null)
                {
                    if (coordinates.Count > 0)
                    {
                        coordinates.RemoveAt(coordinates.Count - 1);
                    }
                    for (var j = 0; j < shape.Count; j++)
                    {
                        coordinates.Add(shape[j]);
                    }
                }

                var tags = new AttributeCollection();
                tags.AddOrReplace(routerDb.EdgeProfiles.Get(edge.Data.Profile));
                tags.AddOrReplace(routerDb.EdgeMeta.Get(edge.Data.MetaId));
                tags.AddOrReplace("edge_id", edge.IdDirected().ToInvariantString());
                var table = tags.ToAttributes();

                featureCollection.Add(new Feature(new LineString(shape.ToCoordinates().ToArray()), table));
                coordinates.Clear();
            }

            var positiveLocation = line.GetPositiveOffsetLocation(routerDb).ToGeoAPICoordinate();

            featureCollection.Add(new Feature(new Point(positiveLocation), (new AttributeCollection(new Attribute("type", "positive_offset_location"))).ToAttributes()));
            var negativeLocation = line.GetNegativeOffsetLocation(routerDb).ToGeoAPICoordinate();

            featureCollection.Add(new Feature(new Point(negativeLocation), (new AttributeCollection(new Attribute("type", "negative_offset_location"))).ToAttributes()));

            return(featureCollection);
        }