Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        private void createFeatureClass()
        {
            string      ftClsPath = rsUtil.TempMosaicDir + "\\catBnd.shp";
            IFields     flds      = new FieldsClass();
            IFieldsEdit fldsE     = (IFieldsEdit)flds;
            IField      fld       = new FieldClass();
            IFieldEdit  fldE      = (IFieldEdit)fld;

            fldE.Name_2 = "catIndex";
            fldE.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            fldsE.AddField(fldE);
            ftCls = geoUtil.createFeatureClass(ftClsPath, fldsE, esriGeometryType.esriGeometryPolygon, sr);
            int catInd = ftCls.FindField("catIndex");
            int cnt    = 0;

            foreach (IRaster rs in inrs)
            {
                IFeature ftr = ftCls.CreateFeature();
                ftr.set_Value(catInd, cnt);
                IEnvelope        ext   = ((IRasterProps)rs).Extent;
                IPolygon         poly  = new PolygonClass();
                IPointCollection pColl = (IPointCollection)poly;
                pColl.AddPoint(ext.UpperLeft);
                pColl.AddPoint(ext.UpperRight);
                pColl.AddPoint(ext.LowerRight);
                pColl.AddPoint(ext.LowerLeft);
                poly.Close();
                ftr.Shape = poly;
                ftr.Store();
                cnt++;
            }
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 从坐标字符串得到范围Polygon
        /// </summary>
        /// <param name="strCoor">坐标字符串,格式为X@Y,以逗号分割</param>
        /// <returns></returns>
        public static IPolygon GetPolygonByCol(string strCoor)
        {
            try
            {
                object           after     = Type.Missing;
                object           before    = Type.Missing;
                IPolygon         polygon   = new PolygonClass();
                IPointCollection pPointCol = (IPointCollection)polygon;
                string[]         strTemp   = strCoor.Split(',');
                for (int index = 0; index < strTemp.Length; index++)
                {
                    string   CoorLine = strTemp[index];
                    string[] coors    = CoorLine.Split('@');

                    double X = Convert.ToDouble(coors[0]);
                    double Y = Convert.ToDouble(coors[1]);

                    IPoint pPoint = new PointClass();
                    pPoint.PutCoords(X, Y);
                    pPointCol.AddPoint(pPoint, ref before, ref after);
                }

                polygon = (IPolygon)pPointCol;
                polygon.Close();

                ITopologicalOperator pTopo = (ITopologicalOperator)polygon;
                pTopo.Simplify();

                return(polygon);
            }
            catch (Exception e)
            {
                //*******************************************************************
                //guozheng added
                if (ModData.SysLog != null)
                {
                    ModData.SysLog.Write(e, null, DateTime.Now);
                }
                else
                {
                    ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    ModData.SysLog.Write(e, null, DateTime.Now);
                }
                //********************************************************************

                return(null);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 从坐标字符串得到范围Polygon
        /// </summary>
        /// <param name="strCoor">坐标字符串,格式为X@Y,以逗号分割</param>
        /// <returns></returns>
        public static IPolygon GetPolygonByCol(string strCoor)
        {
            try
            {
                object           after     = Type.Missing;
                object           before    = Type.Missing;
                IPolygon         polygon   = new PolygonClass();
                IPointCollection pPointCol = (IPointCollection)polygon;
                string[]         strTemp   = strCoor.Split(',');
                for (int index = 0; index < strTemp.Length; index++)
                {
                    string   CoorLine = strTemp[index];
                    string[] coors    = CoorLine.Split('@');

                    double X = Convert.ToDouble(coors[0]);
                    double Y = Convert.ToDouble(coors[1]);

                    IPoint pPoint = new PointClass();
                    pPoint.PutCoords(X, Y);
                    pPointCol.AddPoint(pPoint, ref before, ref after);
                }

                polygon = (IPolygon)pPointCol;
                polygon.Close();

                if (IsValidateGeometry(polygon))
                {
                    return(polygon);
                }
                return(null);
            }
            catch (Exception eError)
            {
                //******************************************
                //guozheng added System Exception log
                if (SysCommon.Log.Module.SysLog == null)
                {
                    SysCommon.Log.Module.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                }
                SysCommon.Log.Module.SysLog.Write(eError);
                //******************************************
                return(null);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 由点坐标创建面对象
        /// </summary>
        /// <param name="pnts">点集合</param>
        /// <returns>返回的面对象</returns>
        public IPolygon CreatePolygonFromPnts(IList <IPoint> pnts, ISpatialReference spr)
        {
            IPolygon            polygon = new PolygonClass();
            INewPolygonFeedback fac     = new NewPolygonFeedbackClass();

            polygon.SpatialReference = spr;
            IPointCollection pntcols = polygon as IPointCollection;

            for (int i = 0; i < pnts.Count; i++)
            {
                pntcols.AddPoint(pnts[i]);
            }
            if (!polygon.IsClosed)
            {
                polygon.Close();
            }
            //polygon.Close();
            return(polygon);
        }
        /// <summary>
        /// 将分段添加对象到指定的图层
        /// </summary>
        /// <params name="hdpnts">对象的点串</params>
        /// <params name="hdid">对象Id</params>
        /// <params name="hdtype">对象类型(针对巷道)</params>
        /// <params name="hdlayer">添加对象图层</params>
        /// <params name="centpnts">中心线上的点串</params>
        //public void AddFDRegToLayer(List<IPoint> pnts0, List<IPoint> pnts1, List<IPoint> centpnts, Dictionary<string, string> sxzs, IFeatureLayer hdlayer, double hdwid)
        //{
        //    try
        //    {
        //        //int count = 0;
        //        //int num0 = pnts0.Count;
        //        //int num1 = pnts1.Count;
        //        //if (num0 == num1)
        //        //    count = num0;
        //        //else if (num0 > num1)
        //        //    count = num1;
        //        //else
        //        //    count = num0;
        //        //if (count > centpnts.Count)
        //        //    count = centpnts.Count;
        //        int count = pnts0.Count;
        //        //pnts1.Reverse();
        //        IFeatureClass Featureclass = hdlayer.FeatureClass;
        //        IWorkspaceEdit workspace = (IWorkspaceEdit)(Featureclass as IDataset).Workspace;
        //        workspace.StartEditing(false);
        //        workspace.StartEditOperation();
        //        //for (int i = 0; i < pnts0.Count-1; i++)
        //        for (int i = 0; i < count - 1; i++)
        //        {
        //            IPolygon polygon = new PolygonClass();
        //            polygon.SpatialReference = Global.spatialref;
        //            IPointCollection regpntcols = (IPointCollection)polygon;
        //            regpntcols.AddPoint(pnts0[i]);
        //            regpntcols.AddPoint(pnts0[i + 1]);
        //            regpntcols.AddPoint(pnts1[i + 1]);
        //            regpntcols.AddPoint(pnts1[i]);
        //            polygon.Close();
        //            //拓扑检查一下
        //            ITopologicalOperator4 tops = polygon as ITopologicalOperator4;
        //            if (!tops.IsSimple)
        //                tops.Simplify();
        //            //查询附近的巷道,确定Id的值,确定对应的符号
        //            IPolyline plincenter = new PolylineClass();
        //            plincenter.FromPoint = centpnts[i];
        //            plincenter.ToPoint = centpnts[i + 1];
        //            plincenter.SpatialReference = Global.spatialref;
        //            //int Idbs = Global.commonclss.SearchHdByLine(plincenter,sxzs["HdId"], Global.centerfdlyr);
        //            //获取巷道分段所包含中心线的xh值
        //            string sql = "\"" + GIS_Const.FIELD_HDID + "\"='" + sxzs[GIS_Const.FIELD_HDID] + "'";
        //            //int[] getAttr = GetCenterLineXH(polygon as IGeometry, sql, Global.centerfdlyr,hdwid);
        //            int[] getAttr = GetCenterLineXHNew(polygon as IGeometry, sql, Global.centerfdlyr, hdwid);
        //            int xh = getAttr[0];
        //            int Idbs = getAttr[1];
        //            //创建Feature
        //            IFeature fea = Featureclass.CreateFeature();
        //            int index = fea.Fields.FindField(GIS_Const.FIELD_SHAPE);
        //            if (index != -1)
        //            {
        //                IGeometryDef geometryDef = fea.Fields.get_Field(index).GeometryDef as IGeometryDef;
        //                if (geometryDef.HasZ)
        //                {
        //                    IZAware pZAware = (IZAware)polygon;
        //                    pZAware.ZAware = true;
        //                    fea.Shape = polygon;
        //                    foreach (string key in sxzs.Keys)
        //                    {
        //                        if (key == GIS_Const.FIELD_XH)
        //                        {
        //                            //int xh = Convert.ToInt16(sxzs[key]);
        //                            fea.set_Value(fea.Fields.FindField(key), xh);
        //                        }
        //                        else if (key == GIS_Const.FIELD_ID)
        //                        {
        //                            fea.set_Value(fea.Fields.FindField(key), Idbs);
        //                        }
        //                        else
        //                            fea.set_Value(fea.Fields.FindField(key), sxzs[key]);
        //                    }
        //                    fea.Store();
        //                }
        //                else
        //                {
        //                    fea.Shape = polygon;
        //                    foreach (string key in sxzs.Keys)
        //                    {
        //                        int fp = fea.Fields.FindField(key);
        //                        if (fp != -1)
        //                        {
        //                            if (key == GIS_Const.FIELD_XH)
        //                            {
        //                                //int xh = Convert.ToInt16(sxzs[key]);
        //                                fea.set_Value(fea.Fields.FindField(key), xh);
        //                            }
        //                            else if (key == GIS_Const.FIELD_ID)
        //                            {
        //                                fea.set_Value(fea.Fields.FindField(key), Idbs);
        //                            }
        //                            else
        //                                fea.set_Value(fea.Fields.FindField(key), sxzs[key]);
        //                        }
        //                    }
        //                    fea.Store();
        //                }
        //            }
        //        }
        //        workspace.StopEditOperation();
        //        workspace.StopEditing(true);
        //    }
        //    catch (Exception ei)
        //    {
        //        throw;
        //    }
        //    //}
        //    //catch (Exception ei)
        //    //{
        //    //    throw new Exception();
        //    //}
        //}
        public void AddFDRegToLayer_JC(List<IPoint> pnts0, List<IPoint> pnts1, List<IPoint> centpnts, Dictionary<string, string> sxzs, IFeatureLayer hdlayer, double hdwid)
        {
            try
            {
                //int count = 0;
                //int num0 = pnts0.Count;
                //int num1 = pnts1.Count;
                //if (num0 == num1)
                //    count = num0;
                //else if (num0 > num1)
                //    count = num1;
                //else
                //    count = num0;
                //if (count > centpnts.Count)
                //    count = centpnts.Count;
                int count = pnts0.Count;
                //pnts1.Reverse();

                IFeatureClass Featureclass = hdlayer.FeatureClass;
                IWorkspaceEdit workspace = (IWorkspaceEdit)(Featureclass as IDataset).Workspace;
                workspace.StartEditing(false);
                workspace.StartEditOperation();
                //for (int i = 0; i < pnts0.Count-1; i++)
                for (int i = 0; i < count - 1; i++)
                {
                    IPolygon polygon = new PolygonClass();
                    polygon.SpatialReference = Global.spatialref;
                    IPointCollection regpntcols = (IPointCollection)polygon;
                    regpntcols.AddPoint(pnts0[i]);
                    regpntcols.AddPoint(pnts0[i + 1]);
                    regpntcols.AddPoint(pnts1[i + 1]);
                    regpntcols.AddPoint(pnts1[i]);

                    polygon.Close();
                    //拓扑检查一下
                    ITopologicalOperator4 tops = polygon as ITopologicalOperator4;
                    if (!tops.IsSimple)
                        tops.Simplify();
                    //查询附近的巷道,确定Id的值,确定对应的符号
                    IPolyline plincenter = new PolylineClass();
                    plincenter.FromPoint = centpnts[i];
                    plincenter.ToPoint = centpnts[i + 1];
                    plincenter.SpatialReference = Global.spatialref;
                    //int Idbs = Global.commonclss.SearchHdByLine(plincenter,sxzs["HdId"], Global.centerfdlyr);
                    //获取巷道分段所包含中心线的xh值
                    string sql = "\"" + GIS.GIS_Const.FIELD_HDID + "\"='" + sxzs[GIS.GIS_Const.FIELD_HDID] + "'";
                    //int[] getAttr = GetCenterLineXH(polygon as IGeometry, sql, Global.centerfdlyr,hdwid);
                    int[] getAttr = GetCenterLineXHNew(polygon as IGeometry, sql, Global.centerfdlyr, hdwid);
                    int xh = getAttr[0];
                    int Idbs = getAttr[1];
                    //创建Feature
                    IFeature fea = Featureclass.CreateFeature();
                    int index = fea.Fields.FindField(GIS_Const.FIELD_SHAPE);
                    if (index != -1)
                    {
                        IGeometryDef geometryDef = fea.Fields.get_Field(index).GeometryDef as IGeometryDef;
                        if (geometryDef.HasZ)
                        {
                            IZAware pZAware = (IZAware)polygon;
                            pZAware.ZAware = true;
                            fea.Shape = polygon;
                            foreach (string key in sxzs.Keys)
                            {
                                if (key == GIS.GIS_Const.FIELD_XH)
                                {
                                    //int xh = Convert.ToInt16(sxzs[key]);
                                    fea.set_Value(fea.Fields.FindField(key), xh);
                                }
                                else if (key == GIS.GIS_Const.FIELD_ID)
                                {
                                    fea.set_Value(fea.Fields.FindField(key), Idbs);
                                }
                                else

                                    fea.set_Value(fea.Fields.FindField(key), sxzs[key]);
                            }
                            fea.Store();
                        }
                        else
                        {
                            fea.Shape = polygon;
                            foreach (string key in sxzs.Keys)
                            {
                                int fp = fea.Fields.FindField(key);
                                if (fp != -1)
                                {
                                    if (key == GIS.GIS_Const.FIELD_XH)
                                    {
                                        //int xh = Convert.ToInt16(sxzs[key]);
                                        fea.set_Value(fea.Fields.FindField(key), xh);
                                    }
                                    else if (key == GIS.GIS_Const.FIELD_ID)
                                    {
                                        fea.set_Value(fea.Fields.FindField(key), Idbs);
                                    }
                                    else

                                        fea.set_Value(fea.Fields.FindField(key), sxzs[key]);
                                }
                            }
                            fea.Store();
                        }
                    }
                }
                workspace.StopEditOperation();
                workspace.StopEditing(true);
            }
            catch (Exception ei)
            {
                throw;
            }

            //}
            //catch (Exception ei)
            //{
            //    throw new Exception();
            //}
        }
        /// <summary>
        /// 掘进巷道矫正
        /// </summary>
        /// <params name="HdId"></params>
        /// <params name="xzpnts"></params>
        /// <params name="jjcd"></params>
        /// <params name="jjfx"></params>
        /// <params name="search"></params>
        /// <params name="checkval"></params>
        /// <params name="jjbs">掘进标识</params>
        public void DrawJJJZ(string HdId, List<IPoint> xzpnts, double hdwid, double jjcd = 0, int jjfx = 0, double search = 0, double checkval = 0, int jjbs = 0)
        {
            List<IPoint> rightpts = null;
            List<IPoint> leftpts = null;
            List<IPoint> rightresults = null;
            List<IPoint> leftresults = null;
            List<IPoint> results = null;
            //int xh = 0;
            Dictionary<string, string> fldvals = new Dictionary<string, string>();
            fldvals.Add(GIS_Const.FIELD_HDID, HdId);
            //查询指定id的巷道对应的中心线(用于计算的分段显示的中心线)
            List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selobjs = Global.commonclss.SearchFeaturesByGeoAndText(Global.centerfdlyr, fldvals);
            if (selobjs.Count == 0)
            {
                MessageBox.Show("没有找到相应的巷道信息!", "系统提示");
                return;
            }
            int xh = Convert.ToInt16(selobjs[0].Item3[GIS_Const.FIELD_XH]);
            xh = xh + 1;
            Dictionary<string, string> fdlin_dics = new Dictionary<string, string>();
            fdlin_dics.Add(GIS_Const.FIELD_HDID, HdId);
            fdlin_dics.Add(GIS_Const.FIELD_XH, (xh).ToString());
            fdlin_dics.Add(GIS_Const.FIELD_ID, "0");
            fdlin_dics.Add(GIS_Const.FIELD_BS, "0");
            //计算延长点的坐标
            IGeometry geosel = selobjs[0].Item2;
            IPolyline plin = (IPolyline)geosel;
            if (jjbs == 1)//根据导线点精确定位的
            {
                //清除掘进信息
                string sql = "\"" + GIS_Const.FIELD_HDID + "\"='" + HdId + "' AND \"" + GIS_Const.FIELD_BS + "\"=0";
                Global.commonclss.DelFeatures(Global.pntlyr, sql);
                Global.commonclss.DelFeatures(Global.centerlyr, sql);
                Global.commonclss.DelFeatures(Global.centerfdlyr, sql);
                Global.commonclss.DelFeatures(Global.hdfdfulllyr, sql);
                Global.commonclss.DelFeatures(Global.hdfdlyr, sql);
                Global.pActiveView.Refresh();
                //构造点集合,用于构造线 面等
                selobjs = Global.commonclss.SearchFeaturesByGeoAndText(Global.centerfdlyr, fldvals);
                List<IPoint> dpts = new List<IPoint>();
                plin = (IPolyline)selobjs[0].Item2;
                dpts.Add(plin.ToPoint);
                dpts.AddRange(xzpnts);
                //
                Dictionary<string, string> fdlin_dics1 = new Dictionary<string, string>();
                fdlin_dics1.Add(GIS_Const.FIELD_HDID, HdId);
                fdlin_dics1.Add(GIS_Const.FIELD_XH, xh.ToString());
                fdlin_dics1.Add(GIS_Const.FIELD_ID, "0");
                fdlin_dics1.Add(GIS_Const.FIELD_BS, "1");
                AddHangdaoToLayer(dpts, fdlin_dics1, Global.pntlyr);//将导线点写到导线图层中
                AddDxdLines(xzpnts, fdlin_dics1, Global.pntlinlyr);
                AddFDLineToLayer(dpts, fdlin_dics1, Global.centerfdlyr, 1);//添加分段中心线到中心线图层
                //将线段添加到中心线全图层中
                List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selcenterlin = Global.commonclss.SearchFeaturesByGeoAndText(Global.centerlyr, fldvals);
                if (selcenterlin.Count > 0)
                {
                    IPolyline centerlin = selcenterlin[0].Item2 as IPolyline;
                    IFeature centerlinfea = selcenterlin[0].Item1;
                    IPointCollection centerlinpnts = centerlin as IPointCollection;

                    IPolyline centerlinnew = new PolylineClass();
                    centerlinnew.SpatialReference = Global.spatialref;
                    IPointCollection centerpnts = centerlinnew as IPointCollection;
                    centerpnts.AddPoint(centerlinpnts.get_Point(centerlinpnts.PointCount - 1));
                    for (int i = 0; i < xzpnts.Count; i++)
                    {
                        centerpnts.AddPoint(xzpnts[i]);
                    }
                    ITopologicalOperator4 toplogical = (ITopologicalOperator4)centerlinnew;
                    if (!toplogical.IsSimple)
                        toplogical.Simplify();
                    List<IGeometry> geos = new List<IGeometry>();
                    geos.Add(centerlinnew);
                    Global.commonclss.CreatePolygonFromExistingGeometries(Global.centerlyr, centerlinfea, geos);
                }
                //将校正的巷道断面添加到巷道分段面中
                List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selhdfd = Global.commonclss.SearchFeaturesByGeoAndText(Global.hdfdlyr, fldvals);
                if (selhdfd.Count > 0)
                {
                    IFeature hdfd_fea = selhdfd[0].Item1;
                    IPolygon hdfd_polygon = (IPolygon)selhdfd[0].Item2;
                    IPointCollection hdfd_cols = hdfd_polygon as IPointCollection;
                    //计算中心线的平行线这点坐标
                    List<IPoint> fddpts = new List<IPoint>();
                    fddpts.Add(plin.FromPoint);
                    fddpts.Add(plin.ToPoint);
                    for (int i = 0; i < xzpnts.Count; i++)
                    {
                        fddpts.Add(xzpnts[i]);
                    }
                    rightpts = Global.cons.GetLRParallelPnts(fddpts, hdwid, 1);//右侧平行线上的端点串
                    leftpts = Global.cons.GetLRParallelPnts(fddpts, hdwid, 0); //左侧平行线上的端点串
                    //rightresults = Global.cons.CalculateRegPnts(rightpts);
                    //leftresults = Global.cons.CalculateRegPnts(leftpts);
                    //results = Global.cons.ConstructPnts(rightresults, leftresults);
                    rightpts.Reverse();
                    leftpts.Reverse();
                    results = Global.cons.ConstructPnts(rightpts, leftpts);

                    IFeatureClass Featureclass = Global.hdfdlyr.FeatureClass;
                    IWorkspaceEdit workspace = (IWorkspaceEdit)(Featureclass as IDataset).Workspace;
                    workspace.StartEditing(false);
                    workspace.StartEditOperation();
                    //leftpts.Reverse();

                    IPolygon polygon = new PolygonClass();
                    polygon.SpatialReference = Global.spatialref;
                    IPointCollection regpntcols = (IPointCollection)polygon;
                    regpntcols.AddPoint(rightpts[0]);
                    regpntcols.AddPoint(rightpts[1]);
                    regpntcols.AddPoint(leftpts[0]);
                    regpntcols.AddPoint(leftpts[1]);
                    polygon.Close();

                    //拓扑检查一下
                    ITopologicalOperator4 tops = polygon as ITopologicalOperator4;
                    if (!tops.IsSimple)
                        tops.Simplify();
                    hdfd_fea.Shape = polygon as IGeometry;
                    hdfd_fea.Store();
                    workspace.StopEditOperation();
                    workspace.StopEditing(true);
                    //AddRegToLayer(results, fdlin_dics1, Global.hdfdlyr);
                    //rightpts.RemoveAt(0);
                    //leftpts.RemoveAt(0);
                    //leftpts.Reverse();
                    AddFDRegToLayer(rightpts, leftpts, fddpts, fdlin_dics1, Global.hdfdlyr, hdwid);
                }
                //更新巷道面全图层
                List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selhdfull = Global.commonclss.SearchFeaturesByGeoAndText(Global.hdfdfulllyr, fldvals);
                if (selhdfull.Count > 0)
                {
                    IFeature hdfull_fea = selhdfull[0].Item1;
                    //IPolygon hdfull_polygon = (IPolygon)selhdfull[0].Item2;
                    //IPointCollection hdfull_cols = hdfull_polygon as IPointCollection;
                    //List<IPoint> hdfull_colsnew = new List<IPoint>();
                    //int pos = hdfull_cols.PointCount / 2;
                    //hdfull_cols.UpdatePoint(pos - 1, rightresults[1]);
                    //hdfull_cols.UpdatePoint(pos, leftresults[1]);
                    //Global.commonclss.UpdateFeature(Global.hdfdfulllyr, hdfull_fea, fdlin_dics1, hdfull_polygon);
                    IPolygon polygonsurplus = new PolygonClass();
                    polygonsurplus.SpatialReference = Global.spatialref;
                    polygonsurplus = Global.commonclss.CreatePolygonFromPnts(results, Global.spatialref);
                    //IGeometry polygonres = new PolygonClass();
                    //polygonres.SpatialReference = Global.spatialref;
                    //ITopologicalOperator topsurplus = hdfull_polygon as ITopologicalOperator;
                    //if (!topsurplus.IsSimple)
                    //    topsurplus.Simplify();
                    //ITopologicalOperator4 tops = polygonsurplus as ITopologicalOperator4;
                    //if (!tops.IsSimple)
                    //    tops.Simplify();
                    List<IGeometry> geos1 = new List<IGeometry>();
                    geos1.Add(polygonsurplus);
                    Global.commonclss.CreatePolygonFromExistingGeometries(Global.hdfdfulllyr, hdfull_fea, geos1);

                    //IPolygon polygonsurplus = new PolygonClass();
                    //polygonsurplus.SpatialReference = Global.spatialref;
                    //polygonsurplus = Global.commonclss.CreatePolygonFromPnts(results, Global.spatialref);
                    //geos1.Add(polygonsurplus);

                    //ITopologicalOperator4 tops = polygonsurplus as ITopologicalOperator4;
                    //if (!tops.IsSimple)
                    //    tops.Simplify();
                    //Global.commonclss.UpdateFeature(Global.hdfdfulllyr, hdfull_fea, fdlin_dics1, polygonsurplus);
                }
            }
        }
        private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)      //地图移动
        {
            if (axMapControl1.LayerCount == 0)
            {
                return;
            }
            sMapUnits = "千米";//GetMapUnit(axMapControl1.Map.MapUnits);  //求量测所需的单位
            #region 状态栏
            //就绪


            //比例尺
            labelItem2.Text = " 比例尺 1:" + ((long)this.axMapControl1.MapScale).ToString();
            //坐标
            lbl_Coordinate.Text = "当前坐标:X:" + e.mapX.ToString() + " Y: " + e.mapY.ToString();
            #endregion

            pMovePt = (axMapControl1.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
            #region 长度量算
            if (pMouseOperate == "MeasureLength")
            {
                if (pNewLineFeedback != null)
                {
                    pNewLineFeedback.MoveTo(pMovePt);
                }
                double deltaX = 0; //两点之间X差值
                double deltaY = 0; //两点之间Y差值

                if ((pPointPt != null) && (pNewLineFeedback != null))
                {
                    deltaX         = pMovePt.X - pPointPt.X;
                    deltaY         = pMovePt.Y - pPointPt.Y;
                    dSegmentLength = Math.Round(111.199 * (Math.Sqrt((deltaY * deltaY) + (deltaX * deltaX) * (Math.Cos((pPointPt.Y + pMovePt.Y) / 2) * Math.Cos((pPointPt.Y + pMovePt.Y) / 2)))), 3);
                    dToltalLength  = dToltalLength + dSegmentLength;
                    if (frmMeasureResult != null)
                    {
                        frmMeasureResult.lblMeasureResult.Text = String.Format(
                            "当前量测的距离为:{0:.###}{1};\r\n总长度为: {2:.###}{1}",
                            dSegmentLength, sMapUnits, dToltalLength);
                        dToltalLength = dToltalLength - dSegmentLength; //鼠标移动到新点重新开始计算
                    }
                    frmMeasureResult.frmClosed += new FrmMeasureResult.FrmClosedEventHandler(frmMeasureResult_frmColsed);
                }
            }
            #endregion
            #region 面积量算
            if (pMouseOperate == "MeasureArea")
            {
                if (pNewPolygonFeedback != null)
                {
                    pNewPolygonFeedback.MoveTo(pMovePt);
                }

                IPointCollection pPointCol = new Polygon();
                IPolygon         pPolygon  = new PolygonClass();
                IGeometry        pGeo      = null;

                ITopologicalOperator pTopo = null;
                for (int i = 0; i <= pAreaPointCol.PointCount - 1; i++)
                {
                    pPointCol.AddPoint(pAreaPointCol.get_Point(i), ref missing, ref missing);
                }
                pPointCol.AddPoint(pMovePt, ref missing, ref missing);

                if (pPointCol.PointCount < 3)
                {
                    return;
                }
                pPolygon = pPointCol as IPolygon;

                if ((pPolygon != null))
                {
                    pPolygon.Close();
                    pGeo  = pPolygon as IGeometry;
                    pTopo = pGeo as ITopologicalOperator;
                    //使几何图形的拓扑正确
                    pTopo.Simplify();
                    pGeo.Project(axMapControl1.Map.SpatialReference);
                    IArea pArea = pGeo as IArea;

                    frmMeasureResult.lblMeasureResult.Text = String.Format(
                        "总面积为:{0:.####}平方{1};\r\n总长度为:{2:.####}{1}",
                        pArea.Area, sMapUnits, pPolygon.Length);
                    pPolygon = null;
                }
            }
            #endregion
            #region 移动显示名称
            IFeatureLayer pFeatureLayer8 = axMapControl1.Map.get_Layer(0) as IFeatureLayer; //定位的图层包括了很多要素
            pFeatureLayer8.DisplayField = "name";
            pFeatureLayer8.ShowTips     = true;
            string pTip8;
            pTip8 = pFeatureLayer8.get_TipText(e.mapX, e.mapY, axMapControl1.ActiveView.FullExtent.Width / 1000);
            if (pTip8 != null && pTip8 != " ")
            {
                toolTip1.SetToolTip(axMapControl1, "这里是:" + pTip8);
            }
            else
            {
                toolTip1.SetToolTip(axMapControl1, "");
            }
            #endregion
        }
Esempio n. 10
0
        public static void CreateFCs(IWorkspace pWs, IMap pMap)
        {
            var FC1 = CreateFeatureClass(pWs, null, "Point", CreateFields(esriGeometryType.esriGeometryPoint));
            var FC2 = CreateFeatureClass(pWs, null, "Line", CreateFields(esriGeometryType.esriGeometryPolyline));
            var FC3 = CreateFeatureClass(pWs, null, "Polygon", CreateFields(esriGeometryType.esriGeometryPolygon));

            //insert& show
            List <IGeometry> ptList = new List <IGeometry>(100);
            IPoint           pt;

            for (int i = 0; i < 1000; i++)
            {
                pt = new PointClass();
                pt.PutCoords(i * 0.01, i * 0.01);
                ptList.Add(pt);
            }

            List <IGeometry> lineList = new List <IGeometry>(100);
            IPolyline        pLine;
            IPoint           pt1, pt2;

            for (int i = 0; i < 1000; i++)
            {
                pLine = new PolylineClass();
                pt1   = new PointClass();
                pt1.PutCoords(i * 0.01, (i + 1) * 0.01);
                pt2 = new PointClass();
                pt2.PutCoords(i * 0.01, (i + 11) * 0.01);
                pLine.FromPoint = pt1;
                pLine.ToPoint   = pt2;
                lineList.Add(pLine);
            }

            List <IGeometry> polygonList = new List <IGeometry>(100);
            IPolygon         pPolygon;
            IPoint           pt3, pt4;

            for (int i = 0; i < 1000; i++)
            {
                pPolygon = new PolygonClass();
                IPointCollection ptColl = pPolygon as IPointCollection;
                pt1 = new PointClass();
                pt1.PutCoords(i * 0.01, (i - 2) * 0.01);
                pt2 = new PointClass();
                pt2.PutCoords((i + 1) * 0.01, (i - 2) * 0.01);
                pt3 = new PointClass();
                pt3.PutCoords((i + 1) * 0.01, (i - 3) * 0.01);
                pt4 = new PointClass();
                pt4.PutCoords(i * 0.01, (i - 3) * 0.01);
                ptColl.AddPoint(pt1);
                ptColl.AddPoint(pt2);
                ptColl.AddPoint(pt3);
                ptColl.AddPoint(pt4);
                pPolygon.Close();
                polygonList.Add(pPolygon);
            }

            InsertFeaturesUsingCursor(FC1, ptList);
            InsertFeaturesUsingCursor(FC2, lineList);
            InsertFeaturesUsingCursor(FC3, polygonList);

            IFeatureLayer pFeaturelayer = new FeatureLayerClass();

            pFeaturelayer.Name         = "pt";
            pFeaturelayer.FeatureClass = FC1;
            pMap.AddLayer(pFeaturelayer);
            pFeaturelayer              = new FeatureLayerClass();
            pFeaturelayer.Name         = "line";
            pFeaturelayer.FeatureClass = FC2;
            pMap.AddLayer(pFeaturelayer);
            pFeaturelayer              = new FeatureLayerClass();
            pFeaturelayer.Name         = "polygon";
            pFeaturelayer.FeatureClass = FC3;
            pMap.AddLayer(pFeaturelayer);
        }
Esempio n. 11
0
        private IPolygon ContructGeometry(out PolygonClass polygon1)
        {
            polygon1 = new PolygonClass();
            var polygon = new PolygonClass();
            var p00 = ConstructPoint(_centerPoint, Angle0, Angle1, _height4, 0);
            var p01 = ConstructPoint(_centerPoint, Angle2, Angle1, _height4);
            var p04 = ConstructPoint(_centerPoint, Angle0, Angle1, _height4);

            var list0 = new List<IPoint>
            {
                p01,
                ConstructPoint2(p01, Angle3, p00, Angle2 - Angle3),
                ConstructPoint2(p00, -Angle3, p04, Angle2 + Angle3),
                p04,
                ConstructPoint(_centerPoint, Angle0, Angle1, _height3),
                ConstructPoint(_centerPoint, Angle2, Angle1, _height3),
                p01
            };

            polygon1.AddGeometry(ConstructRing(list0));

            var list1 = new List<IPoint>
            {
                p00,
                ConstructPoint2(p00, Angle3, p04, Angle2 - Angle3),
                p04,
                ConstructPoint2(p00, -Angle3, p04, Angle2 + Angle3),
                p00
            };

            polygon.AddGeometry(ConstructRing(list1));

            var list2 = new List<IPoint>
            {
                ConstructPoint(_centerPoint, Angle2, Angle1, _height3),
                ConstructPoint(_centerPoint, Angle0, Angle1, _height3),
                ConstructPoint(_centerPoint, Angle0, Angle1, _halfHeight),
                ConstructPoint(_centerPoint, Angle2, Angle1, _halfHeight),
                ConstructPoint(_centerPoint, Angle2, Angle1, _height3)
            };

            polygon.AddGeometry(ConstructRing(list2));

            var list3 = new List<IPoint>
            {
                ConstructPoint(_centerPoint, Angle2, -Angle1, _height3),
                ConstructPoint(_centerPoint, Angle0, -Angle1, _height3),
                ConstructPoint(_centerPoint, Angle0, -Angle1, _halfHeight),
                ConstructPoint(_centerPoint, Angle2, -Angle1, _halfHeight),
                ConstructPoint(_centerPoint, Angle2, -Angle1, _height3)
            };

            polygon.AddGeometry(ConstructRing(list3));

            var p20 = ConstructPoint(_centerPoint, Angle0, -Angle1, _height4, 0);
            var p21 = ConstructPoint(_centerPoint, Angle2, -Angle1, _height4);
            var p24 = ConstructPoint(_centerPoint, Angle0, -Angle1, _height4);

            var list4 = new List<IPoint>
            {
                p21,
                ConstructPoint2(p21, Angle3, p20, Angle2 - Angle3),
                ConstructPoint2(p20, -Angle3, p24, Angle2 + Angle3),
                p24,
                ConstructPoint(_centerPoint, Angle0, -Angle1, _height3),
                ConstructPoint(_centerPoint, Angle2, -Angle1, _height3),
                p21
            };

            polygon1.AddGeometry(ConstructRing(list4));

            var list5 = new List<IPoint>
            {
                p20,
                ConstructPoint2(p20, Angle2 - Angle3, p21, Angle3),
                p21,
                ConstructPoint2(p20, Angle2 + Angle3, p21, -Angle3),
                p20
            };

            polygon.AddGeometry(ConstructRing(list5));
            polygon.Close();

            return polygon;
        }
Esempio n. 12
0
        private void axMapControl_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
        {
            sMapUnits = Utils.MapUtils.GetMapUnit(axMapControl.Map.MapUnits);
            StatusBarInfoSet(String.Format("当前坐标:X = {0:#.######} Y = {1:#.######} {2}", e.mapX, e.mapY, sMapUnits));
            pMovePt = (axMapControl.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

            if (!ApplicationV.IsBanFormMainMapClick)
            {
                #region 长度量算
                if (pMouseOperate == "MeasureLength")
                {
                    if (pNewLineFeedback != null)
                    {
                        pNewLineFeedback.MoveTo(pMovePt);
                    }
                    double deltaX = 0; //两点之间X差值
                    double deltaY = 0; //两点之间Y差值

                    if ((pPointPt != null) && (pNewLineFeedback != null))
                    {
                        deltaX         = pMovePt.X - pPointPt.X;
                        deltaY         = pMovePt.Y - pPointPt.Y;
                        dSegmentLength = Math.Round(Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY)), 3);
                        dToltalLength  = dToltalLength + dSegmentLength;
                        if (frmMeasureResult != null)
                        {
                            frmMeasureResult.lblMeasureResult.Text = String.Format(
                                "当前线段长度:{0} ({1});\r\n总长度为:{2} ({1})",
                                dSegmentLength.ToString("f6"), sMapUnits, dToltalLength.ToString("f6"));
                            dToltalLength = dToltalLength - dSegmentLength; //鼠标移动到新点重新开始计算
                        }
                        frmMeasureResult.frmClosed += new FormMeasureResult.FormMeasureResult.FormClosedEventHandler(frmMeasureResult_frmColsed);
                    }
                }
                #endregion

                #region 面积量算
                if (pMouseOperate == "MeasureArea")
                {
                    if (pNewPolygonFeedback != null)
                    {
                        pNewPolygonFeedback.MoveTo(pMovePt);
                    }

                    IPointCollection pPointCol = new Polygon();
                    IPolygon         pPolygon  = new PolygonClass();
                    IGeometry        pGeo      = null;

                    ITopologicalOperator pTopo = null;
                    for (int i = 0; i <= pAreaPointCol.PointCount - 1; i++)
                    {
                        pPointCol.AddPoint(pAreaPointCol.get_Point(i), ref missing, ref missing);
                    }
                    pPointCol.AddPoint(pMovePt, ref missing, ref missing);

                    if (pPointCol.PointCount < 3)
                    {
                        return;
                    }
                    pPolygon = pPointCol as IPolygon;

                    if ((pPolygon != null))
                    {
                        pPolygon.Close();
                        pGeo  = pPolygon as IGeometry;
                        pTopo = pGeo as ITopologicalOperator;
                        //使几何图形的拓扑正确
                        pTopo.Simplify();
                        pGeo.Project(axMapControl.Map.SpatialReference);
                        IArea pArea = pGeo as IArea;

                        frmMeasureResult.lblMeasureResult.Text = String.Format(
                            "总面积为:{0} (平方{1});\r\n总长度为:{2} ({1})",
                            pArea.Area.ToString("F7"), sMapUnits, pPolygon.Length.ToString("F7"));
                        pPolygon = null;
                    }
                }
                #endregion
            }
        }
Esempio n. 13
0
        public override int Execute(string logfileName)
        {
            this.InitLogging(logfileName);
            this.LogMessage(this.Name + " QA test execution started.");

            int currentOid = -1;
            bool bProblemsRunning = false;

            try
            {
                this.LogMessage(this.Name + " Parameters:");
                for (int i = 0; i < this.ParameterCount; i++)
                    this.LogMessage(this.get_ParameterText(i) + ": " + this.get_ParameterValue(i));

                this.ClearErrors();

                int index = this.FindParameter(ParameterInfo.PARAM_CANDEFER);
                bool canDefer = (bool)((ParameterInfo)this._params[index]).ParamValue;
                index = this.FindParameter(ParameterInfo.PARAM_CANEXCEPT);
                bool canExcept = (bool)((ParameterInfo)this._params[index]).ParamValue;

                if (canDefer || canExcept)
                {
                    this.LogMessage("Errors found by " + this.Name + " cannot be deferred or excepted.");
                }

                IFeatureLayer theSeeLayer = this.SEELayer;
                if (theSeeLayer == null)
                {
                    this.LogMessage("Missing SEE layer. Exiting Execute.");
                    bProblemsRunning = true;
                }
                else if (this._eDao == null)
                {
                    this.LogMessage("Missing Edits Data Access Object. Exiting Execute.");
                    bProblemsRunning = true;
                }
                //else if (this._tmConfig == null)
                //{
                //    this.LogMessage("Missing Transaction Config object. Exiting Execute.");
                //    bProblemsRunning = true;
                //}
                else
                {
                    // Select the SEE polygon
                    string theTxID = this.TxID;
                    IQueryFilter theQF = new QueryFilterClass();
                    theQF.WhereClause = SEE_ID_FIELD_NAME + " = '" + theTxID + "'";
                    IFeatureCursor theFCursor = theSeeLayer.Search(theQF, false);
                    IFeature theSee = theFCursor.NextFeature();
                    Marshal.ReleaseComObject(theFCursor);
                    theFCursor = null;

                    if (theSee == null)
                    {
                        this.LogMessage("Could not find SEE feature with id " + theTxID + ". Exiting Execute.");
                        bProblemsRunning = true;
                    }
                    else if (theSee.Shape == null || theSee.Shape.IsEmpty)
                    {
                        this.LogMessage("The SEE feature with id " + theTxID + " does not have a valid shape. Exiting Execute.");
                        bProblemsRunning = true;
                    }
                    else
                    {
                        ISegmentCollection theSColl = (ISegmentCollection)this.ShapeCopy(theSee);
                        IPolygon theSeeBounds = new PolygonClass();
                        ((ISegmentCollection)theSeeBounds).AddSegmentCollection(theSColl);
                        theSeeBounds.Close();

                        // Convert shift limit to metres
                        DoubleParameterInfo theParam = (DoubleParameterInfo)this._params[this.FindParameter("ignore-shift-smaller-than")];
                        double shiftLimit = (double)theParam.ParamValue;
                        UnitsParameterInfo theUnits = (UnitsParameterInfo)this._params[this.FindParameter("shift-units")];
                        IUnitConverter theConverter = new UnitConverterClass();
                        shiftLimit = theConverter.ConvertUnits(shiftLimit, theUnits.ParamValueInUnits, esriUnits.esriMeters);

                        for (int i = 0; i < this.LayerCount; i++)
                        {
                            IFeatureLayer theFLayer = this.get_Layer(i);
                             if (this.SupportsGeometryType(theFLayer.FeatureClass.ShapeType) == false)
                            {
                                this.LogMessage("Geometry type " + theFLayer.FeatureClass.ShapeType + " of layer " + theFLayer.Name + " not supported by " + this.Name);
                                continue;
                            }

                            if (theFLayer == theSeeLayer)
                                continue;

                            string theLayerKey = ((IDataset)theFLayer.FeatureClass).Name;
                            if (theLayerKey == null)
                            {
                                this.LogMessage("Could not find TM layer key for layer " + theFLayer.Name + " passed to " + this.Name);
                                bProblemsRunning = true;
                                break;
                            }

                            IFeatureClass theEditsFC = this.SiblingFClassWithName(i, "E_" + theLayerKey);
                            if (theEditsFC == null)
                                this.LogMessage("Could not find TM edits featureclass for layer " + theFLayer.Name + " passed to " + this.Name);
                            IFeatureClass thePristineFC = this.SiblingFClassWithName(i, "P_" + theLayerKey);
                            if (thePristineFC == null)
                                this.LogMessage("Could not find TM pristine featureclass for layer " + theFLayer.Name + " passed to " + this.Name);

                            if (theEditsFC == null || thePristineFC == null)
                            {
                                bProblemsRunning = true;
                                break;
                            }

                            if (this.ProcessLayer(theLayerKey, theFLayer.FeatureClass, theEditsFC, thePristineFC, theSeeBounds, shiftLimit) == false)
                            {
                                bProblemsRunning = true;
                                break;
                            }
                        }
                    }
                }

                this.LogMessage("Number of errors found: " + this.ErrorCount);
                if (!bProblemsRunning)
                    this.LogMessage("Test " + this.Name + " successful.");
            }
            catch (Exception ex)
            {
                this.LogMessage("Exception caught: \n" + ex.Message + "\n" + ex.StackTrace.ToString());
                this.LogMessage("id of the current polygon: " + currentOid);
                return -1;
            }
            finally
            {
                this.StopLogging();
            }

            if (bProblemsRunning)
                return -1;

            return this.ErrorCount;
        }
Esempio n. 14
0
        public void ContructGeometry(IPoint point, List <KeyValuePair <int, double> > datasources, out List <KeyValuePair <string, IPolygon> > polygons, out List <IPoint> lineStartPoints, out List <IPoint> txtPoints)
        {
            _centerPoint = new PointClass {
                X = point.X, Y = point.Y
            };
            polygons = new List <KeyValuePair <string, IPolygon> >();

            lineStartPoints = new List <IPoint>();
            txtPoints       = new List <IPoint>();

            var polygonBlack = new PolygonClass();
            var polygonWhite = new PolygonClass();

            _linepoints = lineStartPoints;
            _points     = txtPoints;

            var indexLine   = 0;
            var length      = datasources.Sum(s => s.Value) * BL;
            var totalLength = length / 2;

            _halfHeight = length / 2;
            _height3    = _halfHeight + GeometryHeight1;
            _height4    = _halfHeight + GeometryHeight0 + GeometryHeight1;
            IPoint lastFromPoint = null;

            //IPoint lastToPoint = null;

            foreach (var d in datasources)
            {
                double dd     = d.Value * BL;
                var    list30 = new List <IPoint>
                {
                    ConstructPoint(_centerPoint, 180, 90, totalLength),
                    ConstructPoint(_centerPoint, 0, 90, totalLength),
                    ConstructPoint(_centerPoint, 0, 90, totalLength - dd),
                    ConstructPoint(_centerPoint, 180, 90, totalLength - dd),
                    ConstructPoint(_centerPoint, 180, 90, totalLength)
                };

                //  生成面
                var geometry = ConstructRing(list30);

                if (d.Key == 0)
                {
                    polygonWhite.AddGeometry(geometry);
                }
                else
                {
                    polygonBlack.AddGeometry(geometry);
                }

                //int angleLine = indexLine % 2 == 0 ? 0 : 180;

                var fromPoint = list30[indexLine % 2 + 2];
                //var toPoint = ConstructPoint3(fromPoint, angleLine, LineWidth);

                //  生成线
                _linepoints.Add(fromPoint);

                lastFromPoint = list30[3];
                //lastToPoint = ConstructPoint3(lastFromPoint, Angle2, LineWidth * 2);

                var txtPoint = new PointClass();
                txtPoint.ConstructAngleDistance(fromPoint, (TextOffsetAngle + indexLine % 2 * 180) * Deg2Rad, TextOffsetDistance);

                //  生成点
                _points.Add(txtPoint);

                totalLength -= dd;
                indexLine++;
            }

            if (lastFromPoint != null)
            {
                var txtLastPoint = new PointClass();
                txtLastPoint.ConstructAngleDistance(lastFromPoint, 180 * Deg2Rad, LastTextOffsetDistance);

                //  生成点
                _points.Add(txtLastPoint);
                //  生成线
                _linepoints.Add(lastFromPoint);
            }


            polygonWhite.Close();
            polygonBlack.Close();
            var tPolygon = new PolygonClass();

            polygons.Add(new KeyValuePair <string, IPolygon>("top", ContructGeometry(out tPolygon)));
            polygons.Add(new KeyValuePair <string, IPolygon>("top", tPolygon));
            polygons.Add(new KeyValuePair <string, IPolygon>("white", polygonWhite));
            polygons.Add(new KeyValuePair <string, IPolygon>("black", polygonBlack));
        }
Esempio n. 15
0
        private IPolygon CreateBox(IPoint centre, double orientation, double size, esriUnits units)
        {
            // Orientation is in degrees from east, counterclockwise
            // First point in the polygon will be on a face, at the orientation point
            // Four points on the corners will be at sqrt(2) * size,
            // at orientation+45, orientation+135, orientation+225 and orientation+315
            ISDUTExtension theExt = this.Extension;
            IPolygon theBox = new PolygonClass();

            ISpatialReference theWorkingReference = theExt.FocusMap.SpatialReference;
            theBox.SpatialReference = theWorkingReference;
            esriUnits theWorkingUnits = esriUnits.esriMeters;

            UnitConverter theConverter = new UnitConverterClass();
            double theSize = theConverter.ConvertUnits(size, units, theWorkingUnits);
            double theCornerDistance = Math.Sqrt(2) * theSize;

            IPoint theCentroid = this._Wellsite;
            theCentroid.Project(theWorkingReference);
            Debug.WriteLine("Box centroid X: " + theCentroid.X + "  Y: " + theCentroid.Y);

            IPointCollection thePtColl = (IPointCollection)theBox;
            object theMissing = Type.Missing;

            // Place the first point
            IPoint thePoint = new PointClass();
            thePoint.SpatialReference = theWorkingReference;
            double theAngle = orientation * Math.PI / 180;
            ((IConstructPoint2)thePoint).ConstructAngleDistance(theCentroid, theAngle, theSize);
            Debug.WriteLine("    First point X: " + thePoint.X + "  Y: " + thePoint.Y);
            thePtColl.AddPoint(thePoint, ref theMissing, ref theMissing);

            // Place the corners
            for (int i = 1; i <= 4; i++)
            {
                thePoint = new PointClass();
                thePoint.SpatialReference = theWorkingReference;
                theAngle =  (orientation - 45 + (i * 90)) * Math.PI / 180;
                ((IConstructPoint2)thePoint).ConstructAngleDistance(theCentroid, theAngle, theCornerDistance);
                Debug.WriteLine("    Corner " + i + " X: " + thePoint.X + "  Y: " + thePoint.Y);
                thePtColl.AddPoint(thePoint, ref theMissing, ref theMissing);
            }

            theBox.Close();
            return theBox;
        }
Esempio n. 16
0
        public IElement CreateJionTab(IActiveView iactiveView_0, IPoint ipoint_0)
        {
            IGroupElement element = new GroupElementClass();

            (element as IElementProperties).Name = "接图表";
            (element as IElementProperties).Type = "接图表";
            new PointClass();
            new TextElementClass();
            new TextElementClass();
            new TextElementClass();
            new TextElementClass();
            new TextElementClass();
            new TextElementClass();
            new TextElementClass();
            new TextElementClass();
            ILineElement     element2  = null;
            ILineSymbol      symbol    = null;
            double           num       = this.double_1 / 3.0;
            double           num2      = this.double_0 / 3.0;
            double           num3      = 0.3;
            object           missing   = Type.Missing;
            IElement         element3  = new LineElementClass();
            IElement         element4  = new LineElementClass();
            IElement         element5  = new LineElementClass();
            IElement         element6  = new LineElementClass();
            IElement         element7  = new LineElementClass();
            IPolyline        polyline  = new PolylineClass();
            IPolyline        polyline2 = new PolylineClass();
            IPolyline        polyline3 = new PolylineClass();
            IPolyline        polyline4 = new PolylineClass();
            IPolyline        polyline5 = new PolylineClass();
            IPointCollection points    = polyline as IPointCollection;
            IPoint           inPoint   = new PointClass();
            IPoint           point2    = new PointClass();
            IPoint           point3    = new PointClass();
            IPoint           point4    = new PointClass();

            try
            {
                symbol          = this.ilineSymbol_0;
                element2        = element3 as ILineElement;
                element2.Symbol = symbol;
                element2        = element4 as ILineElement;
                element2.Symbol = symbol;
                element2        = element5 as ILineElement;
                element2.Symbol = symbol;
                element2        = element6 as ILineElement;
                element2.Symbol = symbol;
                element2        = element7 as ILineElement;
                element2.Symbol = symbol;
                point2.PutCoords(ipoint_0.X, ipoint_0.Y + num3);
                inPoint.PutCoords(ipoint_0.X, (ipoint_0.Y + num3) + this.double_1);
                point3.PutCoords(ipoint_0.X + this.double_0, ipoint_0.Y + num3);
                point4.PutCoords(ipoint_0.X + this.double_0, (ipoint_0.Y + num3) + this.double_1);
                points.AddPoint(inPoint, ref missing, ref missing);
                points.AddPoint(point2, ref missing, ref missing);
                points.AddPoint(point3, ref missing, ref missing);
                points.AddPoint(point4, ref missing, ref missing);
                points.AddPoint(inPoint, ref missing, ref missing);
                element3.Geometry = polyline;
                element.AddElement(element3);
                IPoint point5 = new PointClass();
                IPoint point6 = new PointClass();
                point5.PutCoords(inPoint.X, inPoint.Y - num);
                point6.PutCoords(point4.X, point4.Y - num);
                points = polyline2 as IPointCollection;
                points.AddPoint(point5, ref missing, ref missing);
                points.AddPoint(point6, ref missing, ref missing);
                element4.Geometry = polyline2;
                element.AddElement(element4);
                point5.PutCoords(inPoint.X, inPoint.Y - (num * 2.0));
                point6.PutCoords(point4.X, point4.Y - (num * 2.0));
                points = polyline3 as IPointCollection;
                points.AddPoint(point5, ref missing, ref missing);
                points.AddPoint(point6, ref missing, ref missing);
                element5.Geometry = polyline3;
                element.AddElement(element5);
                point5.PutCoords(inPoint.X + num2, inPoint.Y);
                point6.PutCoords(inPoint.X + num2, point2.Y);
                points = polyline4 as IPointCollection;
                points.AddPoint(point5, ref missing, ref missing);
                points.AddPoint(point6, ref missing, ref missing);
                element6.Geometry = polyline4;
                element.AddElement(element6);
                point5.PutCoords(inPoint.X + (num2 * 2.0), inPoint.Y);
                point6.PutCoords(inPoint.X + (num2 * 2.0), point2.Y);
                points = polyline5 as IPointCollection;
                points.AddPoint(point5, ref missing, ref missing);
                points.AddPoint(point6, ref missing, ref missing);
                element7.Geometry = polyline5;
                element.AddElement(element7);
                IPolygon          polygon   = new PolygonClass();
                IElement          element8  = new PolygonElementClass();
                IPolygonElement   element9  = element8 as IPolygonElement;
                ISimpleFillSymbol symbol2   = new SimpleFillSymbolClass();
                IFillShapeElement element10 = element9 as IFillShapeElement;
                IRgbColor         color     = new RgbColorClass
                {
                    Red   = 0,
                    Green = 0,
                    Blue  = 0
                };
                symbol2.Outline  = this.ilineSymbol_0;
                symbol2.Color    = color;
                symbol2.Style    = esriSimpleFillStyle.esriSFSBackwardDiagonal;
                element10.Symbol = symbol2;
                points           = polygon as IPointCollection;
                point5.PutCoords(inPoint.X + num2, inPoint.Y - num);
                points.AddPoint(point5, ref missing, ref missing);
                point5.PutCoords(inPoint.X + (num2 * 2.0), inPoint.Y - num);
                points.AddPoint(point5, ref missing, ref missing);
                point5.PutCoords(inPoint.X + (num2 * 2.0), inPoint.Y - (num * 2.0));
                points.AddPoint(point5, ref missing, ref missing);
                point5.PutCoords(inPoint.X + num2, inPoint.Y - (num * 2.0));
                points.AddPoint(point5, ref missing, ref missing);
                polygon.Close();
                element8.Geometry = polygon;
                element.AddElement(element8);
                IEnvelope envelope = polygon.Envelope;
                new EnvelopeClass();
                if (this.string_0.Trim().Length > 0)
                {
                    element.AddElement(this.method_0(iactiveView_0, this.string_0, inPoint.X + (num2 / 2.0),
                                                     inPoint.Y - (num / 2.0), envelope));
                }
                if (this.string_1.Trim().Length > 0)
                {
                    element.AddElement(this.method_0(iactiveView_0, this.string_1, inPoint.X + (num2 / 2.0),
                                                     inPoint.Y - (1.5 * num), envelope));
                }
                if (this.string_2.Trim().Length > 0)
                {
                    element.AddElement(this.method_0(iactiveView_0, this.string_2, inPoint.X + (num2 / 2.0),
                                                     inPoint.Y - (2.5 * num), envelope));
                }
                if (this.string_3.Trim().Length > 0)
                {
                    element.AddElement(this.method_0(iactiveView_0, this.string_3, inPoint.X + (1.5 * num2),
                                                     inPoint.Y - (0.5 * num), envelope));
                }
                if (this.string_4.Trim().Length > 0)
                {
                    element.AddElement(this.method_0(iactiveView_0, this.string_4, inPoint.X + (1.5 * num2),
                                                     inPoint.Y - (2.5 * num), envelope));
                }
                if (this.string_5.Trim().Length > 0)
                {
                    element.AddElement(this.method_0(iactiveView_0, this.string_5, inPoint.X + (2.5 * num2),
                                                     inPoint.Y - (0.5 * num), envelope));
                }
                if (this.string_6.Trim().Length > 0)
                {
                    element.AddElement(this.method_0(iactiveView_0, this.string_6, inPoint.X + (2.5 * num2),
                                                     inPoint.Y - (1.5 * num), envelope));
                }
                if (this.string_7.Trim().Length > 0)
                {
                    element.AddElement(this.method_0(iactiveView_0, this.string_7, inPoint.X + (2.5 * num2),
                                                     inPoint.Y - (2.5 * num), envelope));
                }
            }
            catch (Exception)
            {
            }
            return(element as IElement);
        }
Esempio n. 17
0
        /// <summary>
        /// 由点坐标创建面对象
        /// </summary>
        /// <params name="pnts">点集合</params>
        /// <returns>返回的面对象</returns>
        public IPolygon CreatePolygonFromPnts(IList<IPoint> pnts, ISpatialReference spr)
        {
            IPolygon polygon = new PolygonClass();
            INewPolygonFeedback fac = new NewPolygonFeedbackClass();

            polygon.SpatialReference = spr;
            IPointCollection pntcols = polygon as IPointCollection;
            for (int i = 0; i < pnts.Count; i++)
            {
                pntcols.AddPoint(pnts[i]);
            }
            if (!polygon.IsClosed)
                polygon.Close();
            //polygon.Close();
            return polygon;
        }
Esempio n. 18
0
 public void RunCloudMetrics(IFeatureClass sampleLocation, float sampleRadius, string LasDir, string DtmDir = "", double cutBelow = 0, double cutAbove = 150, int shape = 0)
 {
     if (fusionInstalled)
     {
         string      LasDatasetPath  = LasDir + "\\LasFile.lasd";
         string      LasFeatureClass = LasDir + "\\LasBoundary.shp";
         ILasDataset lsDset          = new LasDatasetClass();
         ((ILasDataset2)lsDset).SaveAs(LasDatasetPath, true);
         ILasDatasetEdit lsDsetE = (ILasDatasetEdit)lsDset;
         IStringArray    sArr;
         lsDsetE.AddFolder(LasDir, "las", true, out sArr);
         lsDsetE.Save();
         ISpatialReference sp        = lsDset.SpatialReference;
         IFeatureClass     extFtrCls = geoUtil.createFeatureClass(LasFeatureClass, null, esriGeometryType.esriGeometryPolygon, sp);
         string            lasName   = geoUtil.createField(extFtrCls, "LasName", esriFieldType.esriFieldTypeString, false);
         IFeatureCursor    ftrCur    = extFtrCls.Insert(true);
         IFeatureBuffer    ftrBuff   = extFtrCls.CreateFeatureBuffer();
         int lasNameIndex            = extFtrCls.FindField(lasName);
         for (int i = 0; i < lsDset.FileCount; i++)
         {
             ILasFile  lsFile = lsDset.get_File(i);
             string    lsPath = lsFile.Name;
             IEnvelope lsEnv  = lsFile.Extent;
             IPolygon  poly   = new PolygonClass();
             poly.SpatialReference = sp;
             IPointCollection pCol = (IPointCollection)poly;
             pCol.AddPoint(lsEnv.LowerLeft);
             pCol.AddPoint(lsEnv.UpperLeft);
             pCol.AddPoint(lsEnv.UpperRight);
             pCol.AddPoint(lsEnv.LowerRight);
             poly.Close();
             ftrBuff.Shape = poly;
             ftrBuff.set_Value(lasNameIndex, lsPath);
             ftrCur.InsertFeature(ftrBuff);
         }
         ftrCur.Flush();
         System.Runtime.InteropServices.Marshal.ReleaseComObject(ftrCur);
         int[]          cloudMetricFieldsIndex = addCloudMetricFields(sampleLocation);
         IFeatureCursor pntCur = sampleLocation.Update(null, true);
         IFeature       pntftr = pntCur.NextFeature();
         while (pntftr != null)
         {
             Console.WriteLine("Working on Plot OID = " + pntftr.OID.ToString());
             IGeometry geo = pntftr.Shape;
             IPoint    pnt = (IPoint)geo;
             IEnvelope env = new EnvelopeClass();
             env.PutCoords(pnt.X - sampleRadius, pnt.Y - sampleRadius, pnt.X + sampleRadius, pnt.Y + sampleRadius);
             ISpatialFilter sf = new SpatialFilterClass();
             sf.Geometry   = env;
             sf.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
             IFeatureCursor polyCur  = extFtrCls.Search(sf, true);
             IFeature       polyftr  = polyCur.NextFeature();
             List <string>  lasFiles = new List <string>();
             while (polyftr != null)
             {
                 lasFiles.Add(polyftr.get_Value(lasNameIndex).ToString());
                 polyftr = polyCur.NextFeature();
             }
             System.Runtime.InteropServices.Marshal.ReleaseComObject(polyCur);
             if (lasFiles.Count > 0)
             {
                 //Console.WriteLine("Number of las files for point " + pntftr.OID.ToString() + " = " + lasFiles.Count.ToString());
                 object[] metricValues = extractCloudMetrics(env, lasFiles, 0, DtmDir, cutBelow, cutAbove, shape);
                 for (int i = 0; i < metricValues.Length; i++)
                 {
                     object vl      = metricValues[i];
                     int    vlIndex = cloudMetricFieldsIndex[i];
                     if (vlIndex > -1)
                     {
                         pntftr.set_Value(vlIndex, vl);
                     }
                 }
             }
             pntCur.UpdateFeature(pntftr);
             pntftr = pntCur.NextFeature();
         }
     }
 }
 private void createFeatureClass()
 {
     string ftClsPath = rsUtil.TempMosaicDir+"\\catBnd.shp";
     IFields flds = new FieldsClass();
     IFieldsEdit fldsE = (IFieldsEdit)flds;
     IField fld = new FieldClass();
     IFieldEdit fldE = (IFieldEdit)fld;
     fldE.Name_2 = "catIndex";
     fldE.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
     fldsE.AddField(fldE);
     ftCls = geoUtil.createFeatureClass(ftClsPath, fldsE, esriGeometryType.esriGeometryPolygon, sr);
     int catInd = ftCls.FindField("catIndex");
     int cnt = 0;
     foreach (IRaster rs in inrs)
     {
         IFeature ftr = ftCls.CreateFeature();
         ftr.set_Value(catInd, cnt);
         IEnvelope ext = ((IRasterProps)rs).Extent;
         IPolygon poly = new PolygonClass();
         IPointCollection pColl = (IPointCollection)poly;
         pColl.AddPoint(ext.UpperLeft);
         pColl.AddPoint(ext.UpperRight);
         pColl.AddPoint(ext.LowerRight);
         pColl.AddPoint(ext.LowerLeft);
         poly.Close();
         ftr.Shape = poly;
         ftr.Store();
         cnt++;
     }
 }
        /// <summary>
        /// 添加对象到指定的图层
        /// </summary>
        /// <params name="pnts">对象的点串</params>
        /// <params name="dics">属性字段</params>
        /// <params name="hdlayer">添加对象图层</params>
        public void AddHangdaoToLayer(List<IPoint> pnts, Dictionary<string, string> dics, IFeatureLayer layer, List<WirePoint> pntinfos = null)
        {
            //try
            //{
            IFeatureClass Featureclass = layer.FeatureClass;
            IWorkspaceEdit workspace = (IWorkspaceEdit)(Featureclass as IDataset).Workspace;
            workspace.StartEditing(false);
            workspace.StartEditOperation();
            esriGeometryType type = layer.FeatureClass.ShapeType;
            int index = -1;
            IGeometryDef geometryDef = null;

            switch (type)
            {
                case esriGeometryType.esriGeometryPolygon://添加面到相应的图层
                    IPolygon polygon = new PolygonClass();

                    //添加
                    polygon.SpatialReference = Global.spatialref;
                    IPointCollection regpntcols = (IPointCollection)polygon;
                    for (int i = 0; i < pnts.Count; i++)
                    {
                        regpntcols.AddPoint(pnts[i]);
                    }
                    polygon.Close();
                    //拓扑检查一下
                    ITopologicalOperator4 tops = polygon as ITopologicalOperator4;
                    if (!tops.IsSimple)
                        tops.Simplify();
                    IFeature fea = Featureclass.CreateFeature();
                    index = fea.Fields.FindField(GIS_Const.FIELD_SHAPE);
                    geometryDef = fea.Fields.get_Field(index).GeometryDef as IGeometryDef;
                    if (geometryDef.HasZ)
                    {
                        IZAware pZAware = (IZAware)polygon;
                        pZAware.ZAware = true;

                    }

                    fea.Shape = polygon;
                    foreach (string key in dics.Keys)
                    {
                        int fIndex = fea.Fields.FindField(key);
                        if (fIndex != -1)
                        {
                            fea.set_Value(fIndex, dics[key]);
                        }
                    }
                    fea.Store();
                    //地图定位跳转
                    Global.commonclss.JumpToGeometry(polygon);
                    break;

                case esriGeometryType.esriGeometryPolyline://中心线
                    IPolyline polyline = new PolylineClass();
                    IPointCollection plinecols = (IPointCollection)polyline;
                    for (int i = 0; i < pnts.Count; i++)
                    {
                        plinecols.AddPoint(pnts[i]);
                    }
                    polyline.SpatialReference = Global.spatialref;
                    //拓扑检查一下
                    ITopologicalOperator4 tops1 = polyline as ITopologicalOperator4;
                    if (!tops1.IsSimple)
                        tops1.Simplify();
                    //添加
                    IFeature fealin = Featureclass.CreateFeature();

                    IPointCollection polylinenew = new PolylineClass();
                    for (int i = 0; i < plinecols.PointCount; i++)
                    {
                        IPoint pnt = plinecols.get_Point(i);
                        IPoint pntnew = new PointClass();
                        pntnew.X = pnt.X;
                        pntnew.Y = pnt.Y;
                        pntnew.Z = 0.0;
                        polylinenew.AddPoint(pntnew);
                    }
                    polyline = polylinenew as IPolyline;
                    index = fealin.Fields.FindField(GIS_Const.FIELD_SHAPE);
                    geometryDef = fealin.Fields.get_Field(index).GeometryDef as IGeometryDef;
                    if (geometryDef.HasZ)
                    {
                        IZAware pZAware = (IZAware)polyline;
                        pZAware.ZAware = true;
                    }

                    fealin.Shape = polyline;
                    foreach (string key in dics.Keys)
                    {
                        int findex = fealin.Fields.FindField(key);
                        if (findex != -1)
                        {
                            fealin.set_Value(findex, dics[key]);
                        }
                    }
                    fealin.Store();
                    //地图定位跳转
                    Global.commonclss.JumpToGeometry(polyline);
                    break;

                case esriGeometryType.esriGeometryPoint://导线点
                    for (int i = 0; i < pnts.Count; i++)
                    {
                        IFeature feapnt = Featureclass.CreateFeature();
                        index = feapnt.Fields.FindField(GIS_Const.FIELD_SHAPE);
                        geometryDef = feapnt.Fields.get_Field(index).GeometryDef as IGeometryDef;
                        if (geometryDef.HasZ)
                        {
                            IZAware pZAware = (IZAware)pnts[i];
                            pZAware.ZAware = true;
                        }
                        feapnt.Shape = pnts[i];
                        if (pntinfos != null)
                        {
                            string name = pntinfos[i].name;
                            int NamePos = feapnt.Fields.FindField(GIS_Const.FIELD_NAME);
                            feapnt.set_Value(NamePos, name);
                        }
                        foreach (string key in dics.Keys)
                        {
                            int findex = feapnt.Fields.FindField(key);
                            if (findex != -1)
                            {
                                feapnt.set_Value(findex, dics[key]);
                            }
                        }

                        feapnt.Store();
                    }
                    break;
            }
            workspace.StopEditOperation();
            workspace.StopEditing(true);
            //}
            //catch(Exception ei)
            //{s
            //    throw new Exception();
            //}
        }
        /// <summary>
        /// 
        /// </summary>
        /// <params name="pnts0"></params>
        /// <params name="sxzs"></params>
        /// <params name="hdlayer"></params>
        /// <returns></returns>
        public IPolygon AddRegToLayer(List<IPoint> pnts0, Dictionary<string, string> sxzs, IFeatureLayer hdlayer)
        {
            IPolygon polygon = new PolygonClass();
            polygon.SpatialReference = Global.spatialref;
            try
            {
                IFeatureClass Featureclass = hdlayer.FeatureClass;
                IWorkspaceEdit workspace = (IWorkspaceEdit)(Featureclass as IDataset).Workspace;
                workspace.StartEditing(false);
                workspace.StartEditOperation();
                for (int i = 0; i < pnts0.Count; i++)
                {
                    IPointCollection regpntcols = (IPointCollection)polygon;
                    regpntcols.AddPoint(pnts0[i]);
                }
                polygon.Close();
                IFeature fea = Featureclass.CreateFeature();
                int index = fea.Fields.FindField(GIS_Const.FIELD_SHAPE);
                IGeometryDef geometryDef = fea.Fields.get_Field(index).GeometryDef as IGeometryDef;
                if (geometryDef.HasZ)
                {
                    IZAware pZAware = (IZAware)polygon;
                    pZAware.ZAware = true;
                    fea.Shape = polygon;
                    foreach (string key in sxzs.Keys)
                    {
                        fea.set_Value(fea.Fields.FindField(key), sxzs[key]);
                    }
                    fea.Store();
                }
                else
                {
                    fea.Shape = polygon;
                    if (sxzs != null)
                    {
                        foreach (string key in sxzs.Keys)
                        {
                            if (fea.Fields.FindField(key) != -1)
                            {
                                fea.set_Value(fea.Fields.FindField(key), sxzs[key]);
                            }
                        }
                    }
                    fea.Store();
                }
                workspace.StopEditOperation();
                workspace.StopEditing(true);
            }
            catch (Exception ei)
            {

            }
            return polygon;
        }
Esempio n. 22
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add ToolCreateCircle.OnMouseDown implementation
            if ((m_pMapCtl = ClsGlobal.GetMapControl(m_hookHelper)) == null)
            {
                return;
            }
            IPoint pPoint = m_pMapCtl.ToMapPoint(X, Y);

            if (Button == 1)
            {
                if (m_NewCircleFeedback == null)
                {
                    m_NewCircleFeedback         = new NewCircleFeedbackClass();
                    m_NewCircleFeedback.Display = m_pMapCtl.ActiveView.ScreenDisplay;

                    m_NewCircleFeedback.Start(pPoint);
                    m_CenterPoint = pPoint;
                }
                else
                {
                    try
                    {
                        object       Miss = Type.Missing;
                        ICircularArc pArc = m_NewCircleFeedback.Stop();
                        //IGeometry geometry = new PolygonClass();
                        //geometry = m_pMapCtl.TrackCircle();
                        IPolygon           pPolygon = new PolygonClass();
                        ISegment           pArcC    = pArc as ISegment;
                        ISegmentCollection pArcP    = pPolygon as ISegmentCollection;
                        pArcP.AddSegment(pArcC, ref Miss, ref Miss);
                        pPolygon.Close();
                        IFeature pFeature = m_FLayer.FeatureClass.CreateFeature();
                        pFeature.Shape = pPolygon;
                        pFeature.Store();
                        m_pMapCtl.Refresh();
                        m_NewCircleFeedback = null;
                    }
                    catch (System.Exception ex)
                    {
                    }
                }
            }
            if (Button == 2)
            {
                double                radius        = Math.Sqrt((pPoint.X - m_CenterPoint.X) * (pPoint.X - m_CenterPoint.X) + (pPoint.Y - m_CenterPoint.Y) * (pPoint.Y - m_CenterPoint.Y));
                FrmDrawCircle         frm           = new FrmDrawCircle(radius);
                IConstructCircularArc pArcConstruct = null;
                if (m_NewCircleFeedback == null)
                {
                    return;
                }

                if (frm.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        pArcConstruct = new CircularArcClass();
                        pArcConstruct.ConstructCircle(m_CenterPoint, frm.m_radius, false);
                        if (pArcConstruct != null)
                        {
                            IPolygon           pPolygon = new PolygonClass();
                            ISegment           pArcC    = pArcConstruct as ISegment;
                            ISegmentCollection pArcP    = pPolygon as ISegmentCollection;
                            pArcP.AddSegment(pArcC);
                            pPolygon.Close();
                            IFeature pFeature = m_FLayer.FeatureClass.CreateFeature();
                            pFeature.Shape = pPolygon;
                            pFeature.Store();
                            m_pMapCtl.Refresh();
                            m_NewCircleFeedback.Stop();
                            m_NewCircleFeedback = null;
                        }
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        if (m_NewCircleFeedback != null)
                        {
                            m_NewCircleFeedback.Stop();
                        }
                        m_NewCircleFeedback = null;
                    }
                }
            }
        }
Esempio n. 23
0
        private IPolygon GetMGRSPolygon(IPoint point)
        {
            CoordinateMGRS mgrs;

            IPointCollection pc = new RingClass();

            // bottom left
            CoordinateMGRS.TryParse(InputCoordinate, out mgrs);

            // don't create a polygon for 1m resolution
            if (mgrs.Easting.ToString().Length > 4 && mgrs.Northing.ToString().Length > 4)
            {
                return(null);
            }

            var tempPoint = new PointClass() as IConversionNotation;

            (tempPoint as IPoint).SpatialReference = GetSR();
            var anotherMGRSstring = mgrs.ToString("", new CoordinateMGRSFormatter());

            tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // top left
            var tempMGRS    = new CoordinateMGRS(mgrs.GZD, mgrs.GS, mgrs.Easting, mgrs.Northing);
            var tempEasting = mgrs.Easting.ToString().PadRight(5, '0');

            tempMGRS.Easting = Convert.ToInt32(tempEasting);
            var tempNorthing = mgrs.Northing.ToString().PadRight(5, '9');

            tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0', '9'));

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            anotherMGRSstring = tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter());
            tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // top right
            tempEasting       = mgrs.Easting.ToString().PadRight(5, '9');
            tempMGRS.Easting  = Convert.ToInt32(tempEasting.Replace('0', '9'));
            tempNorthing      = mgrs.Northing.ToString().PadRight(5, '9');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0', '9'));

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // bottom right
            tempEasting       = mgrs.Easting.ToString().PadRight(5, '9');
            tempMGRS.Easting  = Convert.ToInt32(tempEasting.Replace('0', '9'));
            tempNorthing      = mgrs.Northing.ToString().PadRight(5, '0');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing);

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // create polygon
            var poly = new PolygonClass();

            poly.SpatialReference = GetSR();
            poly.AddPointCollection(pc);
            poly.Close();

            return(poly);
        }
