예제 #1
0
        /// <summary>
        /// 画线
        /// </summary>
        internal void FlashFeature()
        {
            IPoint point1 = new PointClass();

            point1.PutCoords(101, 40);
            IPoint point2 = new PointClass();

            point2.PutCoords(110, 40);
            IPoint point3 = new PointClass();

            point3.PutCoords(112, 40);

            object           o = Type.Missing;
            IPointCollection pointCollection = new PolygonClass();

            pointCollection.AddPoint(point1, ref o, ref o);
            pointCollection.AddPoint(point2, ref o, ref o);
            pointCollection.AddPoint(point3, ref o, ref o);
            IPolygon polygon = pointCollection as IPolygon;

            IElement element = new PolygonElementClass();

            element.Geometry = polygon;
            IGraphicsContainer graphicsContainer = axMapControl.Map as IGraphicsContainer;

            graphicsContainer.AddElement(element, 0);
            axMapControl.Refresh();
        }
예제 #2
0
        /// <summary>
        /// 将Envelope转换为多边形
        /// </summary>
        /// <param name="layerExtent">Envelope</param>
        /// <param name="pPolygon">结果多边形</param>
        /// <returns>操作结果</returns>
        public static bool ExchangeToPolygon(IEnvelope layerExtent, ref IPolygon4 pPolygon)
        {
            try
            {
                object           Missing   = Type.Missing;
                IPoint           pPoint    = new PointClass();
                IPointCollection pPointCol = new PolygonClass();
                pPoint.PutCoords(layerExtent.XMin, layerExtent.YMax);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMax, layerExtent.YMax);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMax, layerExtent.YMin);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMin, layerExtent.YMin);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMin, layerExtent.YMax);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPolygon = pPointCol as IPolygon4;
                return(true);
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return(false);
            }
        }
예제 #3
0
        public static IGeometry GetExample3()
        {
            const double FromZ = 0;
            const double ToZ   = 9.5;

            //Extrusion: Square Shaped 2D Polygon Extruded To Generate 3D Building Via ConstructExtrudeFromTo()

            IPointCollection polygonPointCollection = new PolygonClass();

            polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-2, 2), ref _missing, ref _missing);
            polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(2, 2), ref _missing, ref _missing);
            polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(2, -2), ref _missing, ref _missing);
            polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-2, -2), ref _missing, ref _missing);

            IPolygon polygon = polygonPointCollection as IPolygon;

            polygon.Close();

            IGeometry polygonGeometry = polygonPointCollection as IGeometry;

            ITopologicalOperator topologicalOperator = polygonGeometry as ITopologicalOperator;

            topologicalOperator.Simplify();

            IConstructMultiPatch constructMultiPatch = new MultiPatchClass();

            constructMultiPatch.ConstructExtrudeFromTo(FromZ, ToZ, polygonGeometry);

            return(constructMultiPatch as IGeometry);
        }
예제 #4
0
        public bool DrawPolygon(IRaster pRaster, ExOriPara pExOriPara, InOriPara pInOriPara, IFeatureClass pFeatureClass, int nID)
        {
            try
            {
                Point2D[,] ptResult = null;
                ClsGetCameraView CGetCameraView = new ClsGetCameraView();
                if (CGetCameraView.ImageReprojectionRange(pRaster, out ptResult, pExOriPara, pInOriPara, 50))
                {
                    IPointCollection pPointCollection = new PolygonClass();
                    for (int j = 0; j < ptResult.GetLength(1); j++)
                    {
                        if (ptResult[0, j] == null)
                        {
                            continue;
                        }
                        IPoint pPoint1 = new PointClass();
                        pPoint1.X = ptResult[0, j].X;
                        pPoint1.Y = ptResult[0, j].Y;
                        pPointCollection.AddPoint(pPoint1);
                    }
                    for (int k = ptResult.GetLength(1) - 1; k >= 0; k--)
                    {
                        if (ptResult[1, k] == null)
                        {
                            continue;
                        }

                        IPoint pPoint2 = new PointClass();
                        pPoint2.X = ptResult[1, k].X;
                        pPoint2.Y = ptResult[1, k].Y;
                        pPointCollection.AddPoint(pPoint2);
                    }
                    IFeature pFeatureTemp = pFeatureClass.CreateFeature();
                    IPolygon pPolygon     = new PolygonClass();
                    pPolygon = pPointCollection as IPolygon;
                    pPolygon.Close();
                    pFeatureTemp.Shape = pPolygon as IGeometry;
                    pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("PointID"), nID);
                    pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("X"), pExOriPara.pos.X);
                    pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("Y"), pExOriPara.pos.Y);
                    pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("Z"), pExOriPara.pos.Z);
                    pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("omg"), pExOriPara.ori.omg);
                    pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("phi"), pExOriPara.ori.phi);
                    pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("kap"), pExOriPara.ori.kap);
                    pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("width"), pInOriPara.nW);
                    pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("height"), pInOriPara.nH);
                    pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("fx"), pInOriPara.dfx);
                    pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("fy"), pInOriPara.dfy);
                    pFeatureTemp.set_Value(pFeatureTemp.Fields.FindField("f"), pInOriPara.df);
                    pFeatureTemp.Store();
                }

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }
        }
예제 #5
0
        public override IGeometry CreateGeometry()
        {
            IPointCollection pointCollection = new PolygonClass();
            IZAware          zAware          = pointCollection as IZAware;

            zAware.ZAware = true;

            IPoint point = new PointClass();

            point.X = -_width / 2;
            point.Y = -_height / 2;
            point.Z = 0;
            pointCollection.AddPoint(point);

            point   = new PointClass();
            point.X = -_width / 2;
            point.Y = _height / 2;
            point.Z = 0;
            pointCollection.AddPoint(point);

            point   = new PointClass();
            point.X = _width / 2;
            point.Y = _height / 2;
            point.Z = 0;
            pointCollection.AddPoint(point);

            point   = new PointClass();
            point.X = _width / 2;
            point.Y = -_height / 2;
            point.Z = 0;
            pointCollection.AddPoint(point);
            ((IPolygon)pointCollection).Close();

            IConstructMultiPatch patch = new MultiPatchClass();

            patch.ConstructExtrude(_polyline.Length, pointCollection as IGeometry);

            IVector3D vectorZ = new Vector3DClass();

            vectorZ.SetComponents(0, 0, 1);
            IVector3D vector3D = new Vector3DClass();

            vector3D.SetComponents(_polyline.ToPoint.X - _polyline.FromPoint.X, _polyline.ToPoint.Y - _polyline.FromPoint.Y, _zdgc - _qdgc);
            double    rotateAngle = Math.Acos(vector3D.ZComponent / vector3D.Magnitude);
            IVector3D vectorAxis  = vectorZ.CrossProduct(vector3D) as IVector3D;

            ITransform3D transform3D = patch as ITransform3D;

            transform3D.RotateVector3D(vectorAxis, rotateAngle);
            transform3D.Move3D(_polyline.FromPoint.X, _polyline.FromPoint.Y, _qdgc);
            return(patch as IGeometry);
        }
예제 #6
0
        /// <summary>
        /// 生成多边形(顺时针)
        /// </summary>
        /// <remarks >如果已经生成过边,则直接返回</remarks>
        private void FormPolygon(List <CPoint> cptlt)
        {
            //定义收集点的容器,并添加三角形的三个顶点
            IPointCollection4 pPntCtl = new PolygonClass();
            object            Missing = Type.Missing;

            pPntCtl.AddPoint((IPoint)_CptLt[0], ref Missing, ref Missing);
            pPntCtl.AddPoint((IPoint)_CptLt[1], ref Missing, ref Missing);
            pPntCtl.AddPoint((IPoint)_CptLt[2], ref Missing, ref Missing);

            //将容器中的点以多边形的方式输出
            this.SetPointCollection(pPntCtl);
            this.Close();
        }
예제 #7
0
        private bool RedrawHengChuanPolygon(TunnelHChuan entity)
        {
            //找到导线点图层
            IMap map = new MapClass();

            map = DataEditCommon.g_pMap;
            var           layerName    = LayerNames.DEFALUT_HENGCHUAN; //“默认_导线点”图层
            IFeatureLayer featureLayer = new FeatureLayerClass();

            featureLayer = LayerHelper.GetLayerByName(map, layerName); //获得图层

            if (featureLayer == null)
            {
                MessageBox.Show("没有找到" + layerName + "图层,将不能绘制导线点。", "提示", MessageBoxButtons.OK);
                return(false);
            }

            var point1 = new PointClass {
                X = entity.X1, Y = entity.Y1, Z = entity.Z1, ZAware = true
            };
            var point2 = new PointClass {
                X = entity.X2, Y = entity.Y2, Z = entity.Z2, ZAware = true
            };
            var line = new LineClass {
                FromPoint = point1, ToPoint = point2
            };
            var polygon = new PolygonClass {
                ZAware = true
            };
            var width = entity.Width / 2;

            polygon.AddPoint(ConstructPoint(point2, line.Angle / Deg2Rad + 90, width));
            polygon.AddPoint(ConstructPoint(point2, line.Angle / Deg2Rad - 90, width));
            polygon.AddPoint(ConstructPoint(point1, line.Angle / Deg2Rad + 180 + 90, width));
            polygon.AddPoint(ConstructPoint(point1, line.Angle / Deg2Rad + 180 - 90, width));
            polygon.SimplifyPreserveFromTo();

            var list = new List <ziduan>
            {
                new ziduan("BID", entity.Id.ToString()),
                new ziduan("BID0", entity.TunnelId1.ToString()),
                new ziduan("BID1", entity.TunnelId2.ToString()),
                new ziduan("NAME", entity.NameHChuan)
            };

            var feature = DataEditCommon.ModifyFeature(featureLayer, entity.Id, polygon, list);

            return(feature != null);
        }
예제 #8
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);
        }
예제 #9
0
        public override IGeometry CreateGeometry()
        {
            IPointCollection pointCollection = new PolygonClass();
            IZAware          zAware          = pointCollection as IZAware;

            zAware.ZAware = true;

            double angle = 2 * Math.PI / _division;

            for (int i = 0; i < _division; i++)
            {
                IPoint point = new PointClass();
                point.X = _diameter * Math.Cos(angle * i) / 2;
                point.Y = _diameter * Math.Sin(angle * i) / 2;
                point.Z = 0;
                pointCollection.AddPoint(point);
            }
            ((IPolygon)pointCollection).Close();

            IConstructMultiPatch patch = new MultiPatchClass();

            patch.ConstructExtrude(0 - _depth, pointCollection as IGeometry);
            ITransform3D transform3D = patch as ITransform3D;

            transform3D.Move3D(_x, _y, _z);
            return(patch as IGeometry);
        }
예제 #10
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            IPointCollection points = new PolygonClass();

            if (this.listView1.Items.Count < 3)
            {
                MessageBox.Show("点数必须大于或等于3个点");
            }
            else
            {
                for (int i = 0; i < this.listView1.Items.Count; i++)
                {
                    ListViewItem item = this.listView1.Items[i];
                    double       num2 = double.Parse(item.Text);
                    double       num3 = double.Parse(item.SubItems[1].Text);
                    if (this.imap_0.MapUnits != esriUnits.esriKilometers)
                    {
                        num2 *= 1000.0;
                        num3 *= 1000.0;
                    }
                    IPoint inPoint = new PointClass
                    {
                        X = num2,
                        Y = num3
                    };
                    object before = Missing.Value;
                    points.AddPoint(inPoint, ref before, ref before);
                }
                (points as IPolygon).Close();
                this.igeometry_0  = points as IGeometry;
                base.DialogResult = DialogResult.OK;
            }
        }
예제 #11
0
        /// <summary>
        /// 坐标串转换为多边形
        /// </summary>
        /// <param name="xyString"></param>
        /// <returns></returns>
        public static IPolygon ToPolygon(string xyString)
        {
            string[] xyStr  = xyString.Split(';');
            IPoint   pPoint = new PointClass();
            //IPolygon pPolygon1 = new PolygonClass();
            IPointCollection pPointCollection = new PolygonClass();

            object _missing = Type.Missing;
            double Lat, Lon;

            for (int i = 0; i < xyStr.Length; i++)
            {
                if (string.IsNullOrEmpty(xyStr[i]))
                {
                    continue;
                }
                Lon      = Convert.ToDouble(xyStr[i].Split(',')[0]);
                Lat      = Convert.ToDouble(xyStr[i].Split(',')[1]);
                pPoint   = new PointClass();
                pPoint.X = Lon;
                pPoint.Y = Lat;
                pPoint.PutCoords(Lon, Lat);
                pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
            }
            IPolygon pPolygon = new PolygonClass();

            pPolygon = (IPolygon)pPointCollection;
            return(pPolygon);
        }
