示例#1
0
        // TODO: Define Coordinate System when the featurelines returns on itslef like a U
        // Minimum distance from baseline
        /// <summary>
        /// CoordinateSystem by station.
        /// </summary>
        /// <param name="station">The station.</param>
        /// <param name="vertical">if set to <c>true</c> the ZAxis is [vertical].</param>
        /// <returns></returns>
        public CoordinateSystem CoordinateSystemByStation(double station, bool vertical = true)
        {
            Utils.Log(string.Format("Featureline.CoordinateSystemByStation started...", ""));

            CoordinateSystem cs     = null;
            CoordinateSystem output = null;

            if (Math.Abs(station - this.Start) < 0.00001)
            {
                station = this.Start;
            }

            if (Math.Abs(station - this.End) < 0.00001)
            {
                station = this.End;
            }

            if (station < this.Start || station > this.End)
            {
                var message = "The Station value is not compatible with the Featureline.";

                Utils.Log(string.Format("ERROR: {0}", message));

                return(null);
            }

            cs = this._baseline.CoordinateSystemByStation(station);

            Utils.Log(string.Format("CoordinateSystem: {0}", cs));

            if (cs != null)
            {
                Plane plane = cs.ZXPlane;

                PolyCurve pc = this._polycurve;

                Point  p = null;
                double d = double.MaxValue;

                try
                {
                    var intersections = pc.Intersect(plane);

                    Utils.Log(string.Format("Intersections: {0}", intersections.Length));

                    // Get the closest point on the Feature Line
                    foreach (var result in intersections)
                    {
                        if (result is Point)
                        {
                            Point r = result as Point;

                            double dist = cs.Origin.DistanceTo(r);

                            if (dist < d)
                            {
                                p = r;
                                d = dist;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Utils.Log(string.Format("ERROR: {0}", ex.Message));

                    throw new Exception(ex.Message);
                }

                Utils.Log(string.Format("Distance: {0}", d));

                // 20190415  -- START
                if (p == null)
                {
                    if (station == this.Start)
                    {
                        p = pc.StartPoint;
                        Utils.Log(string.Format("Point forced on Featureline start.", ""));
                    }
                    if (station == this.End)
                    {
                        p = pc.EndPoint;
                        Utils.Log(string.Format("Point forced on Featureline end.", ""));
                    }
                }

                // 20190415  -- END

                Utils.Log(string.Format("Point: {0}", p));

                if (null != p)
                {
                    output = pc.CoordinateSystemAtParameter(pc.ParameterAtPoint(p));

                    output = CoordinateSystem.ByOriginVectors(output.Origin, output.YAxis.Cross(Vector.ZAxis()), output.YAxis, Vector.ZAxis());

                    if (vertical)
                    {
                        output = CoordinateSystem.ByOriginVectors(output.Origin,
                                                                  Vector.ByCoordinates(output.XAxis.X, output.XAxis.Y, 0, true),
                                                                  Vector.ByCoordinates(output.YAxis.X, output.YAxis.Y, 0, true),
                                                                  Vector.ZAxis());
                    }
                }
                else
                {
                    Utils.Log(string.Format("ERROR: Point is null.", ""));
                }

                Utils.Log(string.Format("Featureline.CoordinateSystemByStation completed.", ""));

                //plane.Dispose();
                //pc.Dispose();
                //p.Dispose();
            }
            else
            {
                var message = "The Station value is not compatible with the Featureline.";

                Utils.Log(string.Format("ERROR: {0}", message));

                throw new Exception(message);
            }

            //cs.Dispose();

            return(output);
        }