Esempio n. 24
0
        /// <summary>
        /// convert an evelope to a polygon
        /// </summary>
        public static IPolygon EnvelopeToPolygon(IEnvelope ThisEnvelope)
        {
            IPolygon EnvelopePoly;
            object emtpy = System.Reflection.Missing.Value;
            IPoint EnveCorner;

            EnvelopePoly = new PolygonClass();

            EnveCorner = ((ESRI.ArcGIS.esriSystem.IClone)ThisEnvelope.Envelope.UpperLeft).Clone() as IPoint;
            ((IPointCollection)EnvelopePoly).AddPoint(EnveCorner, ref emtpy, ref emtpy);

            EnveCorner = ((ESRI.ArcGIS.esriSystem.IClone)ThisEnvelope.Envelope.UpperRight).Clone() as IPoint;
            ((IPointCollection)EnvelopePoly).AddPoint(EnveCorner, ref emtpy, ref emtpy);

            EnveCorner = ((ESRI.ArcGIS.esriSystem.IClone)ThisEnvelope.Envelope.LowerRight).Clone() as IPoint;
            ((IPointCollection)EnvelopePoly).AddPoint(EnveCorner, ref emtpy, ref emtpy);

            EnveCorner = ((ESRI.ArcGIS.esriSystem.IClone)ThisEnvelope.Envelope.LowerLeft).Clone() as IPoint;
            ((IPointCollection)EnvelopePoly).AddPoint(EnveCorner, ref emtpy, ref emtpy);

            EnvelopePoly.Close();

            return EnvelopePoly;
        }
