Esempio n. 1
0
        /// <summary>
        /// Defines any extra points that might coincide with this face.
        /// <c>m_Polygon</c> and <c>m_Line</c> must both be defined prior to call
        /// (via a call to <c>SetLine</c>).
        /// </summary>
        /// <returns>The number of extra points</returns>
        int SetExtraPoints()
        {
            Debug.Assert(m_Polygon!=null);
            Debug.Assert(m_Divider!=null);

            // Determine whether the order needs to be reversed
            // (the points should follow a clockwise cycle round
            // the polygon)
            bool reverse = (m_Divider.Left == m_Polygon);

            // Define the initial position
            if (reverse)
            {
                m_Begin = m_Divider.To;
                m_End = m_Divider.From;
            }
            else
            {
                m_Begin = m_Divider.From;
                m_End = m_Divider.To;
            }

            // Trash any old info kicking around (we shouldn't really have any)
            m_ExtraPoints = null;

            // Get any points along the divider (excluding end points)
            LineGeometry line = m_Divider.LineGeometry;
            ISpatialIndex index = CadastralMapModel.Current.Index;
            ILength tol = new Length(Constants.XYTOL);
            List<PointFeature> xp = new FindPointsOnLineQuery(index, line, false, tol).Result;
            if (xp.Count==0)
                return 0;

            // If we've got more than one extra point, ensure they're sorted in
            // the same direction as the line.
            if (xp.Count==1)
                m_ExtraPoints = xp.ToArray();
            else
            {
                // Sort the points so they're arranged along the divider
                List<TaggedObject<PointFeature, double>> pts =
                    new List<TaggedObject<PointFeature, double>>(xp.Count);

                foreach (PointFeature p in xp)
                {
                    double value = line.GetLength(p).Meters;
                    if (reverse)
                        value = -value;
                    pts.Add(new TaggedObject<PointFeature, double>(p, value));
                }

                pts.Sort(delegate(TaggedObject<PointFeature, double> a,
                                  TaggedObject<PointFeature, double> b)
                                  {
                                      return a.Tag.CompareTo(b.Tag);
                                  });

                // Retrieve the points in their sorted order, ignoring any coincident points
                // (this assumes that it doesn't matter which PointFeature we actually pick up)

                List<PointFeature> extraPoints = new List<PointFeature>(pts.Count);
                PointFeature prev = null;
                foreach (TaggedObject<PointFeature,double> tp in pts)
                {
                    PointFeature p = tp.Thing;

                    if (prev==null || !p.IsCoincident(prev))
                    {
                        extraPoints.Add(p);
                        prev = p;
                    }
                }

                // Allocate array of distinct extra positions
                m_ExtraPoints = extraPoints.ToArray();
            }

            return (m_ExtraPoints==null ? 0 : m_ExtraPoints.Length);
        }
Esempio n. 2
0
        /// <summary>
        /// Defines any extra points that might coincide with this face.
        /// <c>m_Polygon</c> and <c>m_Line</c> must both be defined prior to call
        /// (via a call to <c>SetLine</c>).
        /// </summary>
        /// <returns>The number of extra points</returns>
        int SetExtraPoints()
        {
            Debug.Assert(m_Polygon != null);
            Debug.Assert(m_Divider != null);

            // Determine whether the order needs to be reversed
            // (the points should follow a clockwise cycle round
            // the polygon)
            bool reverse = (m_Divider.Left == m_Polygon);

            // Define the initial position
            if (reverse)
            {
                m_Begin = m_Divider.To;
                m_End   = m_Divider.From;
            }
            else
            {
                m_Begin = m_Divider.From;
                m_End   = m_Divider.To;
            }

            // Trash any old info kicking around (we shouldn't really have any)
            m_ExtraPoints = null;

            // Get any points along the divider (excluding end points)
            LineGeometry        line  = m_Divider.LineGeometry;
            ISpatialIndex       index = CadastralMapModel.Current.Index;
            ILength             tol   = new Length(Constants.XYTOL);
            List <PointFeature> xp    = new FindPointsOnLineQuery(index, line, false, tol).Result;

            if (xp.Count == 0)
            {
                return(0);
            }

            // If we've got more than one extra point, ensure they're sorted in
            // the same direction as the line.
            if (xp.Count == 1)
            {
                m_ExtraPoints = xp.ToArray();
            }
            else
            {
                // Sort the points so they're arranged along the divider
                List <TaggedObject <PointFeature, double> > pts =
                    new List <TaggedObject <PointFeature, double> >(xp.Count);

                foreach (PointFeature p in xp)
                {
                    double value = line.GetLength(p).Meters;
                    if (reverse)
                    {
                        value = -value;
                    }
                    pts.Add(new TaggedObject <PointFeature, double>(p, value));
                }

                pts.Sort(delegate(TaggedObject <PointFeature, double> a,
                                  TaggedObject <PointFeature, double> b)
                {
                    return(a.Tag.CompareTo(b.Tag));
                });

                // Retrieve the points in their sorted order, ignoring any coincident points
                // (this assumes that it doesn't matter which PointFeature we actually pick up)

                List <PointFeature> extraPoints = new List <PointFeature>(pts.Count);
                PointFeature        prev        = null;
                foreach (TaggedObject <PointFeature, double> tp in pts)
                {
                    PointFeature p = tp.Thing;

                    if (prev == null || !p.IsCoincident(prev))
                    {
                        extraPoints.Add(p);
                        prev = p;
                    }
                }

                // Allocate array of distinct extra positions
                m_ExtraPoints = extraPoints.ToArray();
            }

            return(m_ExtraPoints == null ? 0 : m_ExtraPoints.Length);
        }