Exemplo n.º 1
0
        /// <summary>
        /// Retruns the equivalent distance on the mapping plane.
        /// </summary>
        /// <param name="from">The position the distance is measured from.</param>
        /// <param name="to">The approximate end position.</param>
        /// <param name="sys">The mapping system</param>
        /// <returns>The distance on the mapping plane.</returns>
        internal double GetPlanarMetric(IPosition from, IPosition to, ISpatialSystem sys)
        {
            if (!this.IsDefined)
            {
                return(0.0);
            }

            double sfac = sys.GetLineScaleFactor(from, to);

            return(m_ObservedMetric * sfac);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the equivalent distance on the mapping plane.
        /// </summary>
        /// <param name="from">The position the distance is measured from.</param>
        /// <param name="bearing">The bearing for the distance, in radians.</param>
        /// <param name="sys">The mapping system</param>
        /// <returns>The distance on the mapping plane.</returns>
        internal double GetPlanarMetric(IPosition from, double bearing, ISpatialSystem sys)
        {
            // Return zero if this distance is undefined.
            if (!this.IsDefined)
            {
                return(0.0);
            }

            // Calculate approximation for the terminal position (treating
            // this distance as a planar distance).
            IPosition to = Geom.Polar(from, bearing, m_ObservedMetric);

            // Use the approximate location to determine line scale factor
            double sfac = sys.GetLineScaleFactor(from, to);

            return(m_ObservedMetric * sfac);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a formatted distance string.
        /// </summary>
        /// <param name="metric">The distance on the mapping plane (in meters).</param>
        /// <param name="from">The start position.</param>
        /// <param name="to">The end position.</param>
        /// <returns>The formatted distance</returns>
        protected string Format(double metric, IPosition from, IPosition to)
        {
            if (m_Unit == null)
            {
                m_Distance = String.Empty;
            }
            else
            {
                // Get the fixed number of significant digits to show.
                int prec = -1;

                if (m_Unit.UnitType == DistanceUnitType.Meters)
                {
                    prec = 3;
                }
                else if (m_Unit.UnitType == DistanceUnitType.Feet)
                {
                    prec = 2;
                }
                else if (m_Unit.UnitType == DistanceUnitType.Chains)
                {
                    prec = 4;
                }

                // Get string for the planar distance.
                string pstring = m_Unit.Format(metric, true, prec);

                // Get string for the ground distance (don't bother with
                // units abbreviation).
                ISpatialSystem sys     = CadastralMapModel.Current.SpatialSystem;
                double         sfac    = sys.GetLineScaleFactor(from, to);
                double         gmetric = metric / sfac;
                string         gstring = m_Unit.Format(gmetric, false, prec);

                // Format the complete string.
                m_Distance = String.Format("{0} ({1} on ground)", pstring, gstring);
            }

            return(m_Distance);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Calculates the position of the sideshot point.
        /// </summary>
        /// <param name="dir">The direction observation (if any).</param>
        /// <param name="len">The length observation (if any). Could be a <c>Distance</c> or an
        /// <c>OffsetPoint</c>.</param>
        /// <returns>The position of the sideshot point (null if there is insufficient data
        /// to calculate a position)</returns>
        internal static IPosition Calculate(Direction dir, Observation len)
        {
            // Return if there is insufficient data.
            if (dir == null || len == null)
            {
                return(null);
            }

            // Get the position of the point the sideshot should radiate from.
            PointFeature from = dir.From;

            // Get the position of the start of the direction line (which may be offset).
            IPosition start = dir.StartPosition;

            // Get the bearing of the direction.
            double bearing = dir.Bearing.Radians;

            // Get the length of the sideshot arm.
            double length = len.GetDistance(from).Meters;

            // Calculate the resultant position. Note that the length is the length along the
            // bearing -- if an offset was specified, the actual length of the line from-to =
            // sqrt(offset*offset + length*length)
            IPosition to = Geom.Polar(start, bearing, length);

            // Return if the length is an offset point. In that case, the length we have obtained
            // is already a length on the mapping plane, so no further reduction should be done
            // (although it's debateable).
            if (len is OffsetPoint)
            {
                return(to);
            }

            // Using the position we've just got, reduce the length we used to a length on the
            // mapping plane (it's actually a length on the ground).
            ISpatialSystem sys  = CadastralMapModel.Current.SpatialSystem;
            double         sfac = sys.GetLineScaleFactor(start, to);

            return(Geom.Polar(start, bearing, length * sfac));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Calculates intersection points.
        /// </summary>
        /// <param name="dist1">1st distance observation.</param>
        /// <param name="from1">The point the 1st distance was observed from.</param>
        /// <param name="dist2">2nd distance observation.</param>
        /// <param name="from2">The point the 2nd distance was observed from.</param>
        /// <param name="usedefault">True if the default intersection is required (the one that has the
        /// lowest bearing with respect to the 2 from points). False for the other one (if any).</param>
        /// <param name="xsect">The position of the intersection (if any).</param>
        /// <param name="xsect1">The 1st choice intersection (if any).</param>
        /// <param name="xsect2">The 2nd choice intersection (if any).</param>
        /// <returns>True if intersections were calculated. False if the distance circles
        /// don't intersect.</returns>
        internal static bool Calculate(Observation dist1, PointFeature from1, Observation dist2, PointFeature from2, bool usedefault,
                                       out IPosition xsect, out IPosition xsect1, out IPosition xsect2)
        {
            // Initialize intersection positions.
            xsect = xsect1 = xsect2 = null;

            // Get the 2 distances.
            double d1 = dist1.GetDistance(from1).Meters;
            double d2 = dist2.GetDistance(from2).Meters;

            if (d1 < Constants.TINY || d2 < Constants.TINY)
            {
                return(false);
            }

            // Form circles with radii that match the observed distances.
            ICircleGeometry circle1 = new CircleGeometry(from1, d1);
            ICircleGeometry circle2 = new CircleGeometry(from2, d2);

            // See if there is actually an intersection between the two circles.
            IPosition x1, x2;
            uint      nx = IntersectionHelper.Intersect(circle1, circle2, out x1, out x2);

            if (nx == 0)
            {
                return(false);
            }

            // If we have 2 intersections, and we need the non-default one, pick up the 2nd
            // intersection. If only 1 intersection, use that, regardless of the setting for
            // the "use default" flag.

            if (nx == 2 && !usedefault)
            {
                xsect = x2;
            }
            else
            {
                xsect = x1;
            }

            // Return if both distances are offset points.
            OffsetPoint offset1 = (dist1 as OffsetPoint);
            OffsetPoint offset2 = (dist2 as OffsetPoint);

            if (offset1 != null && offset2 != null)
            {
                xsect1 = x1;
                xsect2 = x2;
                return(true);
            }

            // Reduce observed distances to the mapping plane.
            ISpatialSystem sys = CadastralMapModel.Current.SpatialSystem;

            if (offset1 == null)
            {
                d1 = d1 * sys.GetLineScaleFactor(from1, xsect);
            }

            if (offset2 == null)
            {
                d2 = d2 * sys.GetLineScaleFactor(from2, xsect);
            }

            // And calculate the exact intersection (like above)...
            // Form circles with radii that match the observed distances.
            ICircleGeometry circle1p = new CircleGeometry(from1, d1);
            ICircleGeometry circle2p = new CircleGeometry(from2, d2);

            // See if there is still an intersection between the two circles.
            nx = IntersectionHelper.Intersect(circle1p, circle2p, out x1, out x2);
            if (nx == 0)
            {
                return(false);
            }

            // If we have 2 intersections, and we need the non-default one, pick up the 2nd
            // intersection. If only 1 intersection, use that, regardless of the setting for
            // the "use default" flag.

            if (nx == 2 && !usedefault)
            {
                xsect = x2;
            }
            else
            {
                xsect = x1;
            }

            xsect1 = x1;
            xsect2 = x2;

            return(true);
        }
        /// <summary>
        /// Calculates the intersection point.
        /// </summary>
        /// <param name="dir">Direction observation.</param>
        /// <param name="distance">Distance observation.</param>
        /// <param name="from">The point the distance was observed from.</param>
        /// <param name="usedefault">True if the default intersection is required (the one
        /// closer to the origin of the direction line). False for the other one (if any).</param>
        /// <param name="xsect">The position of the intersection (if any).</param>
        /// <param name="xsect1">The 1st choice intersection (if any).</param>
        /// <param name="xsect2">The 2nd choice intersection (if any).</param>
        /// <returns>True if intersections were calculated. False if the distance circles
        /// don't intersect.</returns>
        internal static bool Calculate(Direction dir, Observation distance, PointFeature from, bool usedefault,
                                       out IPosition xsect, out IPosition xsect1, out IPosition xsect2)
        {
            // Initialize intersection positions.
            xsect = xsect1 = xsect2 = null;

            // Get the distance.
            double dist = distance.GetDistance(from).Meters;

            if (dist < Constants.TINY)
            {
                return(false);
            }

            // Form circle with a radius that matches the observed distance.
            ICircleGeometry circle = new CircleGeometry(from, dist);

            // See if there is actually an intersection between the direction & the circle.
            IPosition x1, x2;
            uint      nx = dir.Intersect(circle, out x1, out x2);

            if (nx == 0)
            {
                return(false);
            }

            // If we have 2 intersections, and we need the non-default one, pick up the 2nd
            // intersection. If only 1 intersection, use that, regardless of the setting for
            // the "use default" flag.

            if (nx == 2 && !usedefault)
            {
                xsect = x2;
            }
            else
            {
                xsect = x1;
            }

            // Return if the distance is an offset point.
            OffsetPoint offset = (distance as OffsetPoint);

            if (offset != null)
            {
                xsect1 = x1;
                xsect2 = x2;
                return(true);
            }

            // Reduce observed distance to the mapping plane.
            ISpatialSystem sys = CadastralMapModel.Current.SpatialSystem;

            dist = dist * sys.GetLineScaleFactor(from, xsect);

            // And calculate the exact intersection (like above)...
            // Form circle with a radius that matches the reduced distance.
            ICircleGeometry circlep = new CircleGeometry(from, dist);

            // See if there is actually an intersection between the direction & the circle.
            nx = dir.Intersect(circlep, out x1, out x2);
            if (nx == 0)
            {
                return(false);
            }

            // If we have 2 intersections, and we need the non-default one, pick up the 2nd
            // intersection. If only 1 intersection, use that, regardless of the setting for
            // the "use default" flag.

            if (nx == 2 && !usedefault)
            {
                xsect = x2;
            }
            else
            {
                xsect = x1;
            }

            xsect1 = x1;
            xsect2 = x2;

            return(true);
        }