Exemplo n.º 1
0
        private IGeometry GetGeometryByCoor()
        {
            //直接获得坐标范围
            double dblMinX = 0;
            double dblMaxX = 0;
            double dblMinY = 0;
            double dblMaxY = 0;

            double.TryParse(this.txtMinX.Text, out dblMinX);
            double.TryParse(this.txtMaxX.Text, out dblMaxX);
            double.TryParse(this.txtMinY.Text, out dblMinY);
            double.TryParse(this.txtMaxY.Text, out dblMaxY);

            //定义范围
            IPointCollection pPntCollection = new PolygonClass();
            object           obj            = System.Type.Missing;
            IPoint           pPnt1          = new PointClass();

            pPnt1.PutCoords(dblMinX, dblMinY);
            pPntCollection.AddPoint(pPnt1, ref obj, ref obj);
            IPoint pPnt2 = new PointClass();

            pPnt2.PutCoords(dblMaxX, dblMinY);
            pPntCollection.AddPoint(pPnt2, ref obj, ref obj);
            IPoint pPnt3 = new PointClass();

            pPnt3.PutCoords(dblMaxX, dblMaxY);
            pPntCollection.AddPoint(pPnt3, ref obj, ref obj);
            IPoint pPnt4 = new PointClass();

            pPnt4.PutCoords(dblMinX, dblMaxY);
            pPntCollection.AddPoint(pPnt4, ref obj, ref obj);

            //
            IPolygon2 pPolygon2 = pPntCollection as IPolygon2;

            pPolygon2.Close();

            if (pPolygon2.IsEmpty)
            {
                return(null);
            }

            if (m_pMap != null && m_pMap.SpatialReference != null)
            {
                pPolygon2.Project(m_pMap.SpatialReference);
            }
            return(pPolygon2 as IGeometry);
        }