Exemple #1
0
        //获取矿界
        private IPolygon GetPolygon()
        {
            IPolygon      polygon2     = null;
            ILayer        pLayer       = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MINE_BOUNDARY);
            IFeatureLayer polygonLayer = (IFeatureLayer)pLayer;

            IQueryFilter filter = new QueryFilterClass();

            filter.WhereClause = "layer = '预警矿界'";

            IFeatureLayer         featureLayer        = polygonLayer as IFeatureLayer;
            IFeatureCursor        featureCursor       = featureLayer.Search(filter, false);
            ITopologicalOperator2 topologicalOperator = null;

            //  获得矿界组合成面
            if (featureCursor != null)
            {
                ISegmentCollection polygon = new PolygonClass();

                IFeature feature = featureCursor.NextFeature();

                while (feature != null)
                {
                    polygon.AddSegmentCollection((ISegmentCollection)feature.Shape);
                    feature = featureCursor.NextFeature();
                }

                topologicalOperator = (ITopologicalOperator2)polygon;
                topologicalOperator.IsKnownSimple_2 = true;
                topologicalOperator.Simplify();

                polygon2 = (IPolygon)topologicalOperator;
            }
            return(polygon2);
        }
Exemple #2
0
        /// <summary>
        /// 将多个图形合并(Union)成一个图形(使用GeometryBag提高合并效率)
        /// </summary>
        /// <param name="geometryBag"></param>
        /// <param name="geometryType">几何类型</param>
        /// <returns></returns>
        private static IGeometry UnionGeometryEx(this IGeometry geometryBag, esriGeometryType geometryType)
        {
            ITopologicalOperator unionedGeometry;

            switch (geometryType)
            {
            case esriGeometryType.esriGeometryPoint:
                unionedGeometry = new PointClass();
                break;

            case esriGeometryType.esriGeometryPolyline:
                unionedGeometry = new PolylineClass();
                break;

            case esriGeometryType.esriGeometryPolygon:
                unionedGeometry = new PolygonClass();
                break;

            default:
                throw new NotImplementedException($"几何类型({nameof(geometryType)})应是点(point)、线(polyline)、多边形(polygon)之一,未实现{geometryType}类型的图形合并(Union)!");
            }

            unionedGeometry.ConstructUnion(geometryBag as IEnumGeometry);
            return((IGeometry)unionedGeometry);
        }
Exemple #3
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++;
            }
        }
Exemple #4
0
        private IGeometry mergeSmallGeos(IGeometry geo)
        {
            ITopologicalOperator4 tp4    = (ITopologicalOperator4)geo;
            IGeometryCollection   geoCol = new PolygonClass();
            IGeometry             bGeo   = tp4.Boundary;
            ISpatialFilter        spFilt = new SpatialFilter();

            spFilt.Geometry      = bGeo;
            spFilt.SearchOrder   = esriSearchOrder.esriSearchOrderSpatial;
            spFilt.GeometryField = ftrCls.ShapeFieldName;
            spFilt.SpatialRel    = esriSpatialRelEnum.esriSpatialRelContains;
            spFilt.WhereClause   = "Shape_Area <= " + minarea;
            spFilt.SubFields     = ftrCls.ShapeFieldName;
            IFeatureCursor ftrCur  = ftrCls.Search(spFilt, false);
            IFeature       ftr     = ftrCur.NextFeature();
            int            cntTest = 0;

            while (ftr != null)
            {
                IGeometry sGeo = ftr.ShapeCopy;
                geoCol.AddGeometry(sGeo);
                ftr.Delete();
                ftr = ftrCur.NextFeature();
                cntTest++;
            }
            if (cntTest > 0)
            {
                tp4.ConstructUnion((IEnumGeometry)geoCol);
            }
            return((IGeometry)tp4);
        }
Exemple #5
0
        public static IGeometry GetExample3()
        {
            const double FromZ = 0;
            const double ToZ   = 9.5;

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

            IPointCollection polygonPointCollection = new PolygonClass();

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

            IPolygon polygon = polygonPointCollection as IPolygon;

            polygon.Close();

            IGeometry polygonGeometry = polygonPointCollection as IGeometry;

            ITopologicalOperator topologicalOperator = polygonGeometry as ITopologicalOperator;

            topologicalOperator.Simplify();

            IConstructMultiPatch constructMultiPatch = new MultiPatchClass();

            constructMultiPatch.ConstructExtrudeFromTo(FromZ, ToZ, polygonGeometry);

            return(constructMultiPatch as IGeometry);
        }
        private IPolygon FlatBuffer(IPolyline pLline1, double pBufferDis)
        {
            object o = System.Type.Missing;
            //分别对输入的线平移两次(正方向和负方向)
            IConstructCurve pCurve1 = new PolylineClass();

            pCurve1.ConstructOffset(pLline1, pBufferDis, ref o, ref o);
            IPointCollection pCol    = pCurve1 as IPointCollection;
            IConstructCurve  pCurve2 = new PolylineClass();

            pCurve2.ConstructOffset(pLline1, -1 * pBufferDis, ref o, ref o);
            //把第二次平移的线的所有节点翻转
            IPolyline pline2 = pCurve2 as IPolyline;

            pline2.ReverseOrientation();
            //把第二条的所有节点放到第一条线的IPointCollection里面
            IPointCollection pCol2 = pline2 as IPointCollection;

            pCol.AddPointCollection(pCol2);
            //用面去初始化一个IPointCollection
            IPointCollection pPointCol = new PolygonClass();

            pPointCol.AddPointCollection(pCol);
            //把IPointCollection转换为面
            IPolygon pPolygon = pPointCol as IPolygon;

            //简化节点次序
            pPolygon.SimplifyPreserveFromTo();
            return(pPolygon);
        }
Exemple #7
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            IPointCollection points = new PolygonClass();

            if (this.listView1.Items.Count < 3)
            {
                MessageBox.Show("点数必须大于或等于3个点");
            }
            else
            {
                for (int i = 0; i < this.listView1.Items.Count; i++)
                {
                    ListViewItem item = this.listView1.Items[i];
                    double       num2 = double.Parse(item.Text);
                    double       num3 = double.Parse(item.SubItems[1].Text);
                    if (this.imap_0.MapUnits != esriUnits.esriKilometers)
                    {
                        num2 *= 1000.0;
                        num3 *= 1000.0;
                    }
                    IPoint inPoint = new PointClass
                    {
                        X = num2,
                        Y = num3
                    };
                    object before = Missing.Value;
                    points.AddPoint(inPoint, ref before, ref before);
                }
                (points as IPolygon).Close();
                this.igeometry_0  = points as IGeometry;
                base.DialogResult = DialogResult.OK;
            }
        }
        /// <summary>
        /// 将字符串格式转化为Geometry
        /// </summary>
        /// <param name="geom">    客户端传递多边形格式 1) x1,y1;x2,y2;x3,y3.......xn,yn;x1,y1;保证起始闭合 为无环
        ///                                            2) x1,y1,flag3;x2,y2,flag3;x3,y3,flag3.......xn,yn,,flagn;
        /// </param>
        /// <returns></returns>
        public static IPolygon BuildPolygon(string geom)
        {
            if (string.IsNullOrEmpty(geom) == true)
            {
                throw new Exception(sErroCoordinatesIsNull);
            }

            string[] points = geom.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            if (points != null && points.Length > 2)
            {
                int pointCount = points.Length;
                IPolygon polygon = null;
                IPoint point = null;
                object missing = Type.Missing;
                IGeometryCollection pGeoColl = new PolygonClass() as IGeometryCollection;
                IPointCollection pPointCol = new RingClass();
                for (int i = 0; i < pointCount; i++)
                {
                    string[] pts = points[i].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    point = new PointClass();
                    double x = 0.0;
                    double y = 0.0;
                    int flag = 0;
                    bool bX = double.TryParse(pts[0], out x);
                    bool bY = double.TryParse(pts[1], out y);
                    bool bFlag = int.TryParse(pts[2], out flag);
                    if (bX && bY && bFlag)
                    {
                        pPointCol.AddPoint(point, ref  missing, ref missing);
                        if (flag == -1 || i == (pointCount - 1))
                        {
                            pGeoColl.AddGeometry(pPointCol as IRing, ref missing, ref missing);
                            pPointCol = null;
                            break;
                        }
                        else if (flag == -2)
                        {
                            pGeoColl.AddGeometry(pPointCol as IRing, ref missing, ref missing);
                            pPointCol = new RingClass();
                            continue;
                        }
                    }
                    else
                    {
                        throw new Exception(sErroCoordinatesValueIllegal);
                    }
                }
                if (pPointCol.PointCount > 0)
                {
                    pGeoColl.AddGeometry(pPointCol as IRing, ref missing, ref missing);
                }
                polygon = pGeoColl as IPolygon;
                SimplifyGeometry(polygon);
                return polygon;
            }
            else
            {
                throw new Exception(sErroCoordinatesValueIllegal);
            }
        }
Exemple #9
0
        public static IPolygon GetVisilityPolygon(IPointCollection points)
        {
            IGeometryBridge2  geometryBridge2  = new GeometryEnvironmentClass();
            IPointCollection4 pointCollection4 = new PolygonClass();

            WKSPointZ[] aWKSPoints = new WKSPointZ[points.PointCount];

            for (int i = 0; i < aWKSPoints.Length; i++)
            {
                aWKSPoints[i] = PointToWKSPoint(points.Point[i]);
            }

            geometryBridge2.SetWKSPointZs(pointCollection4, ref aWKSPoints);

            var     geometry = pointCollection4 as IGeometry;
            IZAware zAware   = geometry as IZAware;

            zAware.ZAware = true;

            var result = pointCollection4 as IPolygon;

            result.SpatialReference = points.Point[0].SpatialReference;

            return(result);
        }
Exemple #10
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add ToolCreateParallel.OnMouseDown implementation
            if (Button == 1 && (m_pMapCtl = ClsGlobal.GetMapControl(m_hookHelper)) != null)
            {
                IMap   pMap = m_pMapCtl.Map;
                IPoint po   = m_pMapCtl.ToMapPoint(X, Y);
                ISelectionEnvironment pSelectionEnv = new SelectionEnvironmentClass();

                IGeometry geometry = new PolygonClass();
                geometry = m_pMapCtl.TrackRectangle();
                pMap.SelectByShape(geometry, pSelectionEnv, true);
                m_pMapCtl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                IEnumFeatureSetup pSelectionsetup = pMap.FeatureSelection as IEnumFeatureSetup;
                pSelectionsetup.AllFields = true;//这里是关键
                IEnumFeature pFeatureCollection = pSelectionsetup as IEnumFeature;
                IFeature     pF = pFeatureCollection.Next();
                if (pF != null && pF.Shape is IPolyline)
                {
                    FrmParallelLineOffset frm = new FrmParallelLineOffset();
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        IPolyline pPolyline = ConstructOffset(pF.Shape as IPolyline, frm.offset);
                        IFeature  pFeature  = m_FLayer.FeatureClass.CreateFeature();
                        pFeature.Shape = pPolyline;
                        pFeature.Store();
                        m_pMapCtl.Refresh();
                    }
                }
            }
        }
