Example #1
0
        /// <summary>
        /// Calculate Centroid for given boundayr Geometry
        /// </summary>
        /// <param name="gtGeometry"></param>
        /// <returns></returns>
        public IGTPoint CalculateCentroid(IGTGeometry gtGeometry)
        {
            IGTPoint gtCenterPt = GTClassFactory.Create <IGTPoint>();

            gtCenterPt.X = 0;
            gtCenterPt.Y = 0;
            gtCenterPt.Z = 0;
            if (gtGeometry.KeypointCount > 1)
            {
                for (int indx = 0; indx < gtGeometry.KeypointCount - 1; indx++)
                {
                    gtCenterPt.X += gtGeometry.GetKeypointPosition(indx).X;
                    gtCenterPt.Y += gtGeometry.GetKeypointPosition(indx).Y;
                    gtCenterPt.Z += gtGeometry.GetKeypointPosition(indx).Z;
                }
                gtCenterPt.X /= gtGeometry.KeypointCount - 1;
                gtCenterPt.Y /= gtGeometry.KeypointCount - 1;
                gtCenterPt.Z /= gtGeometry.KeypointCount - 1;
            }
            else
            {
                gtCenterPt = gtGeometry.FirstPoint;
            }
            return(gtCenterPt);
        }
Example #2
0
        /// <summary>
        /// Get Segment And Angle on which point is placed
        /// </summary>
        /// <param name="m_gtPolylineGeometry"></param>
        /// <param name="gtPoint"></param>
        /// <returns></returns>
        protected IGTGeometry GetSegmentAndAngle(IGTGeometry m_gtPolylineGeometry, IGTPoint gtPoint)
        {
            bool        flag = false;
            IGTGeometry m_gtPolylineGeometrySegment = GTClassFactory.Create <IGTGeometry>();
            IGTSegment  m_gtSegment   = GTClassFactory.Create <IGTSegment>();
            IGTPoint    m_gtsnapPoint = GetSnapPoint(m_gtPolylineGeometry, gtPoint);

            try
            {
                if (m_gtPolylineGeometry.Type == "CompositePolylineGeometry")
                {
                    //get the segment
                    for (int i = 0; i < m_gtPolylineGeometry.KeypointCount - 1; i++)
                    {
                        m_gtSegment.Begin = m_gtPolylineGeometry.GetKeypointPosition(i);
                        m_gtSegment.End   = m_gtPolylineGeometry.GetKeypointPosition(i + 1);
                        if (m_gtsnapPoint.IsOn(m_gtSegment))
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (flag)
                    {
                        m_gtPolylineGeometrySegment = m_gtPolylineGeometry.ExtractGeometry(m_gtSegment.Point1, m_gtSegment.Point2, false);
                    }
                }
                return(m_gtPolylineGeometrySegment);
            }
            catch
            {
                throw;
            }
        }
Example #3
0
        /// <summary>
        /// Get Point And Angle
        /// </summary>
        /// <param name="m_gtPolylineGeom"></param>
        /// <param name="m_gtPoint">Related Virtual point</param>
        /// <returns></returns>
        protected IGTPoint GetPointAndAngle(IGTGeometry m_gtPolylineGeom, IGTPoint m_gtPoint)
        {
            bool     flag = false;
            IGTPoint m_gtProjectedPoint = null;
            //Get snappoint if the point feature is not snapped to the linear
            IGTPoint m_gtsnapPoint = GetSnapPoint(m_gtPolylineGeom, m_gtPoint);

            try
            {
                //Check if the geometry is linear
                if ((m_gtPolylineGeom.Type == "CompositePolylineGeometry") || (m_gtPolylineGeom.Type == "PolylineGeometry"))
                {
                    IGTSegment m_segment = GTClassFactory.Create <IGTSegment>();
                    //get the segment
                    for (int i = 0; i < m_gtPolylineGeom.KeypointCount - 1; i++)
                    {
                        m_segment.Begin = m_gtPolylineGeom.GetKeypointPosition(i);
                        m_segment.End   = m_gtPolylineGeom.GetKeypointPosition(i + 1);
                        if (m_gtsnapPoint.IsOn(m_segment))
                        {
                            flag = true;
                            ang  = AngleBetweenTwoPoints(m_segment.Begin, m_segment.End);
                            break;
                        }
                        else
                        {
                            // m_gtProjectedPoint = m_gtsnapPoint;
                        }
                    }
                    if (flag)
                    {
                        m_gtProjectedPoint = m_segment.ProjectPointAtAngle(m_segment.Begin, m_gtsnapPoint, ang);
                    }
                }
                return(m_gtProjectedPoint);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// Method create new polygon
        /// </summary>
        /// <param name="m_TargetPolygon"></param>
        /// <returns></returns>
        private IGTCompositePolygonGeometry CreatePolygon(IGTGeometry m_gTargetPolygon)
        {
            IGTPolylineGeometry         m_gPolylineGeometry         = GTClassFactory.Create <IGTPolylineGeometry>();
            IGTCompositePolygonGeometry m_gCompositePolygonGeometry = GTClassFactory.Create <IGTCompositePolygonGeometry>();
            IGTGeometryCollection       m_gGeometryCollection       = GTClassFactory.Create <IGTGeometryCollection>();

            try
            {
                //Remove duplicate points from New polygon
                for (int i = 0; i < m_gTargetPolygon.KeypointCount; i++)
                {
                    if (i > 0 && i < m_gTargetPolygon.KeypointCount - 1)
                    {
                        if (!m_gTargetPolygon.GetKeypointPosition(i).PointsAreEqual(m_gTargetPolygon.GetKeypointPosition(i + 1)))
                        {
                            m_gPolylineGeometry.Points.Add(m_gTargetPolygon.GetKeypointPosition(i));
                        }
                    }
                    else
                    {
                        m_gPolylineGeometry.Points.Add(m_gTargetPolygon.GetKeypointPosition(i));
                    }
                }

                //Add polylines to the collection
                m_gGeometryCollection.Add(m_gPolylineGeometry);

                //Build composite polygon
                foreach (IGTPolylineGeometry m_gtPolylineGeometry in m_gGeometryCollection)
                {
                    m_gCompositePolygonGeometry.Add(m_gtPolylineGeometry);
                }
                return(m_gCompositePolygonGeometry);
            }
            catch
            {
                throw;
            }
        }