예제 #12
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            DataRowCollection excelRows = ExcelTools.GetExcelRows(this.textBox1.Text, this.comboBox1.Text);
            IPointCollection  points    = new PolygonClass();

            foreach (DataRow row in excelRows)
            {
                try
                {
                    double num     = double.Parse(row[this.cboX.Text].ToString());
                    double num2    = double.Parse(row[this.cboY.Text].ToString());
                    IPoint inPoint = new PointClass
                    {
                        X = num,
                        Y = num2
                    };
                    object before = Missing.Value;
                    points.AddPoint(inPoint, ref before, ref before);
                }
                catch
                {
                }
            }
            (points as IPolygon).Close();
            this.igeometry_0  = points as IGeometry;
            base.DialogResult = DialogResult.OK;
        }
예제 #13
0
        private void CreateFeature(IGeometry pGeom)
        {
            if (pGeom == null)
            {
                return;
            }
            if (m_pCurrentLayer == null)
            {
                return;
            }

            // Create the feature
            IWorkspaceEdit pWorkspaceEdit = GetWorkspaceEdit();
            IFeatureLayer  pFeatureLayer  = (IFeatureLayer)m_pCurrentLayer;
            IFeatureClass  pFeatureClass  = pFeatureLayer.FeatureClass;

            pWorkspaceEdit.StartEditOperation();

            //Envelope to Polygon
            IEnvelope        pEnv = pGeom as IEnvelope;
            IPointCollection pPtColl;

            pPtColl = new PolygonClass();
            object missing = Type.Missing;

            pPtColl.AddPoint(pEnv.LowerLeft, ref missing, ref missing);
            pPtColl.AddPoint(pEnv.UpperLeft, ref missing, ref missing);
            pPtColl.AddPoint(pEnv.UpperRight, ref missing, ref missing);
            pPtColl.AddPoint(pEnv.LowerRight, ref missing, ref missing);
            //Close the polygon
            pPtColl.AddPoint(pEnv.LowerLeft, ref missing, ref missing);

            IFeature pFeature = pFeatureClass.CreateFeature();

            try
            {
                pFeature.Shape = pPtColl as IGeometry;
            }
            catch (Exception ex)
            {
                MessageBox.Show("创建要素", ex.Message);
            }
            pFeature.Store();
            pWorkspaceEdit.StopEditOperation();

            m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, m_pCurrentLayer, pGeom.Envelope);
        }
예제 #14
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (m_hookHelper == null)
            {
                return;
            }
            if (Button == 4 || Button == 2)
            {
                return;
            }
            IActiveView  pAv     = m_hookHelper.ActiveView;
            IMapControl2 pMapCtl = m_hookHelper.Hook as IMapControl2;

            IPolygon         pPoly = new PolygonClass();
            IPointCollection polylinePointCollection = new PolygonClass();

            pPoly.SpatialReference = pMapCtl.SpatialReference;
            IEnvelope pGeo    = pMapCtl.TrackRectangle();
            object    missing = Type.Missing;
            IPoint    pPoint  = new PointClass();

            pPoint.PutCoords(pGeo.XMin, pGeo.YMin);
            polylinePointCollection.AddPoint(pPoint, ref missing, ref missing);
            pPoint.PutCoords(pGeo.XMin, pGeo.YMax);
            polylinePointCollection.AddPoint(pPoint, ref missing, ref missing);
            pPoint.PutCoords(pGeo.XMax, pGeo.YMax);
            polylinePointCollection.AddPoint(pPoint, ref missing, ref missing);
            pPoint.PutCoords(pGeo.XMax, pGeo.YMin);
            polylinePointCollection.AddPoint(pPoint, ref missing, ref missing);
            pPoly = polylinePointCollection as IPolygon;
            pPoly.SimplifyPreserveFromTo();

            if (pPoly == null)
            {
                return;
            }
            //drawgeometryXOR(pGeo);
            frm = new frmAreaStatistics();
            pPoly.SpatialReference = pMapCtl.SpatialReference;  //added by chulili 2013-02-28 到这里为止,pPoly的空间参考变成null了,再赋值一次
            frm.CurGeometry        = pPoly as IGeometry;
            frm.FormClosed        += new FormClosedEventHandler(frm_FormClosed);
            frm.CurMap             = m_hookHelper.Hook as IMapControlDefault;
            frm.InitFrm();
            frm.SetSliderValue(true);
            frm.ShowDialog();
        }
예제 #15
0
        private void method_5(IFillSymbol ifillSymbol_0, Rectangle rectangle_0)
        {
            object           before  = Missing.Value;
            IPoint           inPoint = new PointClass();
            IPointCollection points  = new PolygonClass();

            inPoint.PutCoords((double)(rectangle_0.Left + 3), (double)(rectangle_0.Top + 3));
            points.AddPoint(inPoint, ref before, ref before);
            inPoint.PutCoords((double)(rectangle_0.Right - 3), (double)(rectangle_0.Top + 3));
            points.AddPoint(inPoint, ref before, ref before);
            inPoint.PutCoords((double)(rectangle_0.Right - 3), (double)(rectangle_0.Bottom - 3));
            points.AddPoint(inPoint, ref before, ref before);
            inPoint.PutCoords((double)(rectangle_0.Left + 3), (double)(rectangle_0.Bottom - 3));
            points.AddPoint(inPoint, ref before, ref before);
            inPoint.PutCoords((double)(rectangle_0.Left + 3), (double)(rectangle_0.Top + 3));
            points.AddPoint(inPoint, ref before, ref before);
            ((ISymbol)ifillSymbol_0).Draw((IGeometry)points);
        }
예제 #16
0
        private void method_6(IFillSymbol ifillSymbol_0, Rectangle rectangle_0, bool bool_1)
        {
            object           value        = Missing.Value;
            IPoint           pointClass   = new PointClass();
            IPointCollection polygonClass = new PolygonClass();

            pointClass.PutCoords((double)(rectangle_0.Top + 3), (double)(rectangle_0.Left + 3));
            polygonClass.AddPoint(pointClass, ref value, ref value);
            pointClass.PutCoords((double)(rectangle_0.Top + 3), (double)(rectangle_0.Right - 3));
            polygonClass.AddPoint(pointClass, ref value, ref value);
            pointClass.PutCoords((double)(rectangle_0.Bottom - 3), (double)(rectangle_0.Right - 3));
            polygonClass.AddPoint(pointClass, ref value, ref value);
            pointClass.PutCoords((double)(rectangle_0.Bottom - 3), (double)(rectangle_0.Left + 3));
            polygonClass.AddPoint(pointClass, ref value, ref value);
            pointClass.PutCoords((double)(rectangle_0.Top + 3), (double)(rectangle_0.Left + 3));
            polygonClass.AddPoint(pointClass, ref value, ref value);
            ((ISymbol)ifillSymbol_0).Draw((IGeometry)polygonClass);
        }
예제 #17
0
        private void DrawSymbol(IFillSymbol pSymbol, Rectangle rect, bool b)
        {
            object           before  = Missing.Value;
            IPoint           inPoint = new PointClass();
            IPointCollection points  = new PolygonClass();

            inPoint.PutCoords((double)(rect.Top + 3), (double)(rect.Left + 3));
            points.AddPoint(inPoint, ref before, ref before);
            inPoint.PutCoords((double)(rect.Top + 3), (double)(rect.Right - 3));
            points.AddPoint(inPoint, ref before, ref before);
            inPoint.PutCoords((double)(rect.Bottom - 3), (double)(rect.Right - 3));
            points.AddPoint(inPoint, ref before, ref before);
            inPoint.PutCoords((double)(rect.Bottom - 3), (double)(rect.Left + 3));
            points.AddPoint(inPoint, ref before, ref before);
            inPoint.PutCoords((double)(rect.Top + 3), (double)(rect.Left + 3));
            points.AddPoint(inPoint, ref before, ref before);
            ((ISymbol)pSymbol).Draw((IGeometry)points);
        }
예제 #18
0
        public void addToPoint(string file)
        {
            IPoint           pPoint = null;
            IPointCollection pPCol  = new PolygonClass();

            string[] lines = File.ReadAllLines(file);
            object   ptmp  = Type.Missing;



            ISpatialReferenceFactory pfactory = new SpatialReferenceEnvironmentClass();
            ISpatialReference        flatref  = m_hookHelper.FocusMap.SpatialReference;
            ISpatialReference        earthref = pfactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954);



            for (int i = 1; i < lines.Length; i++)
            {
                string[] temp = lines[i].Trim().Split(' ');
                for (int j = 0; j < temp.Length; j++)
                {
                    pPoint   = new PointClass();
                    pPoint.X = int.Parse(temp[1].Trim());
                    pPoint.Y = int.Parse(temp[2].Trim());


                    IGeometry geo = pPoint as IGeometry;
                    geo.SpatialReference = flatref;
                    geo.Project(earthref);
                    addpoint(geo);
                    pPCol.AddPoint(pPoint, ref ptmp, ref ptmp);

                    if (j == (temp.Length - 1))
                    {
                        string[] temp1 = lines[1].Trim().Split(' ');
                        pPoint = new PointClass();

                        pPoint.PutCoords(int.Parse(temp1[1].Trim()), int.Parse(temp1[2].Trim()));
                        pPCol.AddPoint(pPoint, ref ptmp, ref ptmp);
                    }
                }
            }
            addpolygon(pPCol as IGeometry);
        }
예제 #19
0
        public override IGeometry CreateGeometry()
        {
            IPointCollection pointCollection = new PolygonClass();
            IZAware          zAware          = pointCollection as IZAware;

            zAware.ZAware = true;

            IPoint point = new PointClass();

            point.X = -_width / 2;
            point.Y = -_length / 2;
            point.Z = 0;
            pointCollection.AddPoint(point);

            point   = new PointClass();
            point.X = -_width / 2;
            point.Y = _length / 2;
            point.Z = 0;
            pointCollection.AddPoint(point);

            point   = new PointClass();
            point.X = _width / 2;
            point.Y = _length / 2;
            point.Z = 0;
            pointCollection.AddPoint(point);

            point   = new PointClass();
            point.X = _width / 2;
            point.Y = -_length / 2;
            point.Z = 0;
            pointCollection.AddPoint(point);

            ((IPolygon)pointCollection).Close();

            IConstructMultiPatch patch = new MultiPatchClass();

            patch.ConstructExtrude(0 - _depth, pointCollection as IGeometry);
            ITransform3D transform3D = patch as ITransform3D;
            IVector3D    vector3D    = ConstructVector3D(0, 0, 1);

            transform3D.RotateVector3D(vector3D, _radian);
            transform3D.Move3D(_x, _y, _z);
            return(patch as IGeometry);
        }
예제 #20
0
        private void button5_Click(object sender, EventArgs e)
        {
            strOperator = "add";
            IPointCollection pointCollection;
            IPoint           point     = new PointClass();
            IPoint           fromPoint = new PointClass();
            IPoint           toPoint   = new PointClass();

            if (m_Feature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
            {
                pointCollection = new PolylineClass();
                IPolyline polyline = m_Feature.Shape as IPolyline;

                object missing1 = Type.Missing;
                object missing2 = Type.Missing;
                pointCollection = polyline as IPointCollection;
                //获取线对象的最后两个点
                fromPoint = pointCollection.get_Point(pointCollection.PointCount - 2);
                toPoint   = pointCollection.get_Point(pointCollection.PointCount - 1);
                //根据线最后两个点,创建一个新点
                point.PutCoords((fromPoint.X + toPoint.X) / 2 + 300, (fromPoint.Y + toPoint.Y) / 2 + 500);
                //将新点添加到线对象的点集合中
                pointCollection.AddPoint(point, ref missing1, ref missing2);
            }
            else if (m_Feature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
            {
                pointCollection = new PolygonClass();
                IPolygon polygon = m_Feature.Shape as IPolygon;

                object missing1 = Type.Missing;
                object missing2 = Type.Missing;
                pointCollection = polygon as IPointCollection;
                //获取面对象点集最后两个点
                fromPoint = pointCollection.get_Point(pointCollection.PointCount - 2);
                toPoint   = pointCollection.get_Point(pointCollection.PointCount - 1);
                //根据线最后两个点,创建一个新点
                point.PutCoords((fromPoint.X + toPoint.X) / 2, (fromPoint.Y + toPoint.Y) / 2 + 50);
                //将新点添加到线对象的点集合中
                pointCollection.AddPoint(point, ref missing1, ref missing2);
            }
            IWorkspaceEdit workspaceEdit;
            IWorkspace     workspace;
            IDataset       dataset = m_FeatureLayer.FeatureClass as IDataset;

            workspace     = dataset.Workspace;
            workspaceEdit = workspace as IWorkspaceEdit;
            //开始编辑
            workspaceEdit.StartEditing(true);
            workspaceEdit.StartEditOperation();
            //保存数据
            m_Feature.Store();
            //结束编辑
            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);
            m_activeView.Refresh();
        }
예제 #21
0
        /// <summary>
        /// 鼠标移动事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void mapControl_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
        {
            if (listMapPoints.Count != 0)
            {
                MapLngLat moveLnglat = new MapLngLat(e.mapX, e.mapY);
                if (!isControl)//若没有按下空格
                {
                    listMapPoints.Add(moveLnglat);

                    switch (measureType)
                    {
                    case "distance":
                        measureLine.UpdatePosition(listMapPoints);
                        segmentLength = MapFrame.Core.Common.Utils.GetDistance(downPoint, moveLnglat);
                        toltalLength += segmentLength;
                        ResultEventArgs(string.Format("当前线段长度为:{0} 千米 \n总线段长度为:{1}千米", segmentLength, toltalLength));
                        toltalLength -= segmentLength;
                        break;

                    case "area":

                        measurePolygon.UpdatePosition(listMapPoints);
                        IPolygon             polygon     = new PolygonClass();
                        IGeometry            geometry    = null;
                        ITopologicalOperator topo        = null;
                        IPointCollection     pointCollec = new PolygonClass();
                        for (int i = 0; i < listMapPoints.Count; i++)
                        {
                            pointCollec.AddPoint(new PointClass()
                            {
                                X = listMapPoints[i].Lng, Y = listMapPoints[i].Lat
                            });
                        }
                        polygon = pointCollec as IPolygon;
                        if (polygon != null)
                        {
                            polygon.Close();
                            geometry = polygon as IGeometry;
                            topo     = geometry as ITopologicalOperator;
                            topo.Simplify();
                            geometry.Project(mapControl.Map.SpatialReference);
                            IArea area = geometry as IArea;

                            if (area != null)
                            {
                                measureArea = area.Area;
                                ResultEventArgs(string.Format("面积为:{0} 万平方千米", measureArea));
                                polygon = null;
                            }
                        }
                        break;
                    }
                    listMapPoints.Remove(moveLnglat);
                }
            }
        }
예제 #22
0
        /// <summary>
        /// 由点集合生成面要素   20110609
        /// </summary>
        /// <param name="pPointCollection">点集合</param>
        /// <param name="PointMove">移动的点</param>
        /// <returns></returns>
        public static IPolygon PointToPolygon(IPointCollection pPointCollection, IPoint PointMove)
        {
            IPointCollection pMovePointCollection = new PolygonClass();
            object           pBefore = Type.Missing;
            object           pAfter  = Type.Missing;

            for (int i = 0; i < pPointCollection.PointCount; i++)
            {
                IPoint pPoint = pPointCollection.get_Point(i);
                pMovePointCollection.AddPoint(pPoint, ref pBefore, ref pAfter);
            }
            pMovePointCollection.AddPoint(PointMove, ref pBefore, ref pAfter);
            IZAware pZAware = pMovePointCollection as IZAware;

            pZAware.ZAware = true;
            IPolygon pPolygon = pMovePointCollection as IPolygon;

            return(pPolygon);
        }
예제 #23
0
        private static IPolygon GetAoPolygon(LineString line, ISpatialReference sr)
        {
            var poly = new PolygonClass();

            foreach (var p in line.Coordinates)
            {
                var gp  = (GeographicPosition)p;
                var pnt = GetAoPoint(gp.Longitude, gp.Latitude, sr);
                poly.AddPoint(pnt, Type.Missing, Type.Missing);
            }
            poly.SpatialReference = sr;
            return(poly);
        }
예제 #24
0
        public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY)
        {
            try
            {
                IPoint pPoint = new PointClass();
                pPoint.PutCoords(mapX, mapY);
                FrmMapExportByCoordinate dialog = new FrmMapExportByCoordinate(pPoint);
                dialog.ShowDialog();

                if (dialog.DialogResult == DialogResult.OK)
                {
                    IPointCollection pColl = new PolygonClass();
                    pColl.AddPoint(pPoint);
                    IPoint point1 = new PointClass();
                    point1.PutCoords(mapX + dialog.Length, mapY);
                    pColl.AddPoint(point1);
                    IPoint point2 = new PointClass();
                    point2.PutCoords(mapX, mapY + dialog.Width);
                    pColl.AddPoint(point2);
                    IPoint point3 = new PointClass();
                    point3.PutCoords(mapX + dialog.Length, mapY + dialog.Width);
                    pColl.AddPoint(point3);
                    IGeometry pGeo = pColl as IGeometry;

                    DF2DApplication       app    = DF2DApplication.Application;
                    IMap                  pMap   = app.Current2DMapControl.Map;
                    ISelectionEnvironment selEnv = new SelectionEnvironmentClass();
                    pMap.SelectByShape(pGeo, selEnv, false);
                    ISelection pSelection = pMap.FeatureSelection;

                    FrmDxfExport dialog1 = new FrmDxfExport(pSelection, pMap);
                    WaitForm.Stop();
                    dialog1.ShowDialog();
                }
            }
            catch (System.Exception ex)
            {
            }
        }
        public static IPolygon CreatePolyFromEnv(IEnvelope pEnv)
        {
            if (pEnv == null)
            {
                return(null);
            }
            object o = Type.Missing;

            IPointCollection pPointCol = new PolygonClass();

            IPoint pPoint = new PointClass();

            pPoint.PutCoords(pEnv.XMin, pEnv.YMin);
            pPointCol.AddPoint(pPoint, ref o, ref o);

            pPoint = new PointClass();
            pPoint.PutCoords(pEnv.XMin, pEnv.YMax);
            pPointCol.AddPoint(pPoint, ref o, ref o);

            pPoint = new PointClass();
            pPoint.PutCoords(pEnv.XMax, pEnv.YMax);
            pPointCol.AddPoint(pPoint, ref o, ref o);

            pPoint = new PointClass();
            pPoint.PutCoords(pEnv.XMax, pEnv.YMin);
            pPointCol.AddPoint(pPoint, ref o, ref o);

            pPoint = new PointClass();
            pPoint.PutCoords(pEnv.XMin, pEnv.YMin);
            pPointCol.AddPoint(pPoint, ref o, ref o);

            IGeometry pGeom = (IGeometry)pPointCol;

            pGeom.SpatialReference = pEnv.SpatialReference;

            return((IPolygon)pGeom);
        }
예제 #26
0
        /// <summary>
        /// 计算多边形面积,结果存贮在Area中
        /// </summary>
        /// <param name="point">计算时的终点</param>
        private void CalculateArea(IPoint point)
        {
            IPointCollection pointCollection = new PolygonClass();

            pointCollection.AddPointCollection(_pointCollection);
            object ep = System.Reflection.Missing.Value;

            pointCollection.AddPoint(point, ref ep, ref ep);

            if (pointCollection.PointCount > 2)
            {
                IArea iArea = (IArea)(IPolygon)pointCollection;
                Area = Math.Abs(iArea.Area);
            }
        }
예제 #27
0
        private IPolygon buildHomeRangePolygon(Animal inAnimal, double stretchFactor)
        {
            const int        numberOfPoints = 30;
            IPointCollection boundaryPoints = new PolygonClass();
            IPointCollection myPoints       = new MultipointClass();

            double[]      anglesList = new double[numberOfPoints];
            RandomNumbers rn         = RandomNumbers.getInstance();
            IGeometry     geom       = null;
            double        angle      = 0;
            double        radius     = 0;
            IPoint        tempPoint;
            object        missing = Type.Missing;
            IPolygon      returnPoly;


            try
            {
                geom = (IGeometry)boundaryPoints;

                mLog.Debug("inside buildHomeRangePolygon for animal " + inAnimal.IdNum.ToString());
                for (int i = 0; i < numberOfPoints; i++)
                {
                    anglesList[i] = (rn.getUniformRandomNum() * Math.PI * 2);
                }
                System.Array.Sort(anglesList);
                //go backwards to get clockwise polygon for external ring
                for (int i = numberOfPoints - 1; i >= 0; i--)
                {
                    tempPoint = new PointClass();
                    angle     = anglesList[i];
                    //radius is slightly larger than needed for home range to compensate for not being a circle
                    radius      = Math.Sqrt(1000000 * inAnimal.HomeRangeCriteria.Area / Math.PI) * rn.getPositiveNormalRandomNum(1.2, .1) * stretchFactor;
                    tempPoint.X = inAnimal.HomeRangeCenter.X + radius * Math.Cos(angle);
                    tempPoint.Y = inAnimal.HomeRangeCenter.Y + radius * Math.Sin(angle);
                    boundaryPoints.AddPoint(tempPoint, ref missing, ref missing);
                }
            }
            catch (Exception ex)
            {
                eLog.Debug(ex);
            }
            returnPoly = boundaryPoints as PolygonClass;
            returnPoly.Close();
            mLog.Debug("leaving buildHomeRangePolygon");
            return(returnPoly);
        }
예제 #28
0
        private IPointCollection CreatePointCollectionForCircle(double radius)
        {
            object missing = Type.Missing;
            //radius = radius / 2;
            IPointCollection pointCollection = new PolygonClass();
            double           angle           = 2 * Math.PI / _builderItem.Builder.Division;

            for (int i = 0; i < _builderItem.Builder.Division; i++)
            {
                IPoint point = new PointClass();
                point.X = radius * Math.Cos(angle * i) / 2;
                point.Y = radius * Math.Sin(angle * i) / 2;
                point.Z = 0;
                pointCollection.AddPoint(point, ref missing, ref missing);
            }
            ((IPolygon)pointCollection).Close();
            return(pointCollection);
        }
예제 #29
0
        /// <summary>
        /// 计算多边形面积,结果存贮在Area中
        /// </summary>
        /// <param name="point">计算时的终点</param>
        private void CalculateArea(IPoint point)
        {
            try
            {
                IPointCollection pointCollection = new PolygonClass();
                pointCollection.AddPointCollection(_pointCollection);
                object ep = System.Reflection.Missing.Value;
                pointCollection.AddPoint(point, ref ep, ref ep);

                if (pointCollection.PointCount > 2)
                {
                    IPolygon pPolygon = (IPolygon)pointCollection;
                    IArea    pArea    = (IArea)pPolygon;
                    Area = pArea.Area;
                    Area = Math.Abs(Area);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #30
0
        /// <summary>
        /// 经纬度坐标串转换为投影坐标多边形
        /// </summary>
        /// <param name="xyString">经纬度坐标串</param>
        /// <returns></returns>
        public static IPolygon GeoCorPointToProPolygon(string xyString)
        {
            string[] xyStr  = xyString.Split(';');
            IPoint   pPoint = new PointClass();
            //IPolygon pPolygon1 = new PolygonClass();
            IPointCollection pPointCollection = new PolygonClass();
            //string[] flagStr;
            //if (xyStr[xyStr.Length - 1] == "")
            //{
            //     flagStr = new string[xyStr.Length - 1];
            //     List<string > list = xyStr.ToList();//把数组转换成泛型类
            //     list.RemoveAt(xyStr.Length - 1);//利用泛型类remove掉元素
            //     flagStr = list.ToArray();//再由泛型类转换成数组

            //}
            //else {  flagStr = xyStr; }
            object _missing = Type.Missing;
            double Lat, Lon;

            for (int i = 0; i < xyStr.Length; i++)
            {
                if (string.IsNullOrEmpty(xyStr[i]))
                {
                    continue;
                }
                Lon    = Convert.ToDouble(xyStr[i].Split(',')[0]);
                Lat    = Convert.ToDouble(xyStr[i].Split(',')[1]);
                pPoint = new PointClass();
                //pPoint.X = Lon;
                //pPoint.Y = Lat;
                pPoint = GetProCoordinate(Lon, Lat);  //经纬度-投影坐标 转换
                //pPoint.PutCoords(Lon, Lat);
                pPointCollection.AddPoint(pPoint, ref _missing, ref _missing);
            }
            IPolygon pPolygon = new PolygonClass();

            pPolygon = (IPolygon)pPointCollection;
            return(pPolygon);
        }
예제 #31
0
        /// <summary>
        /// 画线
        /// </summary>
        internal void FlashFeature()
        {
            IPoint point1 = new PointClass();
            //point1.PutCoords(101, 40);
            point1 = GetProject2(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));
            IPoint point2 = new PointClass();
            //point2.PutCoords(110, 40);
            point2 = GetProject2(-120, 40);
            //IPoint point3 = new PointClass();
            //point3.PutCoords(112, 40);

            object o = Type.Missing;
            IPointCollection pointCollection = new PolygonClass();
            pointCollection.AddPoint(point1, ref o, ref o);
            pointCollection.AddPoint(point2, ref o, ref o);
            //pointCollection.AddPoint(point3, ref o, ref o);
            IPolygon polygon = pointCollection as IPolygon;

            IElement element = new PolygonElementClass();
            element.Geometry = polygon;
            IGraphicsContainer graphicsContainer = axMapControl.Map as IGraphicsContainer;
            graphicsContainer.AddElement(element, 0);
            axMapControl.Refresh();
        }
예제 #32
0
        private IFeatureLayer MakePolygonFeatureLayer(FusionTable ft, List<RowPolygon> lstGeomsPolygon)
        {
            IFeatureLayer pPolyLayer = new FeatureLayerClass();
            pPolyLayer.FeatureClass = MakeInMemoryFeatureClass(ft, esriGeometryType.esriGeometryPolygon);
            //Set up the Outpoints cursor
            IFeatureCursor pFCurOutLine = pPolyLayer.Search(null, false);
            pFCurOutLine = pPolyLayer.FeatureClass.Insert(true);

            IFeatureBuffer pFBuffer = pPolyLayer.FeatureClass.CreateFeatureBuffer();

            IPointCollection pointCollection = null;
            IPoint ppoint;
            foreach (RowPolygon poly in lstGeomsPolygon)
            {
                pointCollection = new PolygonClass();
                foreach (List<double> pt in poly.geometry.coordinates[0])
                {
                    ppoint = new PointClass();
                    ppoint.X = pt[0];
                    ppoint.Y = pt[1];
                    pointCollection.AddPoint(ppoint);
                }

                pFBuffer.Shape = pointCollection as PolygonClass;

                pFCurOutLine.InsertFeature(pFBuffer);

            }

            pPolyLayer.Name = "FusionTablePolygon";
            return pPolyLayer;
        }
        public static IGeometry GetExample8()
        {
            const double CircleDegrees = 360.0;
            const int CircleDivisions = 36;
            const double VectorComponentOffset = 0.0000001;
            const double CircleRadius = 3.0;
            const double BaseZ = -10;
            const double OffsetZ = 5;

            //Extrusion: 3D Circle Polygon Having Vertices With Varying Z Values, Extruded Relative To Existing 
            //           Vertex Z Values Via ConstructExtrude()

            IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass();

            IPointCollection polygonPointCollection = new PolygonClass();

            IPoint originPoint = GeometryUtilities.ConstructPoint3D(0, 0, 0);

            IVector3D upperAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, 10);

            IVector3D lowerAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, -10);

            lowerAxisVector3D.XComponent += VectorComponentOffset;

            IVector3D normalVector3D = upperAxisVector3D.CrossProduct(lowerAxisVector3D) as IVector3D;

            normalVector3D.Magnitude = CircleRadius;

            double rotationAngleInRadians = GeometryUtilities.GetRadians(CircleDegrees / CircleDivisions);

            Random random = new Random();

            for (int i = 0; i < CircleDivisions; i++)
            {
                normalVector3D.Rotate(-1 * rotationAngleInRadians, upperAxisVector3D);

                IPoint vertexPoint = GeometryUtilities.ConstructPoint3D(originPoint.X + normalVector3D.XComponent,
                                                                        originPoint.Y + normalVector3D.YComponent,
                                                                        BaseZ + 2 * Math.Sin(random.NextDouble()));

                polygonPointCollection.AddPoint(vertexPoint, ref _missing, ref _missing);
            }

            IPolygon polygon = polygonPointCollection as IPolygon;
            polygon.Close();

            IGeometry polygonGeometry = polygon as IGeometry;

            GeometryUtilities.MakeZAware(polygonGeometry);

            ITopologicalOperator topologicalOperator = polygon as ITopologicalOperator;
            topologicalOperator.Simplify();

            IConstructMultiPatch constructMultiPatch = new MultiPatchClass();
            constructMultiPatch.ConstructExtrude(OffsetZ, polygonGeometry);

            return constructMultiPatch as IGeometry;
        }
        public static IGeometry GetExample10()
        {
            const double CircleDegrees = 360.0;
            const int CircleDivisions = 36;
            const double VectorComponentOffset = 0.0000001;
            const double CircleRadius = 3.0;
            const double BaseZ = 0.0;

            //Extrusion: 3D Circle Polygon Extruded Along 3D Line Via ConstructExtrudeAlongLine()

            IPointCollection polygonPointCollection = new PolygonClass();

            IGeometry polygonGeometry = polygonPointCollection as IGeometry;

            GeometryUtilities.MakeZAware(polygonGeometry);

            IPoint originPoint = GeometryUtilities.ConstructPoint3D(0, 0, 0);

            IVector3D upperAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, 10);

            IVector3D lowerAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, -10);

            lowerAxisVector3D.XComponent += VectorComponentOffset;

            IVector3D normalVector3D = upperAxisVector3D.CrossProduct(lowerAxisVector3D) as IVector3D;

            normalVector3D.Magnitude = CircleRadius;

            double rotationAngleInRadians = GeometryUtilities.GetRadians(CircleDegrees / CircleDivisions);

            for (int i = 0; i < CircleDivisions; i++)
            {
                normalVector3D.Rotate(-1 * rotationAngleInRadians, upperAxisVector3D);

                IPoint vertexPoint = GeometryUtilities.ConstructPoint3D(originPoint.X + normalVector3D.XComponent,
                                                                      originPoint.Y + normalVector3D.YComponent,
                                                                      BaseZ);

                polygonPointCollection.AddPoint(vertexPoint, ref _missing, ref _missing);
            }

            polygonPointCollection.AddPoint(polygonPointCollection.get_Point(0), ref _missing, ref _missing);

            ITopologicalOperator topologicalOperator = polygonGeometry as ITopologicalOperator;
            topologicalOperator.Simplify();

            //Define Line To Extrude Along

            ILine extrusionLine = new LineClass();
            extrusionLine.FromPoint = GeometryUtilities.ConstructPoint3D(-4, -4, -5);
            extrusionLine.ToPoint = GeometryUtilities.ConstructPoint3D(4, 4, 5);

            //Perform Extrusion

            IConstructMultiPatch constructMultiPatch = new MultiPatchClass();
            constructMultiPatch.ConstructExtrudeAlongLine(extrusionLine, polygonGeometry);

            //Transform Extrusion Result

            IArea area = polygonGeometry as IArea;

            ITransform2D transform2D = constructMultiPatch as ITransform2D;
            transform2D.Move(extrusionLine.FromPoint.X - area.Centroid.X, extrusionLine.FromPoint.Y - area.Centroid.Y);

            return constructMultiPatch as IGeometry;
        }
예제 #35
0
        /// <summary>
        /// 将Envelope转换为多边形
        /// </summary>
        /// <param name="layerExtent">Envelope</param>
        /// <param name="pPolygon">结果多边形</param>
        /// <returns>操作结果</returns>
        public static bool ExchangeToPolygon(IEnvelope layerExtent, ref IPolygon4 pPolygon)
        {
            try
            {
                object Missing = Type.Missing;
                IPoint pPoint = new PointClass();
                IPointCollection pPointCol = new PolygonClass();
                pPoint.PutCoords(layerExtent.XMin, layerExtent.YMax);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMax, layerExtent.YMax);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMax, layerExtent.YMin);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMin, layerExtent.YMin);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPoint.PutCoords(layerExtent.XMin, layerExtent.YMax);
                pPointCol.AddPoint(pPoint, ref Missing, ref Missing);
                pPolygon = pPointCol as IPolygon4;
                return true;
            }
            catch(Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return false;
            }
        }
        /// <summary>
        ///     Draw the polygon contained within the properties.
        /// </summary>
        /// <param name="polyToBeDrawn">
        ///     The polygon to be drawn.
        /// </param>
        /// <param name="graphicContainer">
        ///     The graphic container.
        /// </param>
        private void DrawPoly(Properties polyToBeDrawn, IGraphicsContainer graphicContainer)
        {
            var poly = new PolygonClass();
            poly.Project(ArcMap.Document.ActiveView.Extent.SpatialReference);
            foreach (var pnt in polyToBeDrawn.Points)
            {
                var tempPoint = new PointClass();
                tempPoint.PutCoords(pnt.X, pnt.Y);
                tempPoint.SpatialReference = Jarvis.ProjectedCoordinateSystem;
                tempPoint.Project(ArcMap.Document.ActiveView.Extent.SpatialReference);
                poly.AddPoint(tempPoint);
            }

            IElement elm = new PolygonElementClass();
            elm.Geometry = poly;

            graphicContainer.AddElement(elm, 0);
        }
예제 #37
0
        /// <summary>
        /// �����ļ�չ����ͼ��
        /// </summary>
        public void TextToPolygon()
        {
            if (m_FeatureLayer.FeatureClass.ShapeType != ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon)
            {
                MessageBox.Show("��ȷ��չ��ĵ�һ��ͼ��Ϊ��ͼ��", "��ʾ��Ϣ", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                return;
            }
            OpenFileDialog openfileDialog = new OpenFileDialog();
            openfileDialog.Title = "��ѡ��չ����ͼ��������ļ�";
            openfileDialog.Filter = " txt files(*.txt)|*.txt|All files(*.*)|*.*";
            openfileDialog.RestoreDirectory = true;
            if (openfileDialog.ShowDialog() == DialogResult.OK)
            {
                frmW.WaitingLabel = "�����������...";
                frmW.Show();
                Application.DoEvents();
                LocalFilePath = openfileDialog.FileName;
                StreamReader strReadToEnd = new StreamReader(LocalFilePath);
                string sAllLine = strReadToEnd.ReadToEnd();
                int LineCount = sAllLine.Split('\n').Length + 1;
                string[] pline = new string[LineCount];
                double[] x = new double[LineCount];
                double[] y = new double[LineCount];
                string[] pSeparate = new string[] { };

                m_statusBar.Panels[0].ProgressBarMinValue = 0;
                m_statusBar.Panels[0].ProgressBarMaxValue = LineCount - 1;

                StreamReader strRead = new StreamReader(LocalFilePath);
                int i = 0;
                int j = 0;
                int count = 0;
                try
                {
                    if (strRead != null)
                    {
                        pline[i] = strRead.ReadLine();
                        IFeatureClass pFeaCls = m_FeatureLayer.FeatureClass;
                        IFeature pFeature = pFeaCls.CreateFeature();
                        IPointCollection pPointCol = new PolygonClass();
                        IPolygon pPolygon = pPointCol as IPolygon;
                        while (pline[i] != null)
                        {
                            pSeparate = pline[i].Split(',', ' ', ';');
                            if (pSeparate.Length >= 3)
                            {
                                x[j] = double.Parse(pSeparate[1]);
                                y[j] = double.Parse(pSeparate[2]);
                                IPoint pPoint = new PointClass();
                                pPoint.X = x[j];
                                pPoint.Y = y[j];
                                object miss = Type.Missing;
                                pPointCol.AddPoint(pPoint, ref miss, ref miss);
                                j++;
                                i++;
                                pline[i] = strRead.ReadLine();
                            }
                            else
                            {
                                if (count != 0)
                                {
                                    pFeature.Shape = pPointCol as IGeometry;
                                    pFeature.Store();
                                    m_mapControl.ActiveView.Refresh();
                                    pPointCol = new PolygonClass();
                                    pFeature = pFeaCls.CreateFeature();
                                    pPolygon = pPointCol as IPolygon;
                                }
                                count++;
                                i++;
                                pline[i] = strRead.ReadLine();
                            }
                            m_statusBar.Panels[0].ProgressBarValue = i;
                            frmW.WaitingLabel = "���ڻ��Ƶ� " + i.ToString() + " ����";
                            Application.DoEvents();
                        }
                    }
                    frmW.Close();
                    MessageBox.Show("������ɣ�");
                }
                catch
                {
                    MessageBox.Show("�����ı��ļ��ĵ�" + i + "��", "������Ϣ", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
            }
            ICommand pCommand = new ControlsMapFullExtentCommandClass();
            pCommand.OnCreate(m_mapControl.Object);
            pCommand.OnClick();
            m_statusBar.Panels[0].ProgressBarValue = 0;
        }
예제 #38
0
        //编辑层
        public void AddPointByBuffer(int index)
        {
            IPoint point1 = new PointClass();
            //point1.PutCoords(101, 40);
            point1 = GetProject2(-120, 20);
            IPoint point2 = new PointClass();
            //point2.PutCoords(110, 40);
            point2 = GetProject2(-120, 40);
            //IPoint point3 = new PointClass();
            //point3.PutCoords(112, 40);

            object o = Type.Missing;
            IPointCollection pointCollection = new PolygonClass();
            pointCollection.AddPoint(point1, ref o, ref o);
            pointCollection.AddPoint(point2, ref o, ref o);
            //pointCollection.AddPoint(point3, ref o, ref o);
            IPolygon polygon = pointCollection as IPolygon;

            IElement element = new PolygonElementClass();
            element.Geometry = polygon;
            IGraphicsContainer graphicsContainer = axMapControl.Map as IGraphicsContainer;
            graphicsContainer.AddElement(element, 0);
            axMapControl.Refresh();
            //ILayer pLayer = this.axMapControl.get_Layer(2);//获取当前图层,此图层为组图层,需要转换
            //GlobeGraphicsLayer cLyr = null;
            //if (pLayer is GlobeLayer)
            //{
            //    //cLyr = (GlobeGraphicsLayer)pLayer;

            //    IFeatureLayer pFeatureLyr = pLayer as IFeatureLayer;//将ILayer转换为IFeaturelayer,为了对图层上的要素进行编辑
            //    IFeatureClass pFeatCls = pFeatureLyr.FeatureClass;//定义一个要素集合,并获取图层的要素集合
            //    IFeatureClassWrite fr = (IFeatureClassWrite)pFeatCls;//定义一个实现新增要素的接口实例,并该实例作用于当前图层的要素集
            //    IWorkspaceEdit w = (pFeatCls as IDataset).Workspace as IWorkspaceEdit;//定义一个工作编辑工作空间,用于开启前图层的编辑状态
            //    IFeature f;//定义一个IFeature实例,用于添加到当前图层上
            //    w.StartEditing(true);//开启编辑状态
            //    w.StartEditOperation();//开启编辑操作
            //    //IPoint p;//定义一个点,用来作为IFeature实例的形状属性,即shape属性
            //    //下面是设置点的坐标和参考系

            //    //IFeatureLayer l = axMapControl.Map.get_Layer(index) as IFeatureLayer;

            //    //IFeatureClass fc = l.FeatureClass;

            //    //IFeatureClassWrite fr = fc as IFeatureClassWrite;

            //    //IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit;

            //    //IFeature f;
            //    //可选参数的设置

            //    object Missing = Type.Missing;

            //    IPoint p = new PointClass();

            //    w.StartEditing(true);

            //    w.StartEditOperation();
            //    IPolygon polygon;

            //    for (int i = 0; i < 100; i++)
            //    {

            //        f = pFeatCls.CreateFeature();

            //        //定义一个多义线对象

            //        //IPolyline PlyLine = new PolylineClass();

            //        //定义一个点的集合

            //        IPointCollection ptclo = new PolygonClass();

            //        //定义一系列要添加到多义线上的点对象,并赋初始值

            //        for (int j = 0; j < 4; j++)
            //        {
            //            p.PutCoords(j, j);

            //            ptclo.AddPoint(p, ref Missing, ref Missing);

            //        }

            //        //IPointCollection pointCollection = new PolygonClass();

            //        polygon = ptclo as IPolygon;

            //        IElement element = new PolygonElementClass();
            //        element.Geometry = polygon;
            //        IGraphicsContainer graphicsContainer = axMapControl.Map as IGraphicsContainer;
            //        graphicsContainer.AddElement(element, 0);
            //        axMapControl.Refresh();
            //        //f.Shape = PlyLine;

            //        //fr.WriteFeature(f);

            //        IGeometry geo = (IGeometry)polygon;

            //    //开始画点
            //    IMarkerElement pMarkerElement;//对于点,线,面的element定义这里都不一样,他是可实例化的类,而IElement是实例化的类,必须通过 IMarkerElement 初始化负值给 IElement 。
            //    IElement pMElement;
            //    pMarkerElement = new MarkerElementClass();

            //    pMElement = pMarkerElement as IElement;

            //    pMElement.Geometry = polygon;//把你在屏幕中画好的图形付给 IElement 储存
            //    IGraphicsContainer pGraphicsContainer = axMapControl.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器

            //    pGraphicsContainer.AddElement(pMElement, 0);//显示储存在 IElement 中图形,这样就持久化了。

            //    axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

            //    }

            //    //p = new PointClass();
            //    p.SpatialReference = this.axMapControl.SpatialReference;
            //    //p.X = 600;
            //    //p.Y = 500;

            //    //将IPoint设置为IFeature的shape属性时,需要通过中间接口IGeometry转换
            //    IGeometry peo;
            //    peo = p;
            //    f = pFeatCls.CreateFeature();//实例化IFeature对象, 这样IFeature对象就具有当前图层上要素的字段信息
            //    f.Shape = peo;//设置IFeature对象的形状属性
            //    //f.set_Value(0, "Marker01");//设置IFeature对象的索引是3的字段值
            //    f.Store();//保存IFeature对象
            //    fr.WriteFeature(f);//将IFeature对象,添加到当前图层上
            //    w.StopEditOperation();//停止编辑操作
            //    w.StopEditing(true);//关闭编辑状态,并保存修改
            //    this.axMapControl.Refresh();//刷新地图
            //}

            //IFeatureLayer l = axMapControl.Map.get_Layer(index) as IFeatureLayer;

            //IFeatureClass fc = l.FeatureClass;

            //IFeatureClassWrite fr = fc as IFeatureClassWrite;

            //IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit;

            //IFeature f;
            ////可选参数的设置

            //object Missing = Type.Missing;

            //IPoint p = new PointClass();

            //w.StartEditing(true);

            //w.StartEditOperation();

            //for (int i = 0; i < 100; i++)
            //{

            //    f = fc.CreateFeature();

            //    //定义一个多义线对象

            //    IPolyline PlyLine = new PolylineClass();

            //    //定义一个点的集合

            //    IPointCollection ptclo = PlyLine as IPointCollection;

            //    //定义一系列要添加到多义线上的点对象,并赋初始值

            //    for (int j = 0; j < 4; j++)
            //    {
            //        p.PutCoords(j, j);

            //        ptclo.AddPoint(p, ref Missing, ref Missing);

            //    }

            //    f.Shape = PlyLine;

            //    fr.WriteFeature(f);

            //}

            //w.StopEditOperation();

            //w.StopEditing(true);
        }
예제 #39
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                object Missing = Type.Missing;

                IPoint pPointNew = new PointClass();
                int count = listView1.Items.Count;
                if (count == 0)
                {
                    MessageBox.Show("There is no Euler Pole!");
                    return;
                }
                string ContiName = listView1.Items[0].Text;

                CCEuler.EulerPole rotpol;
                CCEuler.EulerPole p;

                double eulerangle;
                double[,] m = new double[3, 3];

                double Ptime;

                Form form_current = Application.OpenForms["ParentForm"];

                ChildForm activeMdiChild = (ChildForm)form_current.ActiveMdiChild;
                IMap pMap = activeMdiChild.axMapControl1.ActiveView.FocusMap;
                IEnvelope pEnv = activeMdiChild.axMapControl1.ActiveView.Extent;
                ISpatialReference pSR = pMap.SpatialReference;

                int lPart;
                int lVertex;

                double firstx = 0;
                double firsty = 0;

                if (activeMdiChild.axMapControl1.ActiveView.FocusMap.SelectionCount < 0)
                {
                    MessageBox.Show("selectable is not correct!");
                    return;
                }

                for (int i = 0; i < count; i++)
                {
                    IEnumFeature pEnumFeat = (IEnumFeature)activeMdiChild.axMapControl1.ActiveView.FocusMap.FeatureSelection;
                    pEnumFeat.Reset();
                    IFeature pFeat = pEnumFeat.Next();

                    rotpol.Lattd = Convert.ToDouble(listView1.Items[i].SubItems[2].Text);
                    rotpol.Longttd = Convert.ToDouble(listView1.Items[i].SubItems[3].Text);
                    eulerangle = Convert.ToDouble(listView1.Items[i].SubItems[4].Text);
                    Ptime = Convert.ToDouble(listView1.Items[i].SubItems[1].Text);

                    CCEuler.calc_pole2matrix(out m, rotpol, eulerangle);

                    saveFileDialog1.ShowDialog();
                    string fullpath = saveFileDialog1.FileName;
                    string strName = System.IO.Path.GetFileNameWithoutExtension(fullpath);
                    string folder = System.IO.Path.GetDirectoryName(fullpath);

                    IFeatureClass pFeatClass = null;

                    if (pFeat.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
                    {
                        CCCreatePolygonFile CrteatePolygonFile = new CCCreatePolygonFile();
                        pFeatClass = CrteatePolygonFile.CreatePolygonFile(folder, strName, pEnv, pSR);

                        while (pFeat != null)
                        {
                            IFields pFlds = pFeat.Table.Fields;
                            long lIndex = pFlds.FindField("Shape");
                            IField pFld = pFlds.get_Field(Convert.ToInt32(lIndex));
                            IPoint pPoint = new PointClass();

                            IPointCollection pPointCollection = (IPointCollection)pFeat.get_Value(Convert.ToInt32(lIndex));
                            IEnumVertex pEnum = pPointCollection.EnumVertices;

                            pEnum.Reset();
                            IPointCollection pNewPointCol = new PolygonClass();
                            pEnum.Next(out pPoint, out  lPart, out lVertex);
                            int first = 0;

                            while (pPoint != null)
                            {
                                p.Longttd = pPoint.X;
                                p.Lattd = pPoint.Y;

                                double X, Y, z;
                                double X1, Y1, z1;

                                CCEuler.sphere2kart(out X, out Y, out z, p);
                                X1 = m[0, 0] * X + m[0, 1] * Y + m[0, 2] * z;
                                Y1 = m[1, 0] * X + m[1, 1] * Y + m[1, 2] * z;
                                z1 = m[2, 0] * X + m[2, 1] * Y + m[2, 2] * z;
                                CCEuler.kart2sphere(out p, X1, Y1, z1);

                                pPointNew.PutCoords(p.Longttd, p.Lattd);

                                if (first == 0)
                                {
                                    firstx = p.Longttd;
                                    firsty = p.Lattd;
                                }

                                pNewPointCol.AddPoint(pPointNew, ref Missing, ref Missing);

                                pEnum.Next(out pPoint, out  lPart, out lVertex);
                                first = 1;
                            }

                            pPointNew.PutCoords(firstx, firsty);

                            pNewPointCol.AddPoint(pPointNew, ref Missing, ref Missing);

                            IFeature pNewfeature = pFeatClass.CreateFeature();
                            pNewfeature.Shape = (IGeometry)pNewPointCol;
                            pNewfeature.Store();

                            pFeat = pEnumFeat.Next();
                        }
                        IFeatureLayer pFLayer = new FeatureLayerClass();
                        pFLayer.FeatureClass = pFeatClass;
                        pFLayer.Name = pFeatClass.AliasName;
                        pMap.AddLayer(pFLayer);

                        activeMdiChild.axMapControl1.ActiveView.Refresh();
                        System.Threading.Thread.Sleep(800);

                        break;
                    }

                    if (pFeat.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                    {
                        CCCreatePolygonFile CreatePolygonFile = new CCCreatePolygonFile();
                        pFeatClass = CreatePolygonFile.CreatePolylineFile(folder, strName, pEnv, pSR);

                        while (pFeat != null)
                        {
                            IFields pFlds = pFeat.Table.Fields;
                            long lIndex = pFlds.FindField("Shape");
                            IField pFld = pFlds.get_Field(Convert.ToInt32(lIndex));
                            IPoint pPoint = new PointClass();

                            IPointCollection pPointCollection = (IPointCollection)pFeat.get_Value(Convert.ToInt32(lIndex));
                            IEnumVertex pEnum = pPointCollection.EnumVertices;

                            pEnum.Reset();

                            IPointCollection pNewPointCol = new PolylineClass();
                            pEnum.Next(out pPoint, out  lPart, out lVertex);

                            int first = 0;

                            while (pPoint != null)
                            {
                                p.Longttd = pPoint.X;
                                p.Lattd = pPoint.Y;

                                double X, Y, z;
                                double X1, Y1, z1;

                                CCEuler.sphere2kart(out X, out Y, out z, p);
                                X1 = m[0, 0] * X + m[0, 1] * Y + m[0, 2] * z;
                                Y1 = m[1, 0] * X + m[1, 1] * Y + m[1, 2] * z;
                                z1 = m[2, 0] * X + m[2, 1] * Y + m[2, 2] * z;
                                CCEuler.kart2sphere(out p, X1, Y1, z1);

                                pPointNew.PutCoords(p.Longttd, p.Lattd);

                                if (first == 0)
                                {
                                    firstx = p.Longttd;
                                    firsty = p.Lattd;
                                }

                                pNewPointCol.AddPoint(pPointNew, ref Missing, ref Missing);

                                pEnum.Next(out pPoint, out  lPart, out lVertex);
                                first = 1;
                            }

                            pNewPointCol.AddPoint(pPointNew, ref Missing, ref Missing);

                            IFeature pNewfeature = pFeatClass.CreateFeature();
                            pNewfeature.Shape = (IGeometry)pNewPointCol;
                            pNewfeature.Store();

                            pFeat = pEnumFeat.Next();
                        }

                        IFeatureLayer pFLayer = new FeatureLayerClass();
                        pFLayer.FeatureClass = pFeatClass;
                        pFLayer.Name = pFeatClass.AliasName;
                        pMap.AddLayer(pFLayer);

                        activeMdiChild.axMapControl1.ActiveView.Refresh();
                        System.Threading.Thread.Sleep(800);

                        break;
                    }

                    if (pFeat.Shape.GeometryType == esriGeometryType.esriGeometryPoint)
                    {

                        CCCreatePolygonFile CreatePolygonFile = new CCCreatePolygonFile();
                        pFeatClass = CreatePolygonFile.CreatePointFile(folder, strName, pEnv, pSR);

                        while (pFeat != null)
                        {
                            IFields pFlds = pFeat.Table.Fields;
                            long lIndex = pFlds.FindField("Shape");
                            IField pFld = pFlds.get_Field(Convert.ToInt32(lIndex));
                            IPoint pPoint = (IPoint)pFeat.get_Value(Convert.ToInt32(lIndex));

                            while (pPoint != null)
                            {
                                p.Longttd = pPoint.X;
                                p.Lattd = pPoint.Y;

                                pPointNew.PutCoords(p.Longttd, p.Lattd);
                                break;
                            }

                            IFeature pNewfeature = pFeatClass.CreateFeature();
                            pNewfeature.Shape = (IGeometry)pPointNew;

                            pNewfeature.Store();
                            pFeat = pEnumFeat.Next();
                        }

                        IFeatureLayer pFLayer = new FeatureLayerClass();
                        pFLayer.FeatureClass = pFeatClass;
                        pFLayer.Name = pFeatClass.AliasName;
                        pMap.AddLayer(pFLayer);

                        activeMdiChild.axMapControl1.ActiveView.Refresh();
                        System.Threading.Thread.Sleep(800);

                        break;
                    }
                }

                MessageBox.Show("OK!");
                FrmReconstruct.ActiveForm.Close();
            }
            catch
            {
                MessageBox.Show("Choose the plate to reconstruct");
            }
        }
        /// <summary>
        /// 根据传入的左邦点数组和右邦点数组生成巷道
        /// </summary>
        /// <param name="tunnel"></param>
        /// <param name="pts"></param>
        /// <param name="editlayer"></param>
        public void DrawHuDong(TunnelEntity tunnel, WirePointInfoEntity[] pts, IFeatureLayer editlayer)
        {
            IPoint point = new PointClass();
               IPointCollection4 pointCollection = new PolygonClass();
               TunnelPointsCalculation TPC = new TunnelPointsCalculation();
               Vector3_DW[] lstLeftBtmVertices = null;
               Vector3_DW[] lstRightBtmVertices = null;
               TPC.CalcLeftAndRightVertics(pts, ref lstLeftBtmVertices,ref lstRightBtmVertices);
               for (int intI = 0; intI < lstLeftBtmVertices.Length; intI++)
               {
               point.X = lstLeftBtmVertices[intI].X;
               point.Y = lstLeftBtmVertices[intI].Y;
               point.Z = lstLeftBtmVertices[intI].Z;
               pointCollection.AddPoint(point);
               }
               for (int intI = lstRightBtmVertices.Length; intI >=0; intI--)
               {
               point.X = lstRightBtmVertices[intI].X;
               point.Y = lstRightBtmVertices[intI].Y;
               point.Z = lstRightBtmVertices[intI].Z;
               pointCollection.AddPoint(point);
               }

               IFeature f;
               IGeometryCollection polygon;
               //定义一个地物类,把要编辑的图层转化为定义的地物类
               IFeatureClass fc = editlayer.FeatureClass;
               //先定义一个编辑的工作空间,然后把转化为数据集,最后转化为编辑工作空间,
               IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit;
               //开始事务操作
               w.StartEditing(false);
               //开始编辑
               w.StartEditOperation();
               //创建一个地物

               //绘制巷道

               polygon = new PolygonClass();
               IGeometryCollection pGeoColl = pointCollection as IGeometryCollection;
               ISegmentCollection pRing = new RingClass();
               pRing.AddSegmentCollection(pGeoColl as ISegmentCollection);

               polygon.AddGeometry(pRing as IGeometry);
               IPolygon polyGonGeo = polygon as IPolygon;
               polyGonGeo.SimplifyPreserveFromTo();
               f = fc.CreateFeature();
               //polygon.PutCoords(Convert.ToDouble(ge.CoordinateX), Convert.ToDouble(ge.CoordinateY));
               //确定图形类型
               f.Shape = (IGeometry)polyGonGeo;

               //给巷道赋属性值
               int num3;
               //num3 = editlayer.FeatureClass.Fields.FindField("OBJECTID");
               //f.set_Value(num3, tunnel.TunnelID);
               num3 = editlayer.FeatureClass.Fields.FindField("MINE_NAME");
               f.set_Value(num3, tunnel.MineName);
               num3 = editlayer.FeatureClass.Fields.FindField("HORIZONTAL");
               f.set_Value(num3, tunnel.HorizontalName);
               num3 = editlayer.FeatureClass.Fields.FindField("MINING_AREA");
               f.set_Value(num3, tunnel.MiningAreaName);
               num3 = editlayer.FeatureClass.Fields.FindField("WORKING_FACE");
               f.set_Value(num3, tunnel.WorkingFaceName);
               num3 = editlayer.FeatureClass.Fields.FindField("TUNNEL_NAME");
               f.set_Value(num3, tunnel.TunnelName);
               num3 = editlayer.FeatureClass.Fields.FindField("SUPPORT_PATTERN");
               f.set_Value(num3, tunnel.TunnelSupportPattern);
               num3 = editlayer.FeatureClass.Fields.FindField("LITHOLOGY_ID");
               f.set_Value(num3, tunnel.TunnelLithologyID);
               num3 = editlayer.FeatureClass.Fields.FindField("FAULTAGETYPE");
               f.set_Value(num3, tunnel.TunnelSectionType);
               num3 = editlayer.FeatureClass.Fields.FindField("PARAM");
               f.set_Value(num3, tunnel.TunnelParam);
               num3 = editlayer.FeatureClass.Fields.FindField("DESIGNLENGTH");
               f.set_Value(num3, tunnel.TunnelDesignLength);
               //num3 = editlayer.FeatureClass.Fields.FindField("RULE_CODE");
               //f.set_Value(num3, tunnel.r);
               //保存地物
               f.Store();
              //渲染巷道样式
               ISimpleFillSymbol pFillSymbol;
               pFillSymbol = new SimpleFillSymbolClass();
               pFillSymbol.Color = getRGB(60, 100, 50);
               pFillSymbol.Outline.Color = getRGB(60, 100, 50);
               pFillSymbol.Outline.Width = 1;
               pFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
               RenderfeatureLayer(editlayer, pFillSymbol as ISymbol);
               //结束编辑
               w.StopEditOperation();
               //结束事务操作
               w.StopEditing(true);
        }
예제 #41
0
        //点成面
        public static void PointToPolygon(AxMapControl axMapControl, double x, double y,int m)
        {
            IPointCollection pCol = new PolygonClass();
            object missing = Type.Missing;
            for(int i=0;i<m;i++)
            {
              IPoint ppp=new PointClass();

              pCol.AddPoint(ppp, ref missing, ref missing);
            }
        }
        public static IGeometry GetExample15()
        {
            const double CircleDegrees = 360.0;
            const int CircleDivisions = 36;
            const double VectorComponentOffset = 0.0000001;
            const double CircleRadius = 9.5;
            const int PointCount = 100;
            const double UpperZMin = 7;
            const double UpperZMax = 10;
            const double LowerZMin = 0;
            const double LowerZMax = 3;

            //Extrusion: Circle Shaped Base Geometry Extruded Between Two Different TIN-Based Functional Surfaces

            IGeometryCollection multiPatchGeometryCollection = new MultiPatchClass();

            //Base Geometry

            IPointCollection polygonPointCollection = new PolygonClass();

            IPoint originPoint = GeometryUtilities.ConstructPoint3D(0, 0, 0);

            IVector3D upperAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, 10);

            IVector3D lowerAxisVector3D = GeometryUtilities.ConstructVector3D(0, 0, -10);

            lowerAxisVector3D.XComponent += VectorComponentOffset;

            IVector3D normalVector3D = upperAxisVector3D.CrossProduct(lowerAxisVector3D) as IVector3D;

            normalVector3D.Magnitude = CircleRadius;

            double rotationAngleInRadians = GeometryUtilities.GetRadians(CircleDegrees / CircleDivisions);

            for (int i = 0; i < CircleDivisions; i++)
            {
                normalVector3D.Rotate(-1 * rotationAngleInRadians, upperAxisVector3D);

                IPoint vertexPoint = GeometryUtilities.ConstructPoint2D(originPoint.X + normalVector3D.XComponent,
                                                                        originPoint.Y + normalVector3D.YComponent);

                polygonPointCollection.AddPoint(vertexPoint, ref _missing, ref _missing);
            }

            IPolygon polygon = polygonPointCollection as IPolygon;
            polygon.Close();

            IGeometry baseGeometry = polygon as IGeometry;

            ITopologicalOperator topologicalOperator = polygon as ITopologicalOperator;
            topologicalOperator.Simplify();

            //Functional Surfaces

            IEnvelope envelope = new EnvelopeClass();
            envelope.XMin = -10;
            envelope.XMax = 10;
            envelope.YMin = -10;
            envelope.YMax = 10;

            Random random = new Random();

            //Upper Functional Surface

            ITinEdit upperTinEdit = new TinClass();
            upperTinEdit.InitNew(envelope);

            for (int i = 0; i < PointCount; i++)
            {
                double x = envelope.XMin + (envelope.XMax - envelope.XMin) * random.NextDouble();
                double y = envelope.YMin + (envelope.YMax - envelope.YMin) * random.NextDouble();
                double z = UpperZMin + (UpperZMax - UpperZMin) * random.NextDouble();

                IPoint point = GeometryUtilities.ConstructPoint3D(x, y, z);

                upperTinEdit.AddPointZ(point, 0);
            }

            IFunctionalSurface upperFunctionalSurface = upperTinEdit as IFunctionalSurface;

            //Lower Functional Surface

            ITinEdit lowerTinEdit = new TinClass();
            lowerTinEdit.InitNew(envelope);

            for (int i = 0; i < PointCount; i++)
            {
                double x = envelope.XMin + (envelope.XMax - envelope.XMin) * random.NextDouble();
                double y = envelope.YMin + (envelope.YMax - envelope.YMin) * random.NextDouble();
                double z = LowerZMin + (LowerZMax - LowerZMin) * random.NextDouble();

                IPoint point = GeometryUtilities.ConstructPoint3D(x, y, z);

                lowerTinEdit.AddPointZ(point, 0);
            }

            IFunctionalSurface lowerFunctionalSurface = lowerTinEdit as IFunctionalSurface;

            IConstructMultiPatch constructMultiPatch = new MultiPatchClass();
            constructMultiPatch.ConstructExtrudeBetween(upperFunctionalSurface, lowerFunctionalSurface, baseGeometry);

            return constructMultiPatch as IGeometry;
        }
        /// <summary>
        ///     The get geo hash poly.
        /// </summary>
        /// <param name="geohash">
        ///     The geo hash.
        /// </param>
        /// <returns>
        ///     The <see cref="Polygon" />.
        /// </returns>
        private Polygon GetGeoHashPoly(string geohash)
        {
            var coords = Jarvis.DecodeBbox(geohash);
            IPoint pt1 = new PointClass();
            pt1.PutCoords(coords[1], coords[2]);
            IPoint pt2 = new PointClass();
            pt2.PutCoords(coords[3], coords[2]);
            IPoint pt3 = new PointClass();
            pt3.PutCoords(coords[3], coords[0]);
            IPoint pt4 = new PointClass();
            pt4.PutCoords(coords[1], coords[0]);

            Polygon poly = new PolygonClass();
            poly.AddPoint(pt1);
            poly.AddPoint(pt2);
            poly.AddPoint(pt3);
            poly.AddPoint(pt4);
            poly.AddPoint(pt1);

            return poly;
        }
        public static IPolygon CreatePolyFromEnv(IEnvelope pEnv)
        {
            if (pEnv == null)
                return null;
            object o = Type.Missing;

            IPointCollection pPointCol = new PolygonClass();

            IPoint pPoint = new PointClass();
            pPoint.PutCoords(pEnv.XMin, pEnv.YMin);
            pPointCol.AddPoint(pPoint, ref o, ref o);

            pPoint = new PointClass();
            pPoint.PutCoords(pEnv.XMin, pEnv.YMax);
            pPointCol.AddPoint(pPoint, ref o, ref o);

            pPoint = new PointClass();
            pPoint.PutCoords(pEnv.XMax, pEnv.YMax);
            pPointCol.AddPoint(pPoint, ref o, ref o);

            pPoint = new PointClass();
            pPoint.PutCoords(pEnv.XMax, pEnv.YMin);
            pPointCol.AddPoint(pPoint, ref o, ref o);

            pPoint = new PointClass();
            pPoint.PutCoords(pEnv.XMin, pEnv.YMin);
            pPointCol.AddPoint(pPoint, ref o, ref o);

            IGeometry pGeom = (IGeometry)pPointCol;
            pGeom.SpatialReference = pEnv.SpatialReference;

            return (IPolygon)pGeom;
        }
        public static IGeometry GetExample3() 
        {
            const double FromZ = 0;
            const double ToZ = 9.5;

            //Extrusion: Square Shaped 2D Polygon Extruded To Generate 3D Building Via ConstructExtrudeFromTo()

            IPointCollection polygonPointCollection = new PolygonClass();

            polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-2, 2), ref _missing, ref _missing);
            polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(2, 2), ref _missing, ref _missing);
            polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(2, -2), ref _missing, ref _missing);
            polygonPointCollection.AddPoint(GeometryUtilities.ConstructPoint2D(-2, -2), ref _missing, ref _missing);

            IPolygon polygon = polygonPointCollection as IPolygon;
            polygon.Close();

            IGeometry polygonGeometry = polygonPointCollection as IGeometry;

            ITopologicalOperator topologicalOperator = polygonGeometry as ITopologicalOperator;
            topologicalOperator.Simplify();

            IConstructMultiPatch constructMultiPatch = new MultiPatchClass();
            constructMultiPatch.ConstructExtrudeFromTo(FromZ, ToZ, polygonGeometry);

            return constructMultiPatch as IGeometry;
        }
예제 #46
0
 public IPolygon ToPolygon(params string[] args)
 {
     if (args == null || (int)args.Length < 6)
     {
         throw new Exception("At least 6 coordinates are required to create a Polygon.");
     }
     if ((int)args.Length % 2 != 0)
     {
         throw new Exception(string.Format("Invalid number [{0}] of coordinates (must be multiple of 2).", (int)args.Length));
     }
     IPointCollection polygonClass = new PolygonClass();
     IPolygon spatialReference = (IPolygon)polygonClass;
     for (int i = 0; i < (int)args.Length; i = i + 2)
     {
         IPoint point = this.ToPoint(args[i], args[i + 1]);
         object value = Missing.Value;
         object obj = Missing.Value;
         polygonClass.AddPoint(point, ref value, ref obj);
     }
     if (!spatialReference.IsClosed)
     {
         spatialReference.Close();
     }
     spatialReference.SpatialReference = this.GetSpatialReference(null);
     return spatialReference;
 }
예제 #47
0
        /// <summary>
        /// 获得回采多边形点列表,最后点为切眼中心点
        /// </summary>
        /// <params name="pline1"></巷道1>
        /// <params name="pline2"></巷道2>
        /// <params name="pline3"></切眼>
        /// <params name="widthhd"></巷道宽度>
        /// <params name="widthqy"></切眼宽度>
        /// <params name="hcDis"></回采距离>
        /// <params name="direct"></回采方向,pline3 from-to方向,返回1-切眼右侧, 返回-1-切眼左侧(),只在中间回采时使用此参数,开始回采时值为0>
        /// <returns></returns>
        public IPointCollection GetBackPolygonArea(IPolyline pline1, IPolyline pline2, IPolyline pline3, double widthhd, double widthhd1, double widthqy, double hcDis, int direct)
        {
            object obj = Type.Missing;
            //ESRI.ArcGIS.Geometry.IPolyline polylineall = new ESRI.ArcGIS.Geometry.PolylineClass();
            IPolyline offsetqy = null;
            Boolean bright = false;
            //交点1(切眼与巷道1交点)
            IPoint point1 = GetIntersectPointExtend(pline3, pline1);

            //交点2(切眼与巷道2交点)
            IPoint point2 = GetIntersectPointExtend(pline3, pline2);

            //CreateFeature(pline3, GetLayerByName("中心线全"));
            int iDirect; //依据切眼与巷道的关系判断回采方向,切眼为巷道起点时使用
            if (direct != 0) //中心点回采
            {
                IPoint outpnt = new PointClass();
                iDirect = direct;
                offsetqy = GetExtentQy(pline1, pline2, pline3);
            }
            else
            {
                iDirect = GetBackDirection(pline3, 200, pline1, pline2);
                offsetqy = ConstructOffset(pline3, widthqy / 2.0 * iDirect);
            } //切眼平移后的线
            IPoint pointCent = ConstructMiddlePoint(offsetqy, offsetqy.Length / 2);//取平移后线的中点
            //平移两侧巷道
            //CreateFeature(pointCent, GetLayerByName("testpoint"));
            //CreateFeature(offsetqy, GetLayerByName("中心线全"));
            IPolyline offsethd1 = GetConstructOffsetHD(pline1, widthhd / 2, pointCent);
            IPolyline offsethd2 = GetConstructOffsetHD(pline2, widthhd1 / 2, pointCent);

            //取两条巷道与切眼交点
            IPoint pnt1 = GetIntersectPoint(offsethd1, offsetqy);
            IPoint pnt2 = GetIntersectPoint(offsethd2, offsetqy);

            ////理顺巷道线的方向
            IPoint outpoint = new PointClass();
            IPolyline offsethd1dir = GetPointPos(pline3.FromPoint, pline3.ToPoint, offsethd1, iDirect);
            IPolyline offsethd2dir = GetPointPos(pline3.FromPoint, pline3.ToPoint, offsethd2, iDirect);

            double dishd1 = 0; double alonghd1 = 0;
            offsethd1dir.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pnt1, false, outpoint, ref alonghd1, ref dishd1, ref bright);

            double dishd2 = 0; double alonghd2 = 0;
            offsethd2dir.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pnt2, false, outpoint, ref alonghd2, ref dishd2, ref bright);

            ICurve newhd1 = new PolylineClass();
            offsethd1dir.GetSubcurve(alonghd1, hcDis + alonghd1, false, out newhd1);

            ICurve newhd2 = new PolylineClass();
            offsethd2dir.GetSubcurve(alonghd2, hcDis + alonghd2, false, out newhd2);

            IPointCollection pntPolycol = new PolygonClass() as IPointCollection;
            IPointCollection pntlinecol = newhd1 as IPointCollection;
            int i = 0;
            IPoint point = null;
            for (i = 0; i < pntlinecol.PointCount; i++)
            {
                point = pntlinecol.get_Point(i);
                pntPolycol.AddPoint(point, ref obj, ref obj);
            }

            pntlinecol = newhd2 as IPointCollection;

            //取回采后切眼的中点
            IPolyline polylineendqy = new PolylineClass();

            if (point == null)
            {
                polylineendqy.FromPoint = point1;
                polylineendqy.ToPoint = point2;
            }
            else
            {
                polylineendqy.FromPoint = point;
                polylineendqy.ToPoint = pntlinecol.get_Point(pntlinecol.PointCount - 1);
            }
            IPoint pointendqyCent = ConstructMiddlePoint(polylineendqy, polylineendqy.Length / 2);//终点切眼的中点

            for (i = pntlinecol.PointCount - 1; i >= 0; i--)
            {
                point = pntlinecol.get_Point(i);
                pntPolycol.AddPoint(point, ref obj, ref obj);
            }
            pntPolycol.AddPoint(pointendqyCent, ref obj, ref obj);

            return pntPolycol;
        }
예제 #48
0
        private void confirmbutton_Click(object sender, EventArgs e)
        {
            List<List<double>> param = new List<List<double>>();
            List<List<double>> newparam = new List<List<double>>();
            if (openfilepath != null && savefilepath != null)
            {
                try
                {
                    //动态数组按行读取txt文档
                    System.IO.FileStream  file = new System.IO.FileStream(openfilepath, FileMode.Open);
                    StreamReader sr = new StreamReader(file);
                    string strLine0 = sr.ReadLine();
                    while (!sr.EndOfStream)
                    {
                        string[] line = sr.ReadLine().Split(' ');
                        string imgname = line[0].Substring(4, line[0].Length - 8);
                        List<double> item = new List<double>();
                        item.Add(double.Parse(imgname));
                        item.Add(double.Parse(line[1]));
                        item.Add(double.Parse(line[2]));
                        item.Add(double.Parse(line[3]));
                        item.Add(double.Parse(line[4]));
                        item.Add(double.Parse(line[5]));
                        item.Add(double.Parse(line[6]));
                        param.Add(item);
                    }
                    sr.Close();
                    sr.Dispose();
                    file.Close();
                    file.Dispose();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("请选择文件!");
            }
            if (FdisBox.Text != "" && cxBox.Text != "" && cyBox.Text != "" && param != null)
            {
                for (int i = 0; i < param.Count; i++)
                {
                    scale = param[i][3] / double.Parse(FdisBox.Text) * 1000;
                    double w = double.Parse(cxBox.Text) / 2000 * scale;
                    double h = double.Parse(cyBox.Text) / 2000 * scale;
                    double x = param[i][1];
                    double y = param[i][2];

                    //三维旋转矩阵
                    var mb = Matrix<double>.Build;
                    var vb = Vector<double>.Build;
                    var pi = Math.PI;

                    var omega = param[i][4] * pi / 180;
                    var phi = param[i][5] * pi / 180;
                    var kappa = param[i][6] * pi / 180; ;
                    var a1 = Math.Cos(phi) * Math.Cos(kappa);
                    var a2 = -Math.Cos(phi) * Math.Sin(kappa);
                    var a3 = -Math.Sin(phi);
                    var b1 = Math.Cos(omega) * Math.Sin(kappa) - Math.Sin(omega) * Math.Sin(phi) * Math.Cos(kappa);
                    var b2 = Math.Cos(omega) * Math.Cos(kappa) + Math.Sin(omega) * Math.Sin(phi) * Math.Sin(kappa);
                    var b3 = -Math.Sin(omega) * Math.Cos(phi);
                    var c1 = Math.Sin(omega) * Math.Sin(kappa) + Math.Cos(omega) * Math.Sin(phi) * Math.Cos(kappa);
                    var c2 = Math.Sin(omega) * Math.Cos(kappa) - Math.Cos(omega) * Math.Sin(phi) * Math.Sin(kappa);
                    var c3 = Math.Cos(omega) * Math.Cos(phi);
                    var matrix = mb.DenseOfArray(new[,] { { a1, a2, a3 }, { b1, b2, b3 }, { c1, c2, c3 } });

                    //点向量
                    var vector1 = vb.Dense(new[] { -w, -h, 0 });
                    var vector2 = vb.Dense(new[] { w, -h, 0 });
                    var vector3 = vb.Dense(new[] { w, h, 0 });
                    var vector4 = vb.Dense(new[] { -w, h, 0 });

                    //矩阵运算
                    var resultv1 = matrix * vector1;
                    var resultv2 = matrix * vector2;
                    var resultv3 = matrix * vector3;
                    var resultv4 = matrix * vector4;
                    double x1 = resultv1[0] + x;
                    double y1 = resultv1[1] + y;
                    double x2 = resultv2[0] + x;
                    double y2 = resultv2[1] + y;
                    double x3 = resultv3[0] + x;
                    double y3 = resultv3[1] + y;
                    double x4 = resultv4[0] + x;
                    double y4 = resultv4[1] + y;

                    List<double> item = new List<double>();
                    item.Add(param[i][0]);
                    item.Add(param[i][1]);
                    item.Add(param[i][2]);
                    item.Add(param[i][3]);
                    item.Add(param[i][4]);
                    item.Add(param[i][5]);
                    item.Add(param[i][6]);
                    item.Add(x1);
                    item.Add(y1);
                    item.Add(x2);
                    item.Add(y2);
                    item.Add(x3);
                    item.Add(y3);
                    item.Add(x4);
                    item.Add(y4);
                    newparam.Add(item);

                }

                ////按行写入text文档
                //FileStream cfile = new FileStream(closefilepath, FileMode.Open);
                //StreamWriter sw = new StreamWriter(cfile);
                //sw.WriteLine("x y z omega phi kappa x1 y1 x2 y2 x3 y3 x4 y4");
                //if (newparam != null)
                //{
                //    for (var i = 0; i < newparam.Count; i++)
                //    {
                //        string wstr = "IMG_" + newparam[i][0] + " " + newparam[i][1] + " " + newparam[i][2] + " " + newparam[i][3] + " " + newparam[i][4] + " " +
                //            newparam[i][5] + " " + newparam[i][6] + " " + newparam[i][7] + " " + newparam[i][8] + " " + newparam[i][9] + " " + newparam[i][10] +
                //            " " + newparam[i][11] + " " + newparam[i][12] + " " + newparam[i][13] + " " + newparam[i][14];
                //        sw.WriteLine(wstr);
                //    }
                //}
                //sw.Close();
                //sw.Dispose();
                //cfile.Close();
                //cfile.Dispose();

                //shp文件存储
                int index = 0;
                index = savefilepath.LastIndexOf("\\");
                string filePath = savefilepath.Substring(0, index);
                string fileName = savefilepath.Substring(index + 1, savefilepath.Length - index - 1);
                Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
                System.Object obj = Activator.CreateInstance(factoryType);
                ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3;
                ISpatialReference spatialReference = spatialReferenceFactory.CreateSpatialReference(4490);

                IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace pFWS = (IFeatureWorkspace)pWSF.OpenFromFile(filePath, 0);
                //检查文件是否存在
                if (System.IO.File.Exists(savefilepath))
                {
                    //if (MessageBox.Show("该文件夹下已经有同名面文件,替换原文件?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    //{
                    //    //IFeatureWorkspace FWS = pWSF.OpenFromFile(filePath, 0) as IFeatureWorkspace;
                    //    IFeatureClass pFeatureClass = pFWS.OpenFeatureClass(fileName);
                    //    IDataset pDataset = pFeatureClass as IDataset;
                    //    pDataset.Delete();
                    //}
                    //else
                    //    return;

                    IFeatureClass pFeatureClass = pFWS.OpenFeatureClass(fileName);
                    IDataset pDataset = pFeatureClass as IDataset;
                    pDataset.Delete();
                }

                //创建shp
                IFields pFields = new FieldsClass();
                IFieldsEdit pFieldsEdit;
                pFieldsEdit = (IFieldsEdit)pFields;

                //shape字段是要素类必需的字段
                IField pField = new FieldClass();
                IFieldEdit pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Name_2 = "Shape";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                IGeometryDef pGeometryDef = new GeometryDefClass();
                IGeometryDefEdit pGDefEdit = (IGeometryDefEdit)pGeometryDef;
                pGDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                pFieldEdit.GeometryDef_2 = pGeometryDef;
                pFieldsEdit.AddField(pField);

                //添加shape字段
                pField = new FieldClass();
                pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Length_2 = 30;
                pFieldEdit.Name_2 = "img_number";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                pFieldsEdit.AddField(pField);

                pField = new FieldClass();
                pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Length_2 = 30;
                pFieldEdit.Name_2 = "center_x";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                pFieldsEdit.AddField(pField);

                pField = new FieldClass();
                pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Length_2 = 30;
                pFieldEdit.Name_2 = "center_y";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                pFieldsEdit.AddField(pField);

                IFeatureClass pFClass;
                pFClass = pFWS.CreateFeatureClass(fileName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

                //点状shape文件
                int pindex = 0;
                pindex = savepointpath.LastIndexOf("\\");
                string pfilePath = savepointpath.Substring(0, pindex);
                string pfileName = savepointpath.Substring(pindex + 1, savepointpath.Length - pindex - 1);

                IWorkspaceFactory ppWSF = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace ppFWS = (IFeatureWorkspace)ppWSF.OpenFromFile(pfilePath, 0);
                //检查文件是否存在
                if (System.IO.File.Exists(savepointpath))
                {
                    IFeatureClass ppFeatureClass = ppFWS.OpenFeatureClass(pfileName);
                    IDataset ppDataset = ppFeatureClass as IDataset;
                    ppDataset.Delete();
                }
                //创建shp
                IFields ppFields = new FieldsClass();
                IFieldsEdit ppFieldsEdit;
                ppFieldsEdit = (IFieldsEdit)ppFields;

                //shape字段是要素类必需的字段
                IField ppField = new FieldClass();
                IFieldEdit ppFieldEdit = (IFieldEdit)ppField;
                ppFieldEdit.Name_2 = "Shape";
                ppFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                IGeometryDef ppGeometryDef = new GeometryDefClass();
                IGeometryDefEdit ppGDefEdit = (IGeometryDefEdit)ppGeometryDef;
                ppGDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                ppFieldEdit.GeometryDef_2 = ppGeometryDef;
                ppFieldsEdit.AddField(ppField);

                //添加shape字段
                ppField = new FieldClass();
                ppFieldEdit = (IFieldEdit)ppField;
                ppFieldEdit.Length_2 = 30;
                ppFieldEdit.Name_2 = "number";
                ppFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                ppFieldsEdit.AddField(ppField);

                ppField = new FieldClass();
                ppFieldEdit = (IFieldEdit)ppField;
                ppFieldEdit.Length_2 = 30;
                ppFieldEdit.Name_2 = "x";
                ppFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                ppFieldsEdit.AddField(ppField);

                ppField = new FieldClass();
                ppFieldEdit = (IFieldEdit)ppField;
                ppFieldEdit.Length_2 = 30;
                ppFieldEdit.Name_2 = "y";
                ppFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                ppFieldsEdit.AddField(ppField);

                IFeatureClass ppFClass;
                ppFClass = ppFWS.CreateFeatureClass(pfileName, ppFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

                for (int i = 0; i < newparam.Count; i++)
                {
                    string imgnumber = "IMG_" + newparam[i][0];
                    double x = newparam[i][1];
                    double y = newparam[i][2];
                    double x1 = newparam[i][7];
                    double y1 = newparam[i][8];
                    double x2 = newparam[i][9];
                    double y2 = newparam[i][10];
                    double x3 = newparam[i][11];
                    double y3 = newparam[i][12];
                    double x4 = newparam[i][13];
                    double y4 = newparam[i][14];

                    //画面
                    IPoint pPoint;
                    //IElement pm = new PolygonElementClass();
                    IPointCollection pPoints=new PolygonClass();
                    object missing = Type.Missing;

                    pPoint = new PointClass();
                    pPoint.PutCoords(x1, y1);
                    pPoints.AddPoint(pPoint, ref missing, ref missing);

                    pPoint = new PointClass();
                    pPoint.PutCoords(x4, y4);
                    pPoints.AddPoint(pPoint, ref missing, ref missing);

                    pPoint = new PointClass();
                    pPoint.PutCoords(x3, y3);
                    pPoints.AddPoint(pPoint, ref missing, ref missing);

                    pPoint = new PointClass();
                    pPoint.PutCoords(x2, y2);
                    pPoints.AddPoint(pPoint, ref missing, ref missing);

                    pPoint = new PointClass();
                    pPoint.PutCoords(x1, y1);
                    pPoints.AddPoint(pPoint, ref missing, ref missing);

                    IFeature pFeature = pFClass.CreateFeature();
                    pFeature.Shape = pPoints as IPolygon;
                    pFeature.Store();

                    pFeature.set_Value(pFeature.Fields.FindField("img_number"), imgnumber);
                    pFeature.set_Value(pFeature.Fields.FindField("center_x"), x);
                    pFeature.set_Value(pFeature.Fields.FindField("center_y"), y);
                    pFeature.Store();

                    //画点
                   // IElement ppm = new MarkerElement();
                    pPoint = new PointClass();
                    pPoint.PutCoords(x, y);
                    pPoint.SpatialReference = spatialReference;
                    IFeature ppFeature = ppFClass.CreateFeature();
                    ppFeature.Shape = pPoint;
                    ppFeature.Store();

                    ppFeature.set_Value(ppFeature.Fields.FindField("number"), imgnumber);
                    ppFeature.set_Value(ppFeature.Fields.FindField("x"), x);
                    ppFeature.set_Value(ppFeature.Fields.FindField("y"), y);
                    ppFeature.Store();
                }
                IFeatureLayer pFeaturelayer = new FeatureLayerClass();
                pFeaturelayer.FeatureClass = pFClass;
                pFeaturelayer.Name = fileName;
                pFeaturelayer.SpatialReference = spatialReference;
                pmap.SpatialReference = spatialReference;
                pmap.AddLayer(pFeaturelayer);

                IFeatureLayer ppFeaturelayer = new FeatureLayerClass();
                ppFeaturelayer.FeatureClass = ppFClass;
                ppFeaturelayer.Name = pfileName;
                ppFeaturelayer.SpatialReference = spatialReference;
                pmap.AddLayer(ppFeaturelayer);

              // this.Close();

            }
            else
            {
                MessageBox.Show("请输入相关参数!");
                return;
            }
        }