Exemple #11
0
        private IElement method_9(IPoint ipoint_0)
        {
            IFillSymbol symbol = new SimpleFillSymbolClass();

            (symbol as ISimpleFillSymbol).Style = esriSimpleFillStyle.esriSFSNull;
            IPolygon polygon = new PolygonClass();
            object   missing = Type.Missing;
            IPoint   inPoint = new PointClass();

            inPoint.PutCoords(ipoint_0.X, ipoint_0.Y);
            (polygon as IPointCollection).AddPoint(inPoint, ref missing, ref missing);
            inPoint = new PointClass();
            inPoint.PutCoords(ipoint_0.X, ipoint_0.Y - this.double_3);
            (polygon as IPointCollection).AddPoint(inPoint, ref missing, ref missing);
            inPoint = new PointClass();
            inPoint.PutCoords(ipoint_0.X + this.double_2, ipoint_0.Y - this.double_3);
            (polygon as IPointCollection).AddPoint(inPoint, ref missing, ref missing);
            inPoint = new PointClass();
            inPoint.PutCoords(ipoint_0.X + this.double_2, ipoint_0.Y);
            (polygon as IPointCollection).AddPoint(inPoint, ref missing, ref missing);
            inPoint = new PointClass();
            inPoint.PutCoords(ipoint_0.X, ipoint_0.Y);
            (polygon as IPointCollection).AddPoint(inPoint, ref missing, ref missing);
            IElement element = new PolygonElementClass
            {
                Geometry = polygon
            };

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

                return(false);
            }
        }
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            m_ActiveView = m_hookHelper.ActiveView;
            m_Map        = m_hookHelper.FocusMap;
            IScreenDisplay    pScreenDisplay = m_ActiveView.ScreenDisplay;
            IRubberBand       pRubberCircle  = new RubberCircleClass();
            ISimpleFillSymbol pFillSymbol    = new SimpleFillSymbolClass();

            pFillSymbol.Color = getRGB(255, 255, 0);
            IGeometry pCircle = pRubberCircle.TrackNew(pScreenDisplay, (ISymbol)pFillSymbol) as IGeometry;

            IConstructCircularArc pConstructArc   = pCircle as IConstructCircularArc;
            IPolygon           pPolygon           = new PolygonClass();
            ISegmentCollection pSegmentCollection = pPolygon as ISegmentCollection;
            ISegment           pSegment           = pConstructArc as ISegment;
            object             missing            = Type.Missing;

            pSegmentCollection.AddSegment(pSegment, ref missing, ref missing);
            pFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross;
            pFillSymbol.Color = getRGB(255, 0, 0);
            IFillShapeElement pPolygonEle = new PolygonElementClass();

            pPolygonEle.Symbol = pFillSymbol;
            IElement pEle = pPolygonEle as IElement;

            pEle.Geometry = pPolygon;
            IGraphicsContainer pGraphicsContainer = m_Map as IGraphicsContainer;

            pGraphicsContainer.AddElement(pEle, 0);
            m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Exemple #14
0
        /// <summary>
        /// 获得指定图层的合并范围 为本次加的一个函数
        /// </summary>
        /// <param name="strLyrName"></param>
        /// <param name="strWhere"></param>
        /// <param name="eFeatureType"></param>
        /// <param name="eGeometryType"></param>
        /// <returns></returns>
        public IGeometry GetLyrUnionPlygon(IList <IFeature> vFeaList)
        {
            if (vFeaList.Count < 1)
            {
                return(null);
            }
            //构造
            IGeometryBag        pGeometryBag = new GeometryBagClass();
            IGeometryCollection pGeometryCol = pGeometryBag as IGeometryCollection;

            object obj = System.Type.Missing;

            //获得所有图形
            for (int i = 0; i < vFeaList.Count; i++)
            {
                if (vFeaList[i].Shape != null && !vFeaList[i].Shape.IsEmpty)
                {
                    pGeometryCol.AddGeometry(vFeaList[i].ShapeCopy, ref obj, ref obj);
                }
            }

            //构造合并
            ITopologicalOperator pTopo = new PolygonClass();

            pTopo.ConstructUnion(pGeometryCol as IEnumGeometry);

            IGeometry pGeometry = pTopo as IGeometry;

            return(pGeometry);
        }
Exemple #15
0
        private IElement method_1()
        {
            object            missing  = System.Type.Missing;
            IPointCollection  points   = null;
            IElement          element  = new PolygonElementClass();
            IFillShapeElement element2 = element as IFillShapeElement;

            new RgbColorClass();
            IGeometry           inGeometry = new RingClass();
            IGeometry           geometry2  = null;
            IGeometryCollection geometrys  = new PolygonClass();
            IGeometry           geometry3  = null;

            points = (IPointCollection)inGeometry;
            points.AddPoint(base.LeftLow, ref missing, ref missing);
            points.AddPoint(base.RightLow, ref missing, ref missing);
            points.AddPoint(base.RightUp, ref missing, ref missing);
            points.AddPoint(base.LeftUp, ref missing, ref missing);
            points.AddPoint(base.LeftLow, ref missing, ref missing);
            geometry2 = this.method_2();
            if (!geometry2.IsEmpty)
            {
                geometrys.AddGeometry(inGeometry, ref missing, ref missing);
                geometrys.AddGeometry(geometry2, ref missing, ref missing);
            }
            geometry3 = geometrys as IGeometry;
            if (!geometry3.IsEmpty)
            {
                geometry3.SpatialReference = geometry2.SpatialReference;
                element.Geometry           = geometry3;
                element2.Symbol            = this.method_7();
            }
            return(element);
        }
Exemple #16
0
        public static IPolygon CreatePolygon([NotNull] IEnumerable <SegmentProxy> segments)
        {
            IGeometryCollection polygon = new PolygonClass();

            CreateGeometry(polygon, segments);
            return((IPolygon)polygon);
        }
        public static IPolygon GeneratePolygon(IGeometry pl)
        {
            if (pl.IsEmpty || (pl is IPolyline) == false)
            {
                return(null);
            }
            var pc1 = (IPointCollection)pl;
            var pg  = new PolygonClass();
            var pc2 = (IPointCollection)pg;

            for (var i = 0; i < pc1.PointCount; i++)
            {
                var pt  = pc1.get_Point(i);
                var pt2 = new PointClass {
                    X = pt.X, Y = pt.Y
                };
                pc2.AddPoint(pt2);
            }

            var pt3 = pc1.get_Point(0);
            var pt4 = new PointClass {
                X = pt3.X, Y = pt3.Y
            };

            pc2.AddPoint(pt4);
            pg.Simplify();
            return(pg);
        }
Exemple #18
0
        private IPolygon method_3()
        {
            IGeometryCollection geometrys = new PolygonClass();
            IRing            inGeometry   = new RingClass();
            IRing            ring2        = new RingClass();
            IPointCollection points       = null;
            IPointCollection points2      = null;
            object           missing      = System.Type.Missing;
            IPoint           inPoint      = new PointClass();
            IPoint           point2       = new PointClass();
            IPoint           point3       = new PointClass();
            IPoint           point4       = new PointClass();

            points = inGeometry as IPointCollection;
            points.AddPoint(base.LeftUp, ref missing, ref missing);
            points.AddPoint(base.RightUp, ref missing, ref missing);
            points.AddPoint(base.RightLow, ref missing, ref missing);
            points.AddPoint(base.LeftLow, ref missing, ref missing);
            inGeometry.Close();
            geometrys.AddGeometry(inGeometry, ref missing, ref missing);
            inPoint.PutCoords(base.LeftUp.X - base.InOutDist, base.LeftUp.Y + base.InOutDist);
            point4.PutCoords(base.LeftLow.X - base.InOutDist, base.LeftLow.Y - base.InOutDist);
            point3.PutCoords(base.RightLow.X + base.InOutDist, base.RightLow.Y - base.InOutDist);
            point2.PutCoords(base.RightUp.X + base.InOutDist, base.RightUp.Y + base.InOutDist);
            points2 = ring2 as IPointCollection;
            points2.AddPoint(inPoint, ref missing, ref missing);
            points2.AddPoint(point2, ref missing, ref missing);
            points2.AddPoint(point3, ref missing, ref missing);
            points2.AddPoint(point4, ref missing, ref missing);
            ring2.Close();
            geometrys.AddGeometry(ring2, ref missing, ref missing);
            return(geometrys as IPolygon);
        }
Exemple #19
0
        /// <summary>
        /// 根据圆心和半径绘制圆
        /// </summary>
        /// <params name="pLayer"></params>
        /// <params name="pPoint"></params>
        /// <params name="circleRadius"></params>
        /// <params name="pScreenDisplay"></params>
        private void DrawCircleByCenterAndRadius(ILayer pLayer, IPoint pPoint, double circleRadius, IScreenDisplay pScreenDisplay)
        {
            if (pLayer != null)
            {
                ISegmentCollection pSegmentCollection = null;
                if (pLayer is IFeatureLayer)
                {
                    IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                    IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                    if (pFeatureClass != null)
                    {
                        if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                        {
                            pSegmentCollection = new PolylineClass();
                        }
                        else if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                        {
                            pSegmentCollection = new PolygonClass();
                        }
                        //开始画圆
                        pSegmentCollection.SetCircle(pPoint, circleRadius);

                        IFeature pCircleFeature = pFeatureClass.CreateFeature();
                        pCircleFeature.Shape = pSegmentCollection as IGeometry;
                        pCircleFeature.Store();
                        //局部刷新
                        IInvalidArea pInvalidArea = new InvalidAreaClass();
                        pInvalidArea.Add(pSegmentCollection);
                        pInvalidArea.Display = pScreenDisplay;
                        pInvalidArea.Invalidate((short)esriScreenCache.esriAllScreenCaches);
                    }
                }
            }
        }
Exemple #20
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            double num    = double.Parse(this.txtXCoor.Text);
            double num2   = double.Parse(this.txtYCoor.Text);
            double radius = double.Parse(this.txtRadio.Text);

            if (this.imap_0.MapUnits != esriUnits.esriKilometers)
            {
                num    *= 1000.0;
                num2   *= 1000.0;
                radius *= 1000.0;
            }
            IPoint centerPoint = new PointClass
            {
                X = num,
                Y = num2
            };
            ICircularArc arc = new CircularArcClass();

            (arc as IConstructCircularArc).ConstructCircle(centerPoint, radius, false);
            ISegmentCollection segments = new PolygonClass();
            object             before   = Missing.Value;

            segments.AddSegment(arc as ISegment, ref before, ref before);
            this.igeometry_0  = segments as IGeometry;
            base.DialogResult = DialogResult.OK;
        }
Exemple #21
0
        public static IGeometryCollection ConstructPolygon(List <IPoint> pointArray)
        {
            //创建一个Ring对象,通过ISegmentCollection接口向其中添加Segment对象
            object             o = Type.Missing;
            ISegmentCollection pSegCollection = new RingClass();

            for (int i = 0; i < pointArray.Count - 1; i++)
            {
                IPoint from = pointArray[i];
                IPoint to   = pointArray[i + 1];

                ILine pLine = new LineClass();
                //设置Line对象的起始终止点
                pLine.PutCoords(from, to);
                //QI到ISegment
                ISegment pSegment = pLine as ISegment;
                pSegCollection.AddSegment(pSegment, ref o, ref o);
            }
            //QI到IRing接口封闭Ring对象,使其有效
            IRing pRing = pSegCollection as IRing;

            pRing.Close();

            //使用Ring对象构建Polygon对象
            IGeometryCollection pGeometryColl = new PolygonClass();

            pGeometryColl.AddGeometry(pRing, ref o, ref o);

            return(pGeometryColl);
        }
Exemple #22
0
        /// <summary>
        /// 多部分(多外环)的多边形转成多个单部分的多边形
        /// </summary>
        /// <param name="polygon"></param>
        /// <returns></returns>
        public static IPolygon[] MultiPartToSinglePart(this IPolygon4 polygon)
        {
            List <IPolygon> polygons = new List <IPolygon>();

            //外部环
            IGeometryBag        exteriorRingGeometryBag        = polygon.ExteriorRingBag;
            IGeometryCollection exteriorRingGeometryCollection = exteriorRingGeometryBag as IGeometryCollection;

            for (int i = 0; i < exteriorRingGeometryCollection.GeometryCount; i++)
            {
                IGeometry exteriorRingGeometry = exteriorRingGeometryCollection.get_Geometry(i);
                IRing     ring = exteriorRingGeometry as IRing;
                ring.Close();
                IGeometryCollection pGeometryColl = new PolygonClass();
                pGeometryColl.AddGeometry(ring);

                //内部环
                IGeometryBag        interiorRingGeometryBag        = polygon.get_InteriorRingBag(exteriorRingGeometry as IRing);
                IGeometryCollection interiorRingGeometryCollection = interiorRingGeometryBag as IGeometryCollection;
                for (int k = 0; k < interiorRingGeometryCollection.GeometryCount; k++)
                {
                    IGeometry interiorRingGeometry = interiorRingGeometryCollection.get_Geometry(k);
                    IRing     ring2 = interiorRingGeometry as IRing;
                    ring2.Close();
                    pGeometryColl.AddGeometry(ring2);
                }

                ITopologicalOperator pTopological = pGeometryColl as ITopologicalOperator;
                pTopological.Simplify();
                IPolygon p = pGeometryColl as IPolygon;
                polygons.Add(p);
            }
            return(polygons.ToArray());
        }
        //public override void JudgeAndFormCEdgeLt()
        //{
        //    if (this.CEdgeLt == null)
        //    {
        //        FormCEdgeLt();
        //    }
        //}


        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        /// <remarks>SetPolygon will first set IPoint</remarks>
        public IPolygon4 SetPolygon()
        {
            //Build a polygon segment-by-segment.
            IPolygon4 polygon = new PolygonClass();

            IGeometryCollection geometryCollection = (IGeometryCollection)polygon;

            var exteriorCptLt = this.CptLt;

            if (CGeoFunc.IsClockwise(exteriorCptLt, true) == false)
            {
                exteriorCptLt = exteriorCptLt.AsEnumerable().Reverse().ToList(); //this will not change this.CptLt
            }

            geometryCollection.AddGeometry(CGeoFunc.GetIrgFromCptLt(exteriorCptLt));
            //add the holes
            if (this.HoleCpgLt != null)
            {
                foreach (var holecpg in this.HoleCpgLt)
                {
                    var interiorCptLt = holecpg.CptLt;
                    if (CGeoFunc.IsClockwise(exteriorCptLt, true) == true)
                    {
                        interiorCptLt = interiorCptLt.AsEnumerable().Reverse().ToList(); //this will not change holecpg.CptLt
                    }
                    geometryCollection.AddGeometry(CGeoFunc.GetIrgFromCptLt(interiorCptLt));
                }
            }
            //polygon.Close();
            this.pPolygon = polygon;
            return(polygon);
        }
Exemple #24
0
        public static IGeometryCollection ConstructPolygon(IPoint[] pointArray)
        {
            //创建一个Ring对象,通过ISegmentCollection接口向其中添加Segment对象
            object             o = Type.Missing;
            ISegmentCollection pSegCollection = new RingClass();

            for (int i = 0; i < pointArray.Length - 1; i++)
            {
                IPoint from = pointArray[i];
                IPoint to   = pointArray[i + 1];

                ILine pLine = new LineClass();
                //设置Line对象的起始终止点
                pLine.PutCoords(from, to);
                //QI到ISegment
                ISegment pSegment = pLine as ISegment;
                pSegCollection.AddSegment(pSegment, ref o, ref o);
            }
            //QI到IRing接口封闭Ring对象,使其有效
            IRing pRing = pSegCollection as IRing;

            pRing.Close();

            //使用Ring对象构建Polygon对象
            IGeometryCollection pGeometryColl = new PolygonClass();

            pGeometryColl.AddGeometry(pRing, ref o, ref o);
            //释放AO对象
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pRing);

            return(pGeometryColl);
        }
Exemple #25
0
 public void FlashElement(IMap pMap, IElement pElement, long lFlashRate, bool bDoubleFlag)
 {
     try
     {
         if ((pMap != null) && (pElement != null))
         {
             if (lFlashRate <= 0L)
             {
                 lFlashRate = 200L;
             }
             IActiveView    view          = pMap as IActiveView;
             IScreenDisplay screenDisplay = view.ScreenDisplay;
             screenDisplay.StartDrawing(screenDisplay.hDC, Convert.ToInt16(esriScreenCache.esriNoScreenCache));
             if (pElement is ILineElement)
             {
                 this.FlashLine(screenDisplay, pElement.Geometry, true, lFlashRate, bDoubleFlag);
             }
             else
             {
                 IPolygon outline = new PolygonClass();
                 pElement.QueryOutline(screenDisplay, outline);
                 this.FlashPolygon(screenDisplay, outline, true, lFlashRate, bDoubleFlag);
             }
             screenDisplay.FinishDrawing();
         }
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.FlashFun", "FlashElement", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
     }
 }
Exemple #26
0
        private IPolygon DissolvePolygon(ISpatialReference spatialRef,
                                         Dictionary <string, IPolygon> originPolygonDict,
                                         string[] originStrArr)
        {
            IGeometry geometryBag   = new GeometryBagClass();
            var       geoCollection = (IGeometryCollection)geometryBag;

            ((IGeometry)geoCollection).SpatialReference = spatialRef;

            for (int i = 0; i < originStrArr.Length; i++)
            {
                var    originStr = originStrArr[i];
                object missing   = Type.Missing;
                //var polygon = (IPolygon)((IClone)originPolygonDict[originStr]).Clone();

                geoCollection.AddGeometry(originPolygonDict[originStr], ref missing, ref missing);
            }

            // 找到的要素合并为一个要素
            IPolygon             outPolygon          = new PolygonClass();
            ITopologicalOperator topologicalOperator = (ITopologicalOperator)outPolygon;

            topologicalOperator.ConstructUnion((IEnumGeometry)geometryBag);

            return(outPolygon);
        }
Exemple #27
0
        private void AddCircleElement(IGeometry pGeo, IActiveView pAv)
        {
            ISegmentCollection pSegColl;

            pSegColl = new PolygonClass();
            object Missing1 = Type.Missing;
            object Missing2 = Type.Missing;

            pSegColl.AddSegment(pGeo as ISegment, ref Missing1, ref Missing2);
            ISimpleLineSymbol pLineSym;

            pLineSym       = new SimpleLineSymbolClass();
            pLineSym.Color = getRGB(110, 22, 125);
            pLineSym.Style = esriSimpleLineStyle.esriSLSSolid;
            pLineSym.Width = 2;
            ISimpleFillSymbol pSimpleFillSym;

            pSimpleFillSym         = new SimpleFillSymbolClass();
            pSimpleFillSym.Color   = getRGB(66, 55, 145);
            pSimpleFillSym.Outline = pLineSym;
            pSimpleFillSym.Style   = esriSimpleFillStyle.esriSFSCross;
            IElement pPolygonEle;

            pPolygonEle          = new CircleElementClass();
            pPolygonEle.Geometry = pSegColl as IGeometry;
            IFillShapeElement pFillEle;

            pFillEle        = pPolygonEle as IFillShapeElement;
            pFillEle.Symbol = pSimpleFillSym;
            IGraphicsContainer pGraphicsContainer;

            pGraphicsContainer = pAv as IGraphicsContainer;
            pGraphicsContainer.AddElement(pFillEle as IElement, 0);
            pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Exemple #28
0
        /// <summary>
        /// 坐标串转换为多边形
        /// </summary>
        /// <param name="xyString"></param>
        /// <returns></returns>
        public static IPolygon ToPolygon(string xyString)
        {
            string[] xyStr  = xyString.Split(';');
            IPoint   pPoint = new PointClass();
            //IPolygon pPolygon1 = new PolygonClass();
            IPointCollection pPointCollection = new PolygonClass();

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

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

            pPolygon = (IPolygon)pPointCollection;
            return(pPolygon);
        }
Exemple #29
0
 /// <summary>
 /// 绘制矩形
 /// </summary>
 /// <params name="pLayer"></params>
 /// <params name="pScreenDisplay"></params>
 private void DrawRectangular(ILayer pLayer, IGeometry pGeo)
 {
     if (pLayer != null)
     {
         ISegmentCollection pSegmentCollection = null;
         if (pLayer is IFeatureLayer)
         {
             IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
             IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
             if (pFeatureClass != null)
             {
                 if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
                 {
                     pSegmentCollection = new PolylineClass();
                 }
                 else if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                 {
                     pSegmentCollection = new PolygonClass();
                 }
                 pSegmentCollection.SetRectangle(pGeo.Envelope);
                 IFeature pFeature = DataEditCommon.CreateUndoRedoFeature(pFeatureLayer, (IGeometry)pSegmentCollection);
                 m_hookHelper.FocusMap.SelectFeature(m_pCurrentLayer, pFeature);
                 m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics | esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewBackground, null, null);
             }
         }
     }
 }
        public void AddCreateElement(IGeometry pCircularArc, IActiveView pAV)

        {
            IFillShapeElement  pElemFillShp;
            IElement           pElem;
            ISimpleFillSymbol  pSFSym;
            ISegmentCollection pSegColl = new PolygonClass();
            object             missing  = Type.Missing;
            ISegment           segement = (ISegment)pCircularArc;

            pSegColl.AddSegment(segement, missing, missing);
            pElem          = new CircleElementClass();
            pElem.Geometry = (IGeometry)pSegColl;
            pElemFillShp   = (IFillShapeElement)pElem;
            pSFSym         = new SimpleFillSymbolClass();
            Color  color  = ColorTranslator.FromHtml(SystemInfo.Instance.FillColor);
            IColor pColor = new RgbColorClass();

            pColor.RGB          = color.B * 65536 + color.G * 256 + color.R;
            pSFSym.Color        = pColor;
            pSFSym.Style        = esriSimpleFillStyle.esriSFSSolid;
            pElemFillShp.Symbol = pSFSym;
            pGraphicsContainer  = pAV as IGraphicsContainer;
            pGraphicsContainer.AddElement(pElem, 0);
        }
Exemple #31
0
        /// <summary>
        /// union几个面要素
        /// </summary>
        /// <param name="lstGeometry">需要操作的面要素集合</param>
        /// <returns>返回union后的图形</returns>
        public static IGeometry GetUnion(List <IGeometry> lstGeometry)
        {
            IGeometryBag        pGeoBag = new GeometryBagClass();
            IGeometryCollection pGeoCol = pGeoBag as IGeometryCollection;

            if (lstGeometry.Count < 1)
            {
                return(null);
            }
            if (lstGeometry[0].SpatialReference != null)
            {
                pGeoBag.SpatialReference = lstGeometry[0].SpatialReference;
            }

            object obj = System.Type.Missing;

            for (int i = 0; i < lstGeometry.Count; i++)
            {
                IGeometry pTempGeo = lstGeometry[i];
                pGeoCol.AddGeometry(pTempGeo, ref obj, ref obj);
            }
            ISpatialIndex pSI = pGeoBag as ISpatialIndex;

            pSI.AllowIndexing = true;
            pSI.Invalidate();

            ITopologicalOperator pTopo = new PolygonClass();

            pTopo.ConstructUnion(pGeoBag as IEnumGeometry);
            IGeometry pGeo = pTopo as IGeometry;

            return(pGeo);
        }
Exemple #32
0
        private IPolygon GeneratePolygonFromRing(Ring ring)
        {
            IGeometryCollection pointPolygon = new PolygonClass();
            object missing = Type.Missing;  
            pointPolygon.AddGeometry(ring as IGeometry, ref missing, ref missing);
            IPolygon polyGonGeo = pointPolygon as IPolygon;
            polyGonGeo.SimplifyPreserveFromTo();

            return polyGonGeo;
        }
        //圆弧(线)转圆几何
        public static IGeometry GetCircleGeometry(ICircularArc pCircularArc)
        {
            ISegmentCollection pSegmentCollection = new PolygonClass();
            object missing1 = System.Type.Missing;
            object missing2 = System.Type.Missing;
            pSegmentCollection.AddSegment(pCircularArc as ISegment, ref missing1, ref missing2);


            IGeometry pGeometry = pSegmentCollection as IGeometry;
            return pGeometry;
        }
        //圆弧(线)转多边形(圆)
        public static IPolygon CircularArcToPolygon(ICircularArc pCircularArc)
        {
            ISegmentCollection pSegmentCollection = new PolygonClass();
            object missing1 = System.Type.Missing;
            object missing2 = System.Type.Missing;
            pSegmentCollection.AddSegment(pCircularArc as ISegment, ref missing1, ref missing2);


            IPolygon pPolygon = pSegmentCollection as IPolygon;
            return pPolygon;
        }
        private IGeometry GetGeometry(ISpatialReference spatialReference)
        {
            IGeometry geometry;

            IPolygon polygon = new PolygonClass();

            polygon.SpatialReference = spatialReference;

            geometry = polygon as IGeometry;

            MakeZAware(geometry);

            return geometry;
        }
 private IPolygon FlatBuffer(IPolyline pLline1, double pBufferDis)
 {
     object o = System.Type.Missing;
      //分别对输入的线平移两次(正方向和负方向)
      IConstructCurve pCurve1 = new PolylineClass();
      pCurve1.ConstructOffset(pLline1, pBufferDis, ref o, ref o);
      IPointCollection pCol = pCurve1 as IPointCollection;
      IConstructCurve pCurve2 = new PolylineClass();
      pCurve2.ConstructOffset(pLline1, -1 * pBufferDis, ref o, ref o);
      //把第二次平移的线的所有节点翻转
      IPolyline pline2 = pCurve2 as IPolyline;
      pline2.ReverseOrientation();
      //把第二条的所有节点放到第一条线的IPointCollection里面
      IPointCollection pCol2 = pline2 as IPointCollection;
      pCol.AddPointCollection(pCol2);
      //用面去初始化一个IPointCollection
      IPointCollection pPointCol = new PolygonClass();
      pPointCol.AddPointCollection(pCol);
      //把IPointCollection转换为面
      IPolygon pPolygon = pPointCol as IPolygon;
      //简化节点次序
      pPolygon.SimplifyPreserveFromTo();
      return pPolygon;
 }
        public static IGeometry GetExample4()
        {
            const double CircleDegrees = 360.0;
            const int CircleDivisions = 18;
            const double VectorComponentOffset = 0.0000001;
            const double InnerBuildingRadius = 3.0;
            const double OuterBuildingExteriorRingRadius = 9.0;
            const double OuterBuildingInteriorRingRadius = 6.0;
            const double BaseZ = 0.0;
            const double InnerBuildingZ = 16.0;
            const double OuterBuildingZ = 6.0;

            //Composite: Tall Building Protruding Through Outer Ring-Shaped Building

            IMultiPatch multiPatch = new MultiPatchClass();

            IGeometryCollection multiPatchGeometryCollection = multiPatch as IGeometryCollection;

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

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

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

            lowerAxisVector3D.XComponent += VectorComponentOffset;

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

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

            //Inner Building

            IGeometry innerBuildingBaseGeometry = new PolygonClass();

            IPointCollection innerBuildingBasePointCollection = innerBuildingBaseGeometry as IPointCollection;

            //Outer Building

            IGeometry outerBuildingBaseGeometry = new PolygonClass();

            IGeometryCollection outerBuildingBaseGeometryCollection = outerBuildingBaseGeometry as IGeometryCollection;

            IPointCollection outerBuildingBaseExteriorRingPointCollection = new RingClass();

            IPointCollection outerBuildingBaseInteriorRingPointCollection = new RingClass();

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

                //Inner Building

                normalVector3D.Magnitude = InnerBuildingRadius;

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

                innerBuildingBasePointCollection.AddPoint(innerBuildingBaseVertexPoint, ref _missing, ref _missing);

                //Outer Building

                //Exterior Ring

                normalVector3D.Magnitude = OuterBuildingExteriorRingRadius;

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

                outerBuildingBaseExteriorRingPointCollection.AddPoint(outerBuildingBaseExteriorRingVertexPoint, ref _missing, ref _missing);

                //Interior Ring

                normalVector3D.Magnitude = OuterBuildingInteriorRingRadius;

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

                outerBuildingBaseInteriorRingPointCollection.AddPoint(outerBuildingBaseInteriorRingVertexPoint, ref _missing, ref _missing);
            }

            IPolygon innerBuildingBasePolygon = innerBuildingBaseGeometry as IPolygon;
            innerBuildingBasePolygon.Close();

            IRing outerBuildingBaseExteriorRing = outerBuildingBaseExteriorRingPointCollection as IRing;
            outerBuildingBaseExteriorRing.Close();

            IRing outerBuildingBaseInteriorRing = outerBuildingBaseInteriorRingPointCollection as IRing;
            outerBuildingBaseInteriorRing.Close();
            outerBuildingBaseInteriorRing.ReverseOrientation();

            outerBuildingBaseGeometryCollection.AddGeometry(outerBuildingBaseExteriorRing as IGeometry, ref _missing, ref _missing);
            outerBuildingBaseGeometryCollection.AddGeometry(outerBuildingBaseInteriorRing as IGeometry, ref _missing, ref _missing);

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

            IConstructMultiPatch innerBuildingConstructMultiPatch = new MultiPatchClass();
            innerBuildingConstructMultiPatch.ConstructExtrudeFromTo(BaseZ, InnerBuildingZ, innerBuildingBaseGeometry);

            IGeometryCollection innerBuildingMultiPatchGeometryCollection = innerBuildingConstructMultiPatch as IGeometryCollection;

            for (int i = 0; i < innerBuildingMultiPatchGeometryCollection.GeometryCount; i++)
            {
                multiPatchGeometryCollection.AddGeometry(innerBuildingMultiPatchGeometryCollection.get_Geometry(i), ref _missing, ref _missing);
            }

            IConstructMultiPatch outerBuildingConstructMultiPatch = new MultiPatchClass();
            outerBuildingConstructMultiPatch.ConstructExtrudeFromTo(BaseZ, OuterBuildingZ, outerBuildingBaseGeometry);

            IMultiPatch outerBuildingMultiPatch = outerBuildingConstructMultiPatch as IMultiPatch;

            IGeometryCollection outerBuildingMultiPatchGeometryCollection = outerBuildingConstructMultiPatch as IGeometryCollection;

            for (int i = 0; i < outerBuildingMultiPatchGeometryCollection.GeometryCount; i++)
            {
                IGeometry outerBuildingPatchGeometry = outerBuildingMultiPatchGeometryCollection.get_Geometry(i);

                multiPatchGeometryCollection.AddGeometry(outerBuildingPatchGeometry, ref _missing, ref _missing);

                if (outerBuildingPatchGeometry.GeometryType == esriGeometryType.esriGeometryRing)
                {
                    bool isBeginningRing = false;

                    esriMultiPatchRingType multiPatchRingType = outerBuildingMultiPatch.GetRingType(outerBuildingPatchGeometry as IRing, ref isBeginningRing);

                    multiPatch.PutRingType(outerBuildingPatchGeometry as IRing, multiPatchRingType);
                }
            }

            return multiPatchGeometryCollection as IGeometry;            
        }
        /// <summary>
        /// The display rectangle.
        /// </summary>
        /// <param name="activeView">
        /// The active view.
        /// </param>
        /// <param name="elm">
        /// The elm.
        /// </param>
        /// <returns>
        /// The <see cref="IPolygon"/>.
        /// </returns>
        public static IPolygon DisplayRectangle(IActiveView activeView, out IElement elm)
        {
            ISegmentCollection segmentCollection = new PolygonClass();

            var tempEnvelope = activeView.Extent;
            CapEnvelope(ref tempEnvelope);
            segmentCollection.SetRectangle(tempEnvelope);

            var polygon = (IPolygon)segmentCollection;
            var rgbColor = VectorIndexColor();
            elm = AddGraphicToMap(activeView.FocusMap, polygon, rgbColor, rgbColor);

            //Best practice: Redraw only the portion of the active view that contains graphics.
            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            return polygon;
        }
        /// <summary>
        /// 回采进尺更新
        /// </summary>
        /// <params name="hd1">主巷道ID</params>
        /// <params name="hd2">辅助巷道ID</params>
        /// <params name="hd3">切眼巷道ID</params>
        /// <params name="Bid">要修改的回采对象的BID</params>
        /// <params name="hccd">回采的尺度</params>
        /// <params name="search">查询附近地质构造的距离</params>
        /// <returns></returns>
        public Dictionary<string, IPoint> UpdateHCCD(string hd1, string hd2, string hd3, string Bid, double hccd, double zywid, double fywid, double qywid, double search = 0)
        {
            Dictionary<string, IPoint> respnts = new Dictionary<string, IPoint>();

            Dictionary<string, string> hdids = new Dictionary<string, string>();
            hdids.Add(GIS_Const.FIELD_HDID, hd1);
            List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selobjs1 = Global.commonclss.SearchFeaturesByGeoAndText(Global.centerlyr, hdids);
            IPolyline pline1 = selobjs1[0].Item2 as IPolyline;

            hdids[GIS_Const.FIELD_HDID] = hd2;
            List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selobjs2 = Global.commonclss.SearchFeaturesByGeoAndText(Global.centerlyr, hdids);
            IPolyline pline2 = selobjs2[0].Item2 as IPolyline;

            hdids[GIS_Const.FIELD_HDID] = hd3;
            List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selobjs3 = Global.commonclss.SearchFeaturesByGeoAndText(Global.centerlyr, hdids);
            IPolyline pline3 = selobjs3[0].Item2 as IPolyline;
            hdids[GIS_Const.FIELD_HDID] = hd1 + "_" + hd2;
            IPointCollection pntcol = new PolygonClass();

            //查询对应的回采进尺的面
            IFeatureClass feaclss = Global.hcqlyr.FeatureClass;
            IWorkspaceEdit wks = (feaclss as IDataset).Workspace as IWorkspaceEdit;
            wks.StartEditing(false);
            wks.StartEditOperation();

            string sql = "\"" + GIS_Const.FIELD_HDID + "\"='" + hdids[GIS_Const.FIELD_HDID] + "' AND \"" + GIS_Const.FIELD_BS + "\"=0 AND " + GIS_Const.FIELD_BID + "='" + Bid + "'";
            IQueryFilter queryfilter = new QueryFilterClass();
            queryfilter.WhereClause = sql;
            IFeatureCursor hdhc_cursors = feaclss.Update(queryfilter, false);
            IFeature hdhc_fea = hdhc_cursors.NextFeature();
            if (hdhc_fea == null)
            {
                MessageBox.Show("没有找到对应的回采进尺空间信息,请检查数据库和地图!", "系统提示");
                return null;
            }
            else
            {
                //修改当前的回采进尺
                List<IPoint> pnthccols = new List<IPoint>();

                IPolygon hcpolygon = hdhc_fea.Shape as IPolygon;
                Dictionary<string, List<IPoint>> oldpnts = Global.commonclss.getCoordinates(hcpolygon, pline1, pline2, pline3, zywid, fywid);
                if (oldpnts.Count == 0)
                    return null;
                IPointCollection pts = hcpolygon as IPointCollection;
                //IPoint ptstart = pts.get_Point(0);
                //IPoint ptend = pts.get_Point(pts.PointCount-1);
                IPoint ptstart = oldpnts["2"][1];
                IPoint ptend = oldpnts["2"][0];
                IPoint ptcenter = new PointClass();
                ptcenter.X = (ptstart.X + ptend.X) / 2;
                ptcenter.Y = (ptstart.Y + ptend.Y) / 2;
                //原始中心点的坐标
                IPoint ptcenter1 = new PointClass();
                //ptcenter1.X = (pts.get_Point(1).X + pts.get_Point(2).X) / 2;
                //ptcenter1.Y = (pts.get_Point(1).Y + pts.get_Point(2).Y) / 2;
                ptcenter1.X = (oldpnts["1"][0].X + oldpnts["1"][1].X) / 2;
                ptcenter1.Y = (oldpnts["1"][0].Y + oldpnts["1"][1].Y) / 2;

                //设置回采移动的切眼
                int dirflag = Global.commonclss.GetDirectionByPnt(pline3, ptcenter);
                IPolyline pline3new = new PolylineClass();
                pline3new.FromPoint = oldpnts["2"][0];
                pline3new.ToPoint = oldpnts["2"][1];
                pntcol = Global.hcjsclass.GetBackPolygonArea(pline1, pline2, pline3new, zywid, fywid, qywid, hccd, dirflag);
                if (pntcol != null)
                {
                    Dictionary<string, string> dics = new Dictionary<string, string>();
                    for (int i = 0; i < pntcol.PointCount - 1; i++)
                    {
                        pnthccols.Add(pntcol.get_Point(i));
                    }
                    IPolygon polygon = Global.commonclss.CreatePolygonFromPnts(pnthccols, Global.spatialref);
                    hdhc_fea.Shape = polygon;
                    hdhc_cursors.UpdateFeature(hdhc_fea);

                    IPoint prevHcPoint = pntcol.get_Point(pntcol.PointCount - 1);
                    prevHcPoint.Z = 0.0;
                    //将当前的回采中心点添加到结果集中,以备更新数据库表中的workingface表
                    respnts.Add(Bid, prevHcPoint);
                    //更新导线点图层中的点
                    //Global.commonclss.UpdateFeature(sql, prevHcPoint, Global.pntlyr);
                    //平移或缩放后面的回采进尺面
                    double xdeta = prevHcPoint.X - ptcenter1.X;
                    double ydeta = prevHcPoint.Y - ptcenter1.Y;
                    int xhpos = hdhc_fea.Fields.FindField(GIS_Const.FIELD_XH);
                    int xh = Convert.ToInt32(hdhc_fea.get_Value(xhpos));
                    Marshal.ReleaseComObject(hdhc_cursors);
                    //string sql_hdfull = "\""+GIS.GIS_Const.FIELD_HDID+"\"='" + hdids[GIS.GIS_Const.FIELD_HDID] + "' AND \""+GIS.GIS_Const.FIELD_BS+"\"=0 AND "+GIS.GIS_Const.FIELD_XH+">" + xh.ToString();
                    string sql_hdfull = "\"HdId\"='" + hdids[GIS_Const.FIELD_HDID] + "' AND \"" + GIS_Const.FIELD_BS + "\"=0 AND " + GIS_Const.FIELD_XH + ">" + xh.ToString();
                    IQueryFilter queryfilter1 = new QueryFilterClass();
                    queryfilter1.WhereClause = sql_hdfull;
                    queryfilter1.SubFields = "*";
                    IFeatureCursor otherhcursor = feaclss.Update(queryfilter1, false);
                    IFeature fea_hc = otherhcursor.NextFeature();
                    int bidpos = otherhcursor.FindField(GIS_Const.FIELD_BID);
                    while (fea_hc != null)
                    {
                        IPolygon reg = fea_hc.Shape as IPolygon;
                        ITransform2D trans = reg as ITransform2D;
                        trans.Move(xdeta, ydeta);
                        fea_hc.Shape = reg;
                        otherhcursor.UpdateFeature(fea_hc);
                        //将工作面的中心点坐标保存到集合中
                        IPointCollection ptsothers = reg as IPointCollection;
                        IPoint ptothercenter = new PointClass();
                        Dictionary<string, List<IPoint>> otherpnts = Global.commonclss.getCoordinates(reg, pline1, pline2, pline3, zywid, fywid);
                        //ptothercenter.X = (ptsothers.get_Point(pts.PointCount - 3).X + ptsothers.get_Point(pts.PointCount - 2).X) / 2;
                        //ptothercenter.Y = (ptsothers.get_Point(pts.PointCount - 3).Y + ptsothers.get_Point(pts.PointCount - 2).Y) / 2;
                        ptothercenter.X = (otherpnts["1"][0].X + otherpnts["1"][1].X) / 2;
                        ptothercenter.Y = (otherpnts["1"][0].Y + otherpnts["1"][1].Y) / 2;
                        ptothercenter.Z = 0.0;
                        string bidval = fea_hc.get_Value(bidpos).ToString();
                        respnts.Add(bidval, ptothercenter);
                        //更新导线点图层
                        //Global.commonclss.UpdateFeature(sql_hdfull, ptothercenter, Global.pntlyr);
                        fea_hc = otherhcursor.NextFeature();
                    }
                    Marshal.ReleaseComObject(otherhcursor);
                }
            }
            Global.pActiveView.Refresh();
            return respnts;
            //将获得的点写入到工作面表中
        }
        /// <summary>
        /// ���Ƽ���ͼ��
        /// </summary>
        /// <params name="geoType"></params>
        /// <params name="geometry"></params>
        /// <returns></returns>
        ESRI.ArcGIS.Carto.IElement createElement_x(ESRI.ArcGIS.Geometry.IGeometry geometry)
        {
            IElement element = null;
            try
            {
                switch (geometry.GeometryType)
                {
                    case esriGeometryType.esriGeometryPolygon:
                        IFillShapeElement pPolygonElement;
                        ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass();
                        IPolygon pPolygon = new PolygonClass();
                        IRubberBand pRubberBand = new RubberPolygonClass();
                        ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
                        pPolygonElement = new PolygonElementClass();

                        //if (e.button == 1)
                        //{
                        //   pPolygon=(IPolygon) pRubberBand.TrackNew(axMapControl1.ActiveView.ScreenDisplay, null);
                        //}
                        pSimpleLineSymbol.Width = 2;
                        pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
                        pSimpleLineSymbol.Color = TransColorToAEColor(Color.Blue);

                        //pSimpleFillSymbol.Color = GetRGBColor(11, 200, 145);
                        pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSNull;
                        pSimpleFillSymbol.Outline = pSimpleLineSymbol;
                        IElement pElement = (IElement)pPolygonElement;
                        pElement.Geometry = geometry;
                        pPolygonElement.Symbol = pSimpleFillSymbol;

                        element = (IElement)pPolygonElement;
                        break;
                    case esriGeometryType.esriGeometryPolyline://Polyline��
                        ISimpleLineSymbol simpleLineSymbol = m_NewPolygonFeedback.Symbol as ISimpleLineSymbol;

                        ILineElement lineElement = new LineElementClass();
                        lineElement.Symbol = simpleLineSymbol as ILineSymbol;
                        element = lineElement as IElement;
                        element.Geometry = geometry;
                        break;
                    case esriGeometryType.esriGeometryPoint:
                        //���ý�����
                        IRgbColor pRGB = new RgbColorClass();
                        pRGB.Red = 255;
                        pRGB.Green = 0;
                        pRGB.Blue = 0;

                        ISimpleMarkerSymbol pSimpleMarkSymbol = new SimpleMarkerSymbolClass();
                        pSimpleMarkSymbol.Color = pRGB as IColor;
                        pSimpleMarkSymbol.Size = 2;
                        pSimpleMarkSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;

                        IMarkerElement pMarkerElement = new MarkerElementClass();
                        pMarkerElement.Symbol = pSimpleMarkSymbol as IMarkerSymbol;
                        element = pMarkerElement as IElement;
                        element.Geometry = geometry as IGeometry;
                        break;
                }
            }
            catch
            { }
            return element;
        }
Exemple #41
0
        private void Coordinate_Load(object sender, EventArgs e)
        {
            //定义点集环形
            Ring ring1 = new RingClass();
            object missing = Type.Missing;
            //新建一个datatable用于保存读入的数据
            DataTable dt = new DataTable();
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Multiselect = false;    //单选
            ofd.Title = "选择坐标文件";
            ofd.Filter = "txt文件|*.txt";
            // ofd.InitialDirectory = Environment.SpecialFolder.Desktop.ToString();
            ofd.InitialDirectory = SystemSet.Base_Map + "\\处理数据库\\坐标数据";

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                //IGeometryCollection pointPolygon = new PolygonClass();
                FileInfo fi = new FileInfo(ofd.FileName);
                try
                {
                    paths1 = ofd.FileName;
                    lengh = paths1.Length - ofd.InitialDirectory.Length;
                    String paths = ofd.FileName;

                    int i = 0;
                    //给datatable添加5个列
                    dt.Columns.Add("编号", typeof(int));
                    dt.Columns.Add("坐标X", typeof(double));
                    dt.Columns.Add("坐标Y", typeof(double));
                    dt.Columns.Add("高程Z", typeof(double));
                    dt.Columns.Add("日期", typeof(string));
                    //读入文件
                    StreamReader sr = new StreamReader(paths, Encoding.Default);

                    //循环读取所有行
                    while (!sr.EndOfStream)//(line = sr.ReadLine()) != null)
                    {
                        i++;
                        //将每行数据,用-分割成2段
                        //sr.ReadLine().TrimStart();//消除前面空格
                        //sr.ReadLine().TrimEnd();//消除尾部空格
                        string[] data = sr.ReadLine().Split(',', ' ');
                        //新建一行,并将读出的数据分段,分别存入5个对应的列中
                        DataRow dr = dt.NewRow();
                        dr[0] = i;
                        dr[1] = data[0];
                        dr[2] = data[1];
                        dr[3] = 0;
                        dr[4] = DateTime.Now.ToLongDateString().ToString();
                        //将这行数据加入到datatable中
                        dt.Rows.Add(dr);
                        //点上生成面
                        IPoint ppp = new PointClass();
                        ppp.PutCoords((double)dr[1], (double)dr[2]);
                        ring1.AddPoint(ppp, ref missing, ref missing);
                        //调用画点工具
                        GISHandler.GISTools.CreatPoint(this.mapControl, (double)dr[1], (double)dr[2], i);
                    }
                }
                catch
                {
                    MessageBox.Show("坐标文件内容错误!请检查格式是否为:x,y或者x y");
                    return;
                }
                IGeometryCollection pointPolygon = new PolygonClass();
                pointPolygon.AddGeometry(ring1 as IGeometry, ref missing, ref missing);
                IPolygon polyGonGeo = pointPolygon as IPolygon;
                ply = polyGonGeo;
                polyGonGeo.SimplifyPreserveFromTo();
                //object miss = Type.Missing;
                //this.mapControl.DrawShape(polyGonGeo, ref miss);

            }
            else
                this.Close();
            gridControl1.DataSource = dt;
            dataGridView1.DataSource = dt;
            gridView1.OptionsView.ShowGroupPanel = false;
        }
        /// <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 IPolygon GetPolygon()
        {
            IPolygon polygon2 = null;
            ILayer pLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MINE_BOUNDARY);
            IFeatureLayer polygonLayer = (IFeatureLayer)pLayer;

            IQueryFilter filter = new QueryFilterClass();
            filter.WhereClause = "layer = '预警矿界'";

            IFeatureLayer featureLayer = polygonLayer as IFeatureLayer;
            IFeatureCursor featureCursor = featureLayer.Search(filter, false);
            ITopologicalOperator2 topologicalOperator = null;

            //  获得矿界组合成面
            if (featureCursor != null)
            {
                ISegmentCollection polygon = new PolygonClass();

                IFeature feature = featureCursor.NextFeature();

                while (feature != null)
                {
                    polygon.AddSegmentCollection((ISegmentCollection)feature.Shape);
                    feature = featureCursor.NextFeature();
                }

                topologicalOperator = (ITopologicalOperator2)polygon;
                topologicalOperator.IsKnownSimple_2 = true;
                topologicalOperator.Simplify();

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

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

            return poly;
        }
        /// <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();
            //}
        }
Exemple #46
0
        private IGeometry BuildWorkingGeometry(GpxFeatureClass featureClass)
        {
            IGeometry result = null;

            if (featureClass.GeometryType == esriGeometryType.esriGeometryPoint)
                result = new PointClass();
            if (featureClass.GeometryType == esriGeometryType.esriGeometryPolyline)
                result = new PolylineClass();
            if (featureClass.GeometryType == esriGeometryType.esriGeometryPolygon)
                result = new PolygonClass();

            if (result == null)
                throw new ArgumentException("Geometry type must be Point/Polyline/Polygon", "featureClass");

            result.SpatialReference = SpatialReference;
            return result;
        }
        /// <summary>
        /// 回采进尺更新
        /// </summary>
        /// <params name="hd1">主巷道ID</params>
        /// <params name="hd2">辅助巷道ID</params>
        /// <params name="hd3">切眼巷道ID</params>
        /// <params name="Bid">要修改的回采对象的BID</params>
        /// <params name="hccd">回采的尺度</params>
        /// <params name="search">查询附近地质构造的距离</params>
        /// <returns></returns>
        public Dictionary<string, IPoint> DelHCCD(string hd1, string hd2, string hd3, string Bid, double zywid, double fywid, double search = 0)
        {
            Dictionary<string, IPoint> respnts = new Dictionary<string, IPoint>();

            Dictionary<string, string> hdids = new Dictionary<string, string>();
            hdids.Add(GIS_Const.FIELD_HDID, hd1);
            List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selobjs1 = Global.commonclss.SearchFeaturesByGeoAndText(Global.centerlyr, hdids);
            if (selobjs1.Count > 0)
            {
                IPolyline pline1 = selobjs1[0].Item2 as IPolyline;

                hdids[GIS_Const.FIELD_HDID] = hd2;
                List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selobjs2 = Global.commonclss.SearchFeaturesByGeoAndText(Global.centerlyr, hdids);
                IPolyline pline2 = selobjs2[0].Item2 as IPolyline;

                hdids[GIS_Const.FIELD_HDID] = hd3;
                List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selobjs3 = Global.commonclss.SearchFeaturesByGeoAndText(Global.centerlyr, hdids);
                IPolyline pline3 = selobjs3[0].Item2 as IPolyline;
                hdids[GIS_Const.FIELD_HDID] = hd1 + "_" + hd2;
                IPointCollection pntcol = new PolygonClass();

                //查询对应的回采进尺的面
                IFeatureClass feaclss = Global.hcqlyr.FeatureClass;
                IWorkspaceEdit wks = (feaclss as IDataset).Workspace as IWorkspaceEdit;
                wks.StartEditing(false);
                wks.StartEditOperation();

                string sql = "\"" + GIS_Const.FIELD_HDID + "\"='" + hdids[GIS_Const.FIELD_HDID] + "' AND \"" + GIS_Const.FIELD_BS + "\"=0 AND " + GIS_Const.FIELD_BID + "='" + Bid + "'";
                IQueryFilter queryfilter = new QueryFilterClass();
                queryfilter.WhereClause = sql;
                IFeatureCursor hdhc_cursors = feaclss.Update(queryfilter, true);
                IFeature hdhc_fea = hdhc_cursors.NextFeature();

                int bidpos = hdhc_cursors.FindField(GIS_Const.FIELD_BID);

                if (hdhc_fea == null)
                {
                    MessageBox.Show("没有找到对应的回采进尺空间信息,请检查数据库和地图!", "系统提示");
                    return null;
                }
                else
                {
                    //修改当前的回采进尺
                    List<IPoint> pnthccols = new List<IPoint>();
                    IPolygon hcpolygon = hdhc_fea.Shape as IPolygon;

                    Dictionary<string, List<IPoint>> oldpnts = Global.commonclss.getCoordinates(hcpolygon, pline1, pline2, pline3, zywid, fywid);
                    if (oldpnts.Count == 0)
                        return null;
                    IPoint ptstart = oldpnts["2"][1];
                    IPoint ptend = oldpnts["2"][0];
                    IPoint ptcenter = new PointClass();
                    ptcenter.X = (ptstart.X + ptend.X) / 2;
                    ptcenter.Y = (ptstart.Y + ptend.Y) / 2;

                    //原始中心点的坐标
                    IPoint ptcenter1 = new PointClass();
                    //ptcenter1.X = (pts.get_Point(1).X + pts.get_Point(2).X) / 2;
                    //ptcenter1.Y = (pts.get_Point(1).Y + pts.get_Point(2).Y) / 2;
                    ptcenter1.X = (oldpnts["1"][0].X + oldpnts["1"][1].X) / 2;
                    ptcenter1.Y = (oldpnts["1"][0].Y + oldpnts["1"][1].Y) / 2;

                    // 平移或缩放后的回采进尺
                    double xdeta = ptcenter.X - ptcenter1.X;
                    double ydeta = ptcenter.Y - ptcenter1.Y;
                    //将当前的回采中心点添加到结果集中,以备更新数据库表中的workingface表
                    string bidval0 = hdhc_fea.get_Value(bidpos).ToString();
                    IPoint centerpt = new PointClass();
                    centerpt.X = ptcenter1.X + xdeta;
                    centerpt.Y = ptcenter1.Y + ydeta;
                    centerpt.Z = 0.0;
                    respnts.Add(bidval0, centerpt);

                    //更新导线点图层中的点
                    int xhpos = hdhc_fea.Fields.FindField(GIS_Const.FIELD_XH);
                    int xh = Convert.ToInt32(hdhc_fea.get_Value(xhpos));
                    hdhc_fea.Delete();

                    string sql_hdfull = "\"" + GIS_Const.FIELD_HDID + "\"='" + hdids[GIS_Const.FIELD_HDID] + "' AND \"" + GIS_Const.FIELD_BS + "\"=0 AND " + GIS_Const.FIELD_XH + ">" + xh.ToString();
                    IQueryFilter queryfilter1 = new QueryFilterClass();
                    queryfilter1.WhereClause = sql_hdfull;
                    IFeatureCursor otherhcursor = feaclss.Update(queryfilter1, true);
                    IFeature fea_hc = otherhcursor.NextFeature();

                    while (fea_hc != null)
                    {
                        IPolygon reg = fea_hc.Shape as IPolygon;
                        ITransform2D trans = reg as ITransform2D;
                        trans.Move(xdeta, ydeta);
                        fea_hc.Shape = reg;
                        otherhcursor.UpdateFeature(fea_hc);
                        //将工作面的中心点坐标保存到集合中
                        IPointCollection ptsothers = reg as IPointCollection;
                        IPoint ptothercenter = new PointClass();
                        ptothercenter.X = (ptsothers.get_Point(1).X + ptsothers.get_Point(2).X) / 2;
                        ptothercenter.Y = (ptsothers.get_Point(1).Y + ptsothers.get_Point(2).Y) / 2;
                        ptothercenter.Z = 0.0;
                        string bidval = fea_hc.get_Value(bidpos).ToString();
                        respnts.Add(bidval, ptothercenter);
                        //更新导线点图层
                        //Global.commonclss.UpdateFeature(sql_hdfull, ptothercenter, Global.pntlyr);
                        fea_hc = otherhcursor.NextFeature();
                    }
                    Marshal.ReleaseComObject(otherhcursor);
                }
                Marshal.ReleaseComObject(hdhc_cursors);
                wks.StopEditOperation();
                wks.StopEditing(true);
            }
            Global.pActiveView.Refresh();
            return respnts;
            //将获得的点写入到工作面表中
        }
Exemple #48
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;
        }
Exemple #49
0
        private IElement DrawCircle(double radius, double x, double y)
        {
            IPoint centralPoint = new PointClass();
            centralPoint.PutCoords(x, y);
            // 创建园
            ICircularArc circularArc = new CircularArcClass();
            IConstructCircularArc construtionCircularArc = circularArc as IConstructCircularArc;
            construtionCircularArc.ConstructCircle(centralPoint, radius, true);

            ISegment pSegment1 = circularArc as ISegment;
            //通过ISegmentCollection构建Ring对象
            ISegmentCollection pSegCollection = new RingClass();
            object o = Type.Missing;
            //添加Segement对象即圆
            pSegCollection.AddSegment(pSegment1, ref o, ref o);

            //QI到IRing接口封闭Ring对象,使其有效
            IRing pRing = pSegCollection as IRing;
            pRing.Close();
            //通过Ring对象使用IGeometryCollection构建Polygon对象
            IGeometryCollection pGeometryColl = new PolygonClass();
            pGeometryColl.AddGeometry(pRing, ref o, ref o);
            //构建一个CircleElement对象
            IElement pElement = new CircleElementClass();
            pElement.Geometry = pGeometryColl as IGeometry;

            IFillShapeElement pFillShapeElement = pElement as IFillShapeElement;

            ISimpleFillSymbol pFillSymbol = new SimpleFillSymbolClass();
            //pFillSymbol.Color = pCircleColor;
            ILineSymbol pLineSymbol = new SimpleLineSymbolClass();

              //  pLineSymbol.Color = DefineColor(0, 255, 0);
            pFillSymbol.Outline = pLineSymbol;

            pFillShapeElement.Symbol = pFillSymbol;

            IFillShapeElement circleElement = pElement as IFillShapeElement;
            circleElement.Symbol = pFillSymbol;
            IGraphicsContainer pGC = this.axMapControl.ActiveView.GraphicsContainer;
            pGC.AddElement(pElement, 0);
            axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            return pElement;
        }
Exemple #50
0
        /// <summary>
        /// 画线
        /// </summary>
        internal void FlashFeature()
        {
            IPoint point1 = new PointClass();
            //point1.PutCoords(101, 40);
            point1 = GetProject2(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));
            IPoint point2 = new PointClass();
            //point2.PutCoords(110, 40);
            point2 = GetProject2(-120, 40);
            //IPoint point3 = new PointClass();
            //point3.PutCoords(112, 40);

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

            IElement element = new PolygonElementClass();
            element.Geometry = polygon;
            IGraphicsContainer graphicsContainer = axMapControl.Map as IGraphicsContainer;
            graphicsContainer.AddElement(element, 0);
            axMapControl.Refresh();
        }
Exemple #51
0
Fichier : 1.cs Projet : trainsn/LBS
        /// <summary>
        /// 从导入的坐标串中生成草图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void biImportToGraphic_ItemClick(object sender, ItemClickEventArgs e)
        {
            string filePath = "";
            object pbefore = Type.Missing;
            object pafter = Type.Missing;
            OpenFileDialog openDlg = new OpenFileDialog();
            openDlg.Filter = "Text files(*.txt)|*.txt";

            IPointCollection ipPoitCol = null;
            IGeometry iGeo = null;
            try
            {
                if (_subType == 1)
                {
                    ipPoitCol = new PolylineClass();
                }
                else if(_subType == 2)
                {
                    ipPoitCol = new PolygonClass();
                }

                if (openDlg.ShowDialog() == DialogResult.OK)
                {
                    filePath = openDlg.FileName;
                    StreamReader strRead = new StreamReader(filePath);
                    string strLine;
                    int RowCou = 0;
                    string strX = string.Empty;
                    string strY = string.Empty;
                    string[] strCoor = new string[2];
                    while ((strLine = strRead.ReadLine()) != null)
                    {
                        if (strLine != "")
                        {
                            RowCou++;
                            strCoor = strLine.Split(',');
                            double x = double.Parse(strCoor[0]);
                            double y = double.Parse(strCoor[1]);
                            if (RowCou == 1)
                            {
                                strX = strCoor[0];
                                strY = strCoor[1];
                            }
                            IPoint ipNewPoint = new PointClass();
                            ipNewPoint.PutCoords(x, y);
                            ipPoitCol.AddPoint(ipNewPoint, ref pbefore, ref pafter);
                        }
                    }
                    //如果第一个点和最后一个点不等,则再加一遍一个点的坐标
                    if (strX != strCoor[0] && strY != strCoor[1])
                    {
                        IPoint ipPoint = new PointClass();
                        ipPoint.PutCoords(double.Parse(strCoor[0]), double.Parse(strCoor[1]));
                        ipPoitCol.AddPoint(ipPoint, ref pbefore, ref pafter);
                    }
                    strRead.Close();
                }

                iGeo = ipPoitCol as IGeometry;

                if (iGeo != null)
                {
                    if (_subType == 1)
                        (_geometryFeedback as INewLineFeedback).Stop();
                    else if(_subType ==2)
                        (_geometryFeedback as INewPolygonFeedback).Stop();

                    TheReferenceInstances.TheAEditer.SketchEdit.DrawGeometry = iGeo;
                    _startPoint = null;

                    RefreshFeedBack();
                }
                else
                {
                    XtraMessageBox.Show("导入的点坐标不能构成面!", "提示");
                    return;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <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();
            //}
        }
Exemple #53
0
 private IGeometry MakePolygonFromPointsList(List<IPoint> ptsList)
 {
     Ring ring = new RingClass();
     object missing = Type.Missing;
     for (int i = 0; i < ptsList.Count; i++)
     {
         ring.AddPoint(ptsList[i]);
     }
     IGeometryCollection pointPolygon = new PolygonClass();
     pointPolygon.AddGeometry(ring as IGeometry, ref missing, ref missing);
     IPolygon polygon = pointPolygon as IPolygon;
     polygon.SimplifyPreserveFromTo();
     return polygon;
 }
        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;
        }
        /// <summary>
        /// 绘制工作面回采
        /// </summary>
        /// <params name="hd1">巷道1 ID</params>
        /// <params name="hd2">巷道2 ID</params>
        /// <params name="hd3">切眼  ID</params>
        /// <params name="hccd">回采长度</params>
        /// <params name="hd1wid1">巷道1宽度</params>
        /// <params name="hd1wid2">巷道2宽度</params>
        /// <params name="hcbz">回采与回采校正标识</params>
        /// <returns></returns>
        public Dictionary<string, List<GeoStruct>> DrawHDHC(string hd1, string hd2, string hd3, double hccd, double hd1wid1, double hd1wid2, double qywid, int hcbz, double searchlen,
            Dictionary<string, string> dics, bool isAdd, IPoint prevPoint, out IPoint pos)
        {
            List<int> hd_ids = new List<int>();
            hd_ids.Add(Convert.ToInt16(hd1));
            hd_ids.Add(Convert.ToInt16(hd2));
            hd_ids.Add(Convert.ToInt16(hd3));
            //返回工作面坐标点
            IPoint prevHcPoint = new PointClass();
            pos = prevHcPoint;
            Dictionary<string, List<GeoStruct>> dzxlist = new Dictionary<string, List<GeoStruct>>();

            Dictionary<string, string> hdids = new Dictionary<string, string>();
            hdids.Add(GIS_Const.FIELD_HDID, hd1);
            List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selobjs1 = Global.commonclss.SearchFeaturesByGeoAndText(Global.centerlyr, hdids);

            if (null == selobjs1 || selobjs1.Count < 0)
            {
                Log.Error("[GIS]....绘制回采巷道,“中心线图层”可能不存在,请检查GIS数据库。");
                return null;
            }

            IPolyline pline1 = selobjs1[0].Item2 as IPolyline;

            hdids[GIS_Const.FIELD_HDID] = hd2;
            List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selobjs2 = Global.commonclss.SearchFeaturesByGeoAndText(Global.centerlyr, hdids);
            IPolyline pline2 = selobjs2[0].Item2 as IPolyline;

            hdids[GIS_Const.FIELD_HDID] = hd3;
            List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selobjs3 = Global.commonclss.SearchFeaturesByGeoAndText(Global.centerlyr, hdids);
            IPolyline pline3 = selobjs3[0].Item2 as IPolyline;
            hdids[GIS_Const.FIELD_HDID] = hd1 + "_" + hd2;

            //设置回采移动的切眼
            int dirflag = 0;
            List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selhcregs = Global.commonclss.SearchFeaturesByGeoAndText(Global.hcqlyr, hdids);
            if (prevPoint != null && selhcregs != null && selhcregs.Count > 0)
            {
                //查询回采面中心点在切眼中的方向
                dirflag = Global.commonclss.GetDirectionByPnt(pline3, prevPoint);
                //构造新的切眼巷道
                Dictionary<string, List<IPoint>> regcoordinates = Global.commonclss.getCoordinates(selhcregs[0].Item2 as IPolygon, pline1, pline2, pline3, hd1wid1, hd1wid2);
                pline3 = new PolylineClass();
                pline3.FromPoint = regcoordinates["1"][1];
                pline3.ToPoint = regcoordinates["1"][0];
            }
            //查询采掘图层上是否包含了相应的回采区
            List<Tuple<IFeature, IGeometry, Dictionary<string, string>>> selcjqs = Global.commonclss.SearchFeaturesByGeoAndText(Global.hcqlyr, hdids);
            IPointCollection pntcol = new PolygonClass();
            if (hcbz == 1)//粗糙回采
            {
                pntcol = Global.hcjsclass.GetBackPolygonArea(pline1, pline2, pline3, hd1wid1, hd1wid1, qywid, hccd, dirflag);
                if (pntcol == null)
                {
                    pos = null;
                    return null;
                }
                List<IPoint> pnthccols = new List<IPoint>();
                for (int i = 0; i < pntcol.PointCount - 1; i++)
                {
                    pnthccols.Add(pntcol.get_Point(i));
                }
                if (isAdd)
                    Global.cons.AddHangdaoToLayer(pnthccols, dics, Global.hcqlyr);
                else
                {
                    IPolygon poly = Global.commonclss.CreatePolygonFromPnts(pnthccols, Global.spatialref);
                    if (selcjqs.Count > 0)
                        Global.commonclss.UpdateFeature(Global.hcqlyr, selcjqs[0].Item1, dics, poly);
                }
                prevHcPoint = pntcol.get_Point(pntcol.PointCount - 1);
                pos = pntcol.get_Point(pntcol.PointCount - 1);

                //根据点查询60米范围内的地质构造的信息

                //dzxlist = Global.commonclss.GetStructsInfos(prevHcPoint, hd_ids);
                dzxlist = Global.commonclss.GetStructsInfosNew(prevHcPoint, hd_ids, 2);
            }
            if (hcbz == 2)//回采校正
            {
                double x = 0.0;//Convert.ToDouble(this.txtX.Text);
                double y = 0.0;// Convert.ToDouble(this.txtY.Text);
                double hccd1 = Math.Sqrt(Math.Pow((x - prevHcPoint.X), 2) + Math.Pow((y - prevHcPoint.Y), 2));
                //将BS为0的回采去删除,创建新的回采区
                string sql = "\"" + GIS_Const.FIELD_HDID + "\"='" + hd1 + "_" + hd2 + "' AND \"" + GIS_Const.FIELD_BS + "\"=0";
                Global.commonclss.DelFeatures(Global.hcqlyr, sql);
                //查询对应的采掘
                pntcol = Global.hcjsclass.GetBackPolygonArea(pline1, pline2, pline3, hd1wid1, hd1wid1, hd1wid2, hccd1, dirflag);
                if (pntcol == null)
                    return null;
                //构造采掘区对象
                List<IPoint> pnthccols = new List<IPoint>();
                for (int i = 0; i < pntcol.PointCount - 1; i++)
                {
                    pnthccols.Add(pntcol.get_Point(i));
                }
                if (isAdd)
                    Global.cons.AddHangdaoToLayer(pnthccols, dics, Global.hcqlyr);
                else
                {
                    IPolygon poly = Global.commonclss.CreatePolygonFromPnts(pnthccols, Global.spatialref);
                    Global.commonclss.UpdateFeature(Global.hcqlyr, selcjqs[0].Item1, dics, poly);
                }
                //将当前点写入到对应的工作面表中
                prevHcPoint = pntcol.get_Point(pntcol.PointCount - 1);
                pos = prevHcPoint;
                //根据点查询60米范围内的地质构造的信息
                //dzxlist = Global.commonclss.GetStructsInfos(prevHcPoint, hd_ids);
                dzxlist = Global.commonclss.GetStructsInfosNew(prevHcPoint, hd_ids, 2);

            }
            Global.pActiveView.Refresh();
            return dzxlist;
        }
Exemple #56
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            //m_Cursor = new System.Windows.Forms.Cursor(GetType().Assembly.GetManifestResourceStream(GetType(), "AopenMap.cur"));
            if (Button == 1)
            {
                if (m_InUse == true)
                {
                    m_pAV = m_HookHelper.ActiveView;
                    m_pScrD = m_pAV.ScreenDisplay;
                    IMap pMap = m_HookHelper.FocusMap;
                    IPoint pPnt;
                    pPnt = (IPoint)m_pScrD.DisplayTransformation.ToMapPoint(X, Y);
                    if (m_pNewPolygonFeedback == null)
                    {
                        m_pNewPolygonFeedback = new NewPolygonFeedbackClass();
                        ISimpleLineSymbol pSLnSym;
                        IRgbColor pRGB = new RgbColorClass();
                        pSLnSym = (ISimpleLineSymbol)m_pNewPolygonFeedback.Symbol;
                        pRGB.Red = 140;
                        pRGB.Green = 140;
                        pRGB.Blue = 255;
                        pSLnSym.Color = pRGB;
                        pSLnSym.Style = esriSimpleLineStyle.esriSLSSolid;
                        pSLnSym.Width = 2;
                        m_pNewPolygonFeedback.Display = m_pScrD;
                        m_pNewPolygonFeedback.Start(pPnt);

                    }
                    else
                    {
                        m_pNewPolygonFeedback.AddPoint(pPnt);
                    }

                }

            }
            else if (Button == 2)
            {

                IPolygon pGeomLn;
                pGeomLn = m_pNewPolygonFeedback.Stop();
                m_pNewPolygonFeedback = null;
                IMap pMap = m_HookHelper.FocusMap;
                ISpatialReference spatialReference = pMap.SpatialReference;
                //IBorder pBorder = new SymbolBorderClass();
                //*****************************************88888888
                if (pFirstGeom == null)
                {
                    pFirstGeom = pGeomLn;

                }
                if (mGeomln != null)
                {
                    pFirstGeom = mGeomln;
                }
                if (pFirstGeom != pGeomLn)
                {
                    IPolygon mFirstGeom;
                    mFirstGeom = pFirstGeom;
                    IRelationalOperator pROperator = (IRelationalOperator)mFirstGeom;
                    if (pROperator.Disjoint((IGeometry)pGeomLn) == false)
                    {

                        //先定义一个IGeometrycollection的多边形,将每个画出来的IgeometryCollection添加进去
                        //先添一个构成一个IPolygon,转化为ITopo_ ,再同样构成另一个,进行Union
                        IGeometryCollection pcGeometry = new PolygonClass();
                        object o = System.Type.Missing;
                        IPolygon cFirstGeom = new PolygonClass();
                        cFirstGeom = pFirstGeom;
                        ITopologicalOperator tempTopo = (ITopologicalOperator)cFirstGeom;
                        tempTopo.Simplify();

                        ITopologicalOperator pTopo = (ITopologicalOperator)pGeomLn;
                        pTopo.Simplify();
                        IGeometry kGeom;
                        kGeom = pTopo.Union((IGeometry)cFirstGeom);
                        mGeomln = (IPolygon)kGeom;
                        mGeomln.SpatialReference = spatialReference;
                        m_pAV.FocusMap.ClipGeometry = mGeomln;
                        //IBorder pBorder = new SymbolBorderClass();
                        //m_HookHelper.FocusMap.ClipBorder = pBorder;
                        m_pAV.Extent = mGeomln.Envelope;
                        m_pAV.Refresh();
                        m_Cursor = base.m_cursor;
                        //layVisbleExceptMap();

                    }

                }

                else
                {

                    //*************************************************8
                    //mGeomln = pGeomLn;
                    pGeomLn.SpatialReference = spatialReference;
                    LayerControl.LyrPolygon = pGeomLn;
                    m_HookHelper.FocusMap.ClipGeometry = pGeomLn;
                    IBorder pBorder = new SymbolBorderClass();
                    m_HookHelper.FocusMap.ClipBorder = pBorder;
                    m_pAV.Extent = pGeomLn.Envelope;
                    m_pAV.Refresh();
                    m_Cursor = base.m_cursor;
                    pGeomLn = null;
                }

            }
        }
        /// <summary>
        /// Check数据是否在矿界范围之内。
        /// </summary>
        /// <params name="file"></params>
        /// <returns></returns>
        private bool withIn(string file)
        {
            try
            {
                bool within = true;
                ILayer pLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MINE_BOUNDARY);
                if (pLayer == null)
                {
                    MessageBox.Show("煤层矿界图层缺失!");
                    return false;
                }
                IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
                IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                IQueryFilter pFilter = new QueryFilterClass();
                pFilter.WhereClause = "layer='预警矿界'";
                IFeatureCursor pCursor = pFeatureClass.Search(pFilter, false);
                IFeature pFeature = pCursor.NextFeature();
                List<IGeometry> list = new List<IGeometry>();
                if (pFeature == null)
                    return false;
                ISegmentCollection pSegmentCollection = new PolygonClass();
                while (pFeature != null)
                {
                    list.Add(pFeature.Shape);
                    pFeature = pCursor.NextFeature();
                }
                IGeometry pgeoLine = MyMapHelp.GetGeoFromGeos(list);
                pSegmentCollection = pgeoLine as ISegmentCollection;
                IPolyline pPolyline = pSegmentCollection as IPolyline;

                IPolygon pPolygon = DataEditCommon.PolylineToPolygon(pPolyline);

                string[] liststr = File.ReadAllLines(file);
                list = new List<IGeometry>();
                IPoint pt = new PointClass();
                double x, y;
                for (int i = 0; i < liststr.Length; i++)
                {
                    pt = new PointClass();
                    if (!double.TryParse(liststr[i].Split(',')[0], out x) || !double.TryParse(liststr[i].Split(',')[1], out y))
                    {
                        MessageBox.Show("存在非数字的坐标,请检查!");
                        return false;
                    }
                    pt.X = x;
                    pt.Y = y;
                    list.Add(pt);
                }
                if (list.Count < 3)
                {
                    MessageBox.Show("离散点数据为空或小于三个,无法生成等值线!");
                    return false;
                }
                for (int i = 0; i < liststr.Length; i++)
                {
                    for (int j = 0; j < liststr.Length; j++)
                    {
                        if (liststr[i].Split(',')[0] == liststr[j].Split(',')[0] && liststr[i].Split(',')[1] == liststr[j].Split(',')[1] && liststr[i].Split(',')[2] == liststr[j].Split(',')[2] && i != j)
                        {
                            MessageBox.Show("存在重复点,请检查!");
                            return false;
                        }
                    }
                }
                List<IGeometry> listrt = MyMapHelp.withIn(pPolygon, list);
                if (listrt.Count > 0)
                {
                    within = false;
                    DialogResult dr = MessageBox.Show("存在超边界的坐标,是否立即查看?", "", MessageBoxButtons.YesNo);
                    if (dr == DialogResult.Yes)
                    {
                        string strlen = "";
                        for (int i = 0; i < listrt.Count; i++)
                        {
                            pt = listrt[i] as IPoint;
                            strlen += pt.X.ToString() + "," + pt.Y.ToString() + " \r\n";
                        }
                        string filename = Application.StartupPath + "\\ContentError.txt";
                        File.WriteAllText(filename, strlen);
                        Process.Start(filename);
                    }
                }
                return within;
            }
            catch (Exception ex)
            {
                MessageBox.Show("获取矿界失败!" + ex.Message);
                return false;
            }
        }
Exemple #58
0
        public static IGeometry get_GraphicShape(IEnumElement theElements, int a_Dimensionality, bool multipart)
        {
            IGeometry theReturn = null;
            IGeometryCollection theGeomColl = null;
            object missing = Type.Missing;

            if (theElements != null)
            {
                theElements.Reset();
                IElement theElement = theElements.Next();
                while (theElement != null)
                {
                    if (theGeomColl == null)
                        theGeomColl = new GeometryBagClass();

                    IGeometry theShape = null;
                    if (theElement is IGroupElement)
                    {
                        theShape = get_GraphicShape(((IGroupElement)theElement).Elements, a_Dimensionality, multipart);
                    }
                    else if (theElement is ICircleElement
                        || theElement is IPolygonElement
                        || theElement is IRectangleElement
                        || theElement is IEllipseElement
                        || theElement is ILineElement
                        || theElement is IMarkerElement)
                        theShape = theElement.Geometry;

                    if (theShape != null)
                        theGeomColl.AddGeometry(theShape, ref missing, ref missing);

                    theElement = theElements.Next();
                }
            }

            if (theGeomColl != null && theGeomColl.GeometryCount > 0)
            {
                ITopologicalOperator theTopoOp = null;

                switch (a_Dimensionality)
                {
                    case 0:
                        if (multipart)
                        {
                            theTopoOp = new MultipointClass();
                            theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                        }
                        else
                            theTopoOp = theGeomColl.get_Geometry(0) as ITopologicalOperator;
                        break;
                    case 1:
                        theTopoOp = new PolylineClass();
                        theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                        break;
                    case 2:
                        theTopoOp = new PolygonClass();
                        theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                        break;
                }

                theReturn = theTopoOp as IGeometry;
            }
            return theReturn;
        }
        /// <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;
        }
        private IGeoDataset ConvertAndUnionWatershed(IGeoDataset tWatershedGDS)
        {
            //Convert the raster IGeodataset into a Polygon IFeatureClass, in a memory-workspace
            IWorkspace inMemFeatWksp = CreateInMemoryWorkspace();
            //IWorkspaceFactory pWSF = new ShapefileWorkspaceFactory();
            //IWorkspace pWS = pWSF.OpenFromFile(out_folder,0);
            string current = GetTimeStamp(DateTime.Now);
            string outname = "resultWatershed" + current;
            IFeatureClass tWaterShedPolyFC;
            IGeoDataset tInitialPolygons;
            try
            {
                IConversionOp pConversionOp = new ESRI.ArcGIS.GeoAnalyst.RasterConversionOp() as IConversionOp;
                tInitialPolygons = pConversionOp.RasterDataToPolygonFeatureData(tWatershedGDS, inMemFeatWksp, outname, false);
                tWaterShedPolyFC = tInitialPolygons as IFeatureClass;
            }
            catch
            {
                logger.LogMessage(ServerLogger.msgType.debug, "convert and union wshed", 8000,
                        "Error in converting watershed to in-memory FC");
                tWaterShedPolyFC = null;
                tInitialPolygons = null;
            }

            // attempt to add a CATCH_AREA field to the feature class
            bool setAreaOk = false;
            try
            {
                //setAreaOk = AddAreaField(tWaterShedPolyFC);
                setAreaOk = AddAField(tWaterShedPolyFC, "Total_Area", esriFieldType.esriFieldTypeDouble);
            }
            catch
            {
                logger.LogMessage(ServerLogger.msgType.debug, "convert and union wshed", 8000,
                        "Error adding area field to output");
            }

            IFeature tWaterShedFeature;
            // if there is more than one feature in the FC then union them using geometrybag
            if (tWaterShedPolyFC.FeatureCount(null) > 1)
            {
                logger.LogMessage(ServerLogger.msgType.infoStandard, "convert and union wshed", 8000,
                        "Attempting to union multiple polygons...");

                // there is more than one polygon i.e. diagonally connected. merge them into a single feature
                // with multiple rings using a geometrybag
                IGeometryBag tGeometryBag = new GeometryBagClass();
                tGeometryBag.SpatialReference = tInitialPolygons.SpatialReference;
                IFeatureCursor tFCursor = tWaterShedPolyFC.Search(null, false);
                IGeometryCollection tGeomColl = tGeometryBag as IGeometryCollection;
                IFeature tCurrentFeature = tFCursor.NextFeature();
                ITable tTable = tCurrentFeature.Table;
                while (tCurrentFeature != null)
                {
                    object missing = Type.Missing;
                    tGeomColl.AddGeometry(tCurrentFeature.Shape, ref missing, ref missing);
                    tCurrentFeature = tFCursor.NextFeature();
                }
                ITopologicalOperator tUnioned = new PolygonClass();
                tUnioned.ConstructUnion(tGeometryBag as IEnumGeometry);
                logger.LogMessage(ServerLogger.msgType.infoStandard, "convert and union wshed", 8000,
                    "Done with ConstructUnion, doing area");
                try
                {
                    IArea tmpArea = tUnioned as IArea;
                    double tArea = tmpArea.Area;
                    // delete the previously existing rows from the table
                    tTable.DeleteSearchedRows(null);
                    // replace them with a new row representing the unioned feature
                    IRow tRow = tTable.CreateRow();
                    tRow.set_Value(tTable.FindField("SHAPE"), tUnioned);
                    tRow.set_Value(tTable.FindField("ID"), -1);
                    tRow.set_Value(tTable.FindField("GRIDCODE"), -1);
                    if (setAreaOk)
                    {
                        tRow.set_Value(tTable.FindField("Total_Area"), tArea);
                    }
                    tRow.Store();
                }
                catch (Exception ex)
                {
                    logger.LogMessage(ServerLogger.msgType.error, "store unioned polygon", 8000,
                       "Error setting fields of unioned polygon!" + ex.StackTrace + ex.Message);
                }
            }
            else
            {
                // There is only one polygon - i.e. there were not diagonally-disconnected bits
                // NB features are indexed starting at 1. Just for a laff.
                tWaterShedFeature = tWaterShedPolyFC.GetFeature(1);
                if (setAreaOk)
                {
                    try
                    {
                        int tAreaFieldIdx = tWaterShedFeature.Fields.FindField("Total_Area");
                        IArea tArea = tWaterShedFeature.Shape as IArea;
                        double tmpArea = tArea.Area;
                        tWaterShedFeature.set_Value(tAreaFieldIdx, tmpArea);
                        tWaterShedFeature.Store();
                        logger.LogMessage(ServerLogger.msgType.debug, "convert and union wshed", 8000,
                      "Done adding area to one polygon");
                    }
                    catch
                    {
                        logger.LogMessage(ServerLogger.msgType.debug, "convert and union wshed", 8000,
                        "Error adding area field to single polygon output");
                    }
                }
            }
            return (IGeoDataset)tWaterShedPolyFC;
        }