コード例 #1
0
        /// <summary>
        /// Returns the location on the graph.
        /// </summary>
        public static Coordinate LocationOnGraph(this GeometricGraph graph, uint edgeId, ushort offset)
        {
            var geometricEdge = graph.GetEdge(edgeId);
            var shape         = graph.GetShape(geometricEdge);
            var length        = graph.Length(geometricEdge);
            var currentLength = 0.0;
            var targetLength  = length * (offset / (double)ushort.MaxValue);

            for (var i = 1; i < shape.Count; i++)
            {
                var segmentLength = Coordinate.DistanceEstimateInMeter(shape[i - 1], shape[i]);
                if (segmentLength + currentLength > targetLength)
                {
                    var   segmentOffsetLength = segmentLength + currentLength - targetLength;
                    var   segmentOffset       = 1 - (segmentOffsetLength / segmentLength);
                    short?elevation           = null;
                    if (shape[i - 1].Elevation.HasValue &&
                        shape[i].Elevation.HasValue)
                    {
                        elevation = (short)(shape[i - 1].Elevation.Value + (segmentOffset * (shape[i].Elevation.Value - shape[i - 1].Elevation.Value)));
                    }
                    return(new Coordinate()
                    {
                        Latitude = (float)(shape[i - 1].Latitude + (segmentOffset * (shape[i].Latitude - shape[i - 1].Latitude))),
                        Longitude = (float)(shape[i - 1].Longitude + (segmentOffset * (shape[i].Longitude - shape[i - 1].Longitude))),
                        Elevation = elevation
                    });
                }
                currentLength += segmentLength;
            }
            return(shape[shape.Count - 1]);
        }
コード例 #2
0
        /// <summary>
        /// Gets the shape of the given edge.
        /// </summary>
        public static ShapeBase GetShape(this GeometricGraph graph, long directedEdgeId)
        {
            if (directedEdgeId == 0)
            {
                throw new ArgumentOutOfRangeException("directedEdgeId");
            }

            uint edgeId;

            if (directedEdgeId > 0)
            {
                edgeId = (uint)directedEdgeId - 1;
            }
            else
            {
                edgeId = (uint)((-directedEdgeId) - 1);
            }
            return(graph.GetShape(edgeId));
        }