Esempio n. 25
0
        private IPolygon ContructGeometry(out PolygonClass polygon1)
        {
            polygon1 = new PolygonClass();
            var polygon = new PolygonClass();
            var p00     = ConstructPoint(_centerPoint, Angle0, Angle1, _height4, 0);
            var p01     = ConstructPoint(_centerPoint, Angle2, Angle1, _height4);
            var p04     = ConstructPoint(_centerPoint, Angle0, Angle1, _height4);

            var list0 = new List <IPoint>
            {
                p01,
                ConstructPoint2(p01, Angle3, p00, Angle2 - Angle3),
                ConstructPoint2(p00, -Angle3, p04, Angle2 + Angle3),
                p04,
                ConstructPoint(_centerPoint, Angle0, Angle1, _height3),
                ConstructPoint(_centerPoint, Angle2, Angle1, _height3),
                p01
            };

            polygon1.AddGeometry(ConstructRing(list0));

            var list1 = new List <IPoint>
            {
                p00,
                ConstructPoint2(p00, Angle3, p04, Angle2 - Angle3),
                p04,
                ConstructPoint2(p00, -Angle3, p04, Angle2 + Angle3),
                p00
            };

            polygon.AddGeometry(ConstructRing(list1));

            var list2 = new List <IPoint>
            {
                ConstructPoint(_centerPoint, Angle2, Angle1, _height3),
                ConstructPoint(_centerPoint, Angle0, Angle1, _height3),
                ConstructPoint(_centerPoint, Angle0, Angle1, _halfHeight),
                ConstructPoint(_centerPoint, Angle2, Angle1, _halfHeight),
                ConstructPoint(_centerPoint, Angle2, Angle1, _height3)
            };

            polygon.AddGeometry(ConstructRing(list2));

            var list3 = new List <IPoint>
            {
                ConstructPoint(_centerPoint, Angle2, -Angle1, _height3),
                ConstructPoint(_centerPoint, Angle0, -Angle1, _height3),
                ConstructPoint(_centerPoint, Angle0, -Angle1, _halfHeight),
                ConstructPoint(_centerPoint, Angle2, -Angle1, _halfHeight),
                ConstructPoint(_centerPoint, Angle2, -Angle1, _height3)
            };

            polygon.AddGeometry(ConstructRing(list3));

            var p20 = ConstructPoint(_centerPoint, Angle0, -Angle1, _height4, 0);
            var p21 = ConstructPoint(_centerPoint, Angle2, -Angle1, _height4);
            var p24 = ConstructPoint(_centerPoint, Angle0, -Angle1, _height4);

            var list4 = new List <IPoint>
            {
                p21,
                ConstructPoint2(p21, Angle3, p20, Angle2 - Angle3),
                ConstructPoint2(p20, -Angle3, p24, Angle2 + Angle3),
                p24,
                ConstructPoint(_centerPoint, Angle0, -Angle1, _height3),
                ConstructPoint(_centerPoint, Angle2, -Angle1, _height3),
                p21
            };

            polygon1.AddGeometry(ConstructRing(list4));

            var list5 = new List <IPoint>
            {
                p20,
                ConstructPoint2(p20, Angle2 - Angle3, p21, Angle3),
                p21,
                ConstructPoint2(p20, Angle2 + Angle3, p21, -Angle3),
                p20
            };

            polygon.AddGeometry(ConstructRing(list5));
            polygon.Close();

            return(polygon);
        }
Esempio n. 26
0
        public static void CreateFCs(IWorkspace pWs, IMap pMap)
        {
            var FC1 = CreateFeatureClass(pWs, null, "Point", CreateFields(esriGeometryType.esriGeometryPoint));
            var FC2 = CreateFeatureClass(pWs, null, "Line", CreateFields(esriGeometryType.esriGeometryPolyline));
            var FC3 = CreateFeatureClass(pWs, null, "Polygon", CreateFields(esriGeometryType.esriGeometryPolygon));

            //insert& show
            List<IGeometry> ptList = new List<IGeometry>(100);
            IPoint pt;
            for (int i = 0; i < 1000; i++)
            {
                pt = new PointClass();
                pt.PutCoords(i * 0.01, i * 0.01);
                ptList.Add(pt);
            }

            List<IGeometry> lineList = new List<IGeometry>(100);
            IPolyline pLine;
            IPoint pt1, pt2;
            for (int i = 0; i < 1000; i++)
            {
                pLine = new PolylineClass();
                pt1 = new PointClass();
                pt1.PutCoords(i * 0.01, (i + 1) * 0.01);
                pt2 = new PointClass();
                pt2.PutCoords(i * 0.01, (i + 11) * 0.01);
                pLine.FromPoint = pt1;
                pLine.ToPoint = pt2;
                lineList.Add(pLine);
            }

            List<IGeometry> polygonList = new List<IGeometry>(100);
            IPolygon pPolygon;
            IPoint pt3, pt4;
            for (int i = 0; i < 1000; i++)
            {
                pPolygon = new PolygonClass();
                IPointCollection ptColl = pPolygon as IPointCollection;
                pt1 = new PointClass();
                pt1.PutCoords(i * 0.01, (i - 2) * 0.01);
                pt2 = new PointClass();
                pt2.PutCoords((i + 1) * 0.01, (i - 2) * 0.01);
                pt3 = new PointClass();
                pt3.PutCoords((i + 1) * 0.01, (i - 3) * 0.01);
                pt4 = new PointClass();
                pt4.PutCoords(i * 0.01, (i - 3) * 0.01);
                ptColl.AddPoint(pt1);
                ptColl.AddPoint(pt2);
                ptColl.AddPoint(pt3);
                ptColl.AddPoint(pt4);
                pPolygon.Close();
                polygonList.Add(pPolygon);
            }

            InsertFeaturesUsingCursor(FC1, ptList);
            InsertFeaturesUsingCursor(FC2, lineList);
            InsertFeaturesUsingCursor(FC3, polygonList);

            IFeatureLayer pFeaturelayer = new FeatureLayerClass();
            pFeaturelayer.Name = "pt";
            pFeaturelayer.FeatureClass = FC1;
            pMap.AddLayer(pFeaturelayer);
            pFeaturelayer = new FeatureLayerClass();
            pFeaturelayer.Name = "line";
            pFeaturelayer.FeatureClass = FC2;
            pMap.AddLayer(pFeaturelayer);
            pFeaturelayer = new FeatureLayerClass();
            pFeaturelayer.Name = "polygon";
            pFeaturelayer.FeatureClass = FC3;
            pMap.AddLayer(pFeaturelayer);
        }
        private IPolygon GetMGRSPolygon(IPoint point)
        {
            CoordinateMGRS mgrs;

            IPointCollection pc = new RingClass();

            // bottom left
            CoordinateMGRS.TryParse(InputCoordinate, out mgrs);

            // don't create a polygon for 1m resolution
            if (mgrs.Easting.ToString().Length > 4 && mgrs.Northing.ToString().Length > 4)
                return null;

            var tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            var anotherMGRSstring = mgrs.ToString("", new CoordinateMGRSFormatter());
            tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);
            
            // top left
            var tempMGRS = new CoordinateMGRS(mgrs.GZD, mgrs.GS, mgrs.Easting, mgrs.Northing);
            var tempEasting = mgrs.Easting.ToString().PadRight(5,'0');
            tempMGRS.Easting = Convert.ToInt32(tempEasting);
            var tempNorthing = mgrs.Northing.ToString().PadRight(5,'9');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0','9'));

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            anotherMGRSstring = tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter());
            tempPoint.PutCoordsFromMGRS(anotherMGRSstring, esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // top right
            tempEasting = mgrs.Easting.ToString().PadRight(5,'9');
            tempMGRS.Easting = Convert.ToInt32(tempEasting.Replace('0', '9'));
            tempNorthing = mgrs.Northing.ToString().PadRight(5,'9');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing.Replace('0', '9'));

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // bottom right
            tempEasting = mgrs.Easting.ToString().PadRight(5,'9');
            tempMGRS.Easting = Convert.ToInt32(tempEasting.Replace('0', '9'));
            tempNorthing = mgrs.Northing.ToString().PadRight(5,'0');
            tempMGRS.Northing = Convert.ToInt32(tempNorthing);

            tempPoint = new PointClass() as IConversionNotation;
            (tempPoint as IPoint).SpatialReference = GetSR();
            tempPoint.PutCoordsFromMGRS(tempMGRS.ToString("ZSX00000Y00000", new CoordinateMGRSFormatter()), esriMGRSModeEnum.esriMGRSMode_Automatic);
            pc.AddPoint(tempPoint as IPoint);

            // create polygon
            var poly = new PolygonClass();
            poly.SpatialReference = GetSR();
            poly.AddPointCollection(pc);
            poly.Close();

            return poly;
        }
Esempio n. 28
0
        private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)//左下角鼠标坐标显示
        {
            sMapUnit        = GetMapUnit(axMapControl1.Map.MapUnits);
            barCoorTxt.Text = string.Format("当前坐标:X{0:#.###}  Y={1:#.###}{2}", e.mapX, e.mapY, sMapUnit);
            pMovePt         = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); //获取移动点
            switch (mousedownname)
            {
            case "MeasureLength":    //距离量测
                if (pNewLineFeedback != null)
                {
                    pNewLineFeedback.MoveTo(pMovePt);    //移动至当前
                }
                if (pPointPt != null && pNewLineFeedback != null)
                {
                    double deltaX = pMovePt.X - pPointPt.X;    //两点间X差
                    double deltaY = pMovePt.Y - pPointPt.Y;    //两点间Y 差
                    dSegmentLength = Math.Round(Math.Sqrt(deltaX * deltaX + deltaY * deltaY), 3);
                    dToltaLength   = dToltaLength + dSegmentLength;
                    if (frmMeasureresult != null)
                    {
                        frmMeasureresult.label2.Text = String.Format("当前长度线段为:{0:.###}{1};\r\n总长度为:{2:.###}{1}", dSegmentLength, sMapUnit, dToltaLength);
                        dToltaLength = dToltaLength - dSegmentLength;    //鼠标移动到新点重新开始计算
                    }
                }

                break;

            case "MeasureArea":    //面积量测
                if (pNewPolygonFeedback != null)
                {
                    pNewPolygonFeedback.MoveTo(pMovePt);
                }
                IPointCollection pPointCol = new Polygon();      //实例化一个新的点集对象
                IPolygon         pPolygon  = new PolygonClass(); //实例化一个面几何对象


                for (int i = 0; i <= pAreaPointCollection.PointCount - 1; i++)
                {
                    pPointCol.AddPoint(pAreaPointCollection.get_Point(i), ref missing, ref missing);    //将全局变量中已经确定的点集赋给pPointCol这个点集对象
                }

                pPointCol.AddPoint(pMovePt, ref missing, ref missing);    //将当前的移动点赋给pPointCol这个点集对象

                if (pPointCol.PointCount < 3)
                {
                    return;                       //小于三个点无法形成面,不执行以下语句
                }
                pPolygon = pPointCol as IPolygon; //将点集合形成一个面对象
                if ((pPolygon != null))
                {
                    pPolygon.Close();
                    IGeometry            pGeo  = pPolygon;
                    ITopologicalOperator pTopo = pGeo as ITopologicalOperator;
                    pTopo.Simplify();
                    pGeo.Project(axMapControl1.Map.SpatialReference);
                    IArea pArea = pGeo as IArea;
                    frmMeasureresult.label2.Text = String.Format("总面积为:{0:.####}平方{1};\r\n总长度为:{2:.#####}{1}", pArea.Area, sMapUnit, pPolygon.Length);
                }

                break;
            }
        }
Esempio n. 29
0
        /// <summary>
        /// MainMapControl鼠标移动事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainMapControl_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
        {
            sMapUnits = GetMapUnit(MainMapControl.Map.MapUnits);
            toolStripStatusLabel1.Text = String.Format("当前坐标:X = {0:#.###} Y = {1:#.###} {2}", e.mapX, e.mapY, sMapUnits);
            pMovePt = (MainMapControl.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);

            switch (pMouseOperate)
            {
            case "MeasureLength":
                if (pNewLineFeedback != null)
                {
                    pNewLineFeedback.MoveTo(pMovePt);
                }
                double deltaX = 0;     //两点之间X差值
                double deltaY = 0;     //两点之间Y差值

                if ((pPointPt != null) && (pNewLineFeedback != null))
                {
                    deltaX         = pMovePt.X - pPointPt.X;
                    deltaY         = pMovePt.Y - pPointPt.Y;
                    dSegmentLength = Math.Round(Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY)), 3);
                    dToltalLength  = dToltalLength + dSegmentLength;
                    if (frmMeasureResult != null)
                    {
                        frmMeasureResult.lblMeasureResult.Text = String.Format(
                            "当前线段长度:{0:.###}{1};\r\n总长度为: {2:.###}{1}",
                            dSegmentLength, sMapUnits, dToltalLength);
                        dToltalLength = dToltalLength - dSegmentLength;     //鼠标移动到新点重新开始计算
                    }
                    frmMeasureResult.frmClosed += new FormMeasureResult.FormClosedEventHandler(frmMeasureResult_frmColsed);
                }
                break;

            case "MeasureArea":
                if (pNewPolygonFeedback != null)
                {
                    pNewPolygonFeedback.MoveTo(pMovePt);
                }

                IPointCollection pPointCol = new Polygon();
                IPolygon         pPolygon  = new PolygonClass();
                IGeometry        pGeo      = null;

                ITopologicalOperator pTopo = null;
                for (int i = 0; i <= pAreaPointCol.PointCount - 1; i++)
                {
                    pPointCol.AddPoint(pAreaPointCol.get_Point(i), ref missing, ref missing);
                }
                pPointCol.AddPoint(pMovePt, ref missing, ref missing);

                if (pPointCol.PointCount < 3)
                {
                    return;
                }
                pPolygon = pPointCol as IPolygon;

                if ((pPolygon != null))
                {
                    pPolygon.Close();
                    pGeo  = pPolygon as IGeometry;
                    pTopo = pGeo as ITopologicalOperator;
                    //使几何图形的拓扑正确
                    pTopo.Simplify();
                    pGeo.Project(MainMapControl.Map.SpatialReference);
                    IArea pArea = pGeo as IArea;

                    frmMeasureResult.lblMeasureResult.Text = String.Format(
                        "总面积为:{0:.####}平方{1};\r\n总长度为:{2:.####}{1}",
                        pArea.Area, sMapUnits, pPolygon.Length);
                    pPolygon = null;
                }

                break;

            default:
                break;
            }
        }
Esempio n. 30
0
        public void ContructGeometry(IPoint point, List<KeyValuePair<int, double>> datasources, out List<KeyValuePair<string, IPolygon>> polygons, out List<IPoint> lineStartPoints, out List<IPoint> txtPoints)
        {
            _centerPoint = new PointClass { X = point.X, Y = point.Y };
            polygons = new List<KeyValuePair<string, IPolygon>>();

            lineStartPoints = new List<IPoint>();
            txtPoints = new List<IPoint>();

            var polygonBlack = new PolygonClass();
            var polygonWhite = new PolygonClass();
            _linepoints = lineStartPoints;
            _points = txtPoints;

            var indexLine = 0;
            var length = datasources.Sum(s => s.Value) * BL;
            var totalLength = length / 2;
            _halfHeight = length / 2;
            _height3 = _halfHeight + GeometryHeight1;
            _height4 = _halfHeight + GeometryHeight0 + GeometryHeight1;
            IPoint lastFromPoint = null;
            //IPoint lastToPoint = null;

            foreach (var d in datasources)
            {
                double dd = d.Value * BL;
                var list30 = new List<IPoint>
                {
                    ConstructPoint(_centerPoint, 180, 90, totalLength),
                    ConstructPoint(_centerPoint, 0, 90, totalLength),
                    ConstructPoint(_centerPoint, 0, 90, totalLength - dd),
                    ConstructPoint(_centerPoint, 180, 90, totalLength - dd),
                    ConstructPoint(_centerPoint, 180, 90, totalLength)
                };

                //  生成面
                var geometry = ConstructRing(list30);

                if (d.Key == 0)
                {
                    polygonWhite.AddGeometry(geometry);
                }
                else
                {
                    polygonBlack.AddGeometry(geometry);
                }

                //int angleLine = indexLine % 2 == 0 ? 0 : 180;

                var fromPoint = list30[indexLine % 2 + 2];
                //var toPoint = ConstructPoint3(fromPoint, angleLine, LineWidth);

                //  生成线
                _linepoints.Add(fromPoint);

                lastFromPoint = list30[3];
                //lastToPoint = ConstructPoint3(lastFromPoint, Angle2, LineWidth * 2);

                var txtPoint = new PointClass();
                txtPoint.ConstructAngleDistance(fromPoint, (TextOffsetAngle + indexLine % 2 * 180) * Deg2Rad, TextOffsetDistance);

                //  生成点
                _points.Add(txtPoint);

                totalLength -= dd;
                indexLine++;
            }

            if (lastFromPoint != null)
            {
                var txtLastPoint = new PointClass();
                txtLastPoint.ConstructAngleDistance(lastFromPoint, 180 * Deg2Rad, LastTextOffsetDistance);

                //  生成点
                _points.Add(txtLastPoint);
                //  生成线
                _linepoints.Add(lastFromPoint);
            }

            polygonWhite.Close();
            polygonBlack.Close();
            var tPolygon = new PolygonClass();
            polygons.Add(new KeyValuePair<string, IPolygon>("top", ContructGeometry(out tPolygon)));
            polygons.Add(new KeyValuePair<string, IPolygon>("top", tPolygon));
            polygons.Add(new KeyValuePair<string, IPolygon>("white", polygonWhite));
            polygons.Add(new KeyValuePair<string, IPolygon>("black", polygonBlack));
        }