예제 #1
0
        public static IPolygon MakePolygonFromRing(IRing pRing, bool blMakeAreaZ /*使面积为正*/)
        {
            if (pRing == null || pRing.IsEmpty || pRing.IsClosed == false)
            {
                return(null);
            }
            IPolygon            pPolygon            = new PolygonClass();
            IGeometryCollection pGeometryCollection = pPolygon as IGeometryCollection;

            object    pBObj     = Type.Missing;
            object    pAObj     = Type.Missing;
            IGeometry pGeometry = pRing as IGeometry;

            pGeometryCollection.AddGeometry(pGeometry, ref pBObj, ref pAObj);

            if (blMakeAreaZ == false)
            {
                return(pPolygon);
            }

            IArea pArea = pPolygon as IArea;

            if (pArea.Area >= 0)
            {
                return(pPolygon);
            }

            ESRI.ArcGIS.esriSystem.IClone pClone = pRing as ESRI.ArcGIS.esriSystem.IClone;
            IRing pNewRing = pClone.Clone() as IRing;

            pNewRing.ReverseOrientation();
            pGeometry = pNewRing as IGeometry;
            pGeometryCollection.AddGeometry(pGeometry, ref pBObj, ref pAObj);
            return(pPolygon);
        }
        //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);
        }
예제 #3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //生成被查询的图层集以传入查询结果窗体
            lstQueryedLayer = new List <ILayer>();
            foreach (ListViewItem lvi in lstLayer.Items)
            {
                if (lvi.Checked == true)
                {
                    lstQueryedLayer.Add(lvi.Tag as ILayer);
                }
            }
            //生成选择的查询图层的搜索图形
            IFeatureLayer pFL = null;

            foreach (ILayer pLayer in lstSelectLayer)
            {
                if (pLayer.Name == cboxSearchLayer.Text)
                {
                    pFL = pLayer as IFeatureLayer;
                }
            }
            IGeometryBag gmBag = new GeometryBagClass();

            gmBag.SpatialReference = pMap.SpatialReference;//定义空间参考,否则加入的图形将失去参考
            IGeometryCollection gmCollection = gmBag as IGeometryCollection;

            if (rdSelect.Checked)//如果单选框 选择的要素是选中状态
            {
                ISelectionSet pSelSet = (pFL as IFeatureSelection).SelectionSet;
                ICursor       pCursor;
                pSelSet.Search(null, false, out pCursor);
                IFeature pFeature = (pCursor as IFeatureCursor).NextFeature();
                object   obj      = Type.Missing;
                while (pFeature != null)
                {
                    gmCollection.AddGeometry(pFeature.ShapeCopy, ref obj, ref obj);
                    pFeature = (pCursor as IFeatureCursor).NextFeature();
                }
            }
            else//如果单选框 全部要素是选择状态
            {
                IFeatureCursor pFeaCursor = pFL.FeatureClass.Search(null, false);
                IFeature       pFea       = pFeaCursor.NextFeature();
                object         obj        = Type.Missing;
                while (pFea != null)
                {
                    gmCollection.AddGeometry(pFea.ShapeCopy, ref obj, ref obj);
                    pFea = pFeaCursor.NextFeature();
                }
            }
            ISpatialIndex pSI = gmBag as ISpatialIndex;//重建索引

            pSI.AllowIndexing = true;
            pSI.Invalidate();
            GeometryBag = gmBag;
        }
예제 #4
0
        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            {
                object missing = Type.Missing;
                if (bCreateOrNot)
                {
                    axMapControl1.CurrentTool = null;

                    ESRI.ArcGIS.Geometry.IGeometry pGeometry = axMapControl1.TrackPolygon();

                    pGeometryCollection.AddGeometry(pGeometry, ref missing, ref missing);
                    ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbol();
                    pSimpleLineSymbol.Color = GetAEColor(this.listView1.Items.Count + 1);
                    pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
                    ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbol();
                    pSimpleFillSymbol.Color = GetAEColor(this.listView1.Items.Count + 1);
                    IFillShapeElement pFillElement = new PolygonElementClass();
                    pFillElement.Symbol = pSimpleFillSymbol;
                    IElement pElement;

                    pElement          = pFillElement as IElement;
                    pElement.Geometry = pGeometry;
                    pGraphic          = axMapControl1.ActiveView as IGraphicsContainer;
                    pGraphic.AddElement(pElement, 0);
                    axMapControl1.Refresh();

                    polyGonCount            += 1;
                    this.txtSampleCount.Text = polyGonCount.ToString();

                    IElementProperties pElementProperties = pElement as IElementProperties;
                    pElementProperties.Name = txtClassID.Text;
                }
            }
        }
예제 #5
0
파일: Utils3D.cs 프로젝트: secondii/Yutai
        public static IMultiPatch EnvelopeToBoundingBox(IEnvelope2 ienvelope2_0)
        {
            object value = Missing.Value;
            double double_;
            double double_2;
            double double_3;
            double double_4;

            ienvelope2_0.QueryCoords(out double_, out double_2, out double_3, out double_4);
            double              zMin               = ienvelope2_0.ZMin;
            double              zMax               = ienvelope2_0.ZMax;
            IMultiPatch         multiPatch         = new MultiPatch() as IMultiPatch;
            IGeometryCollection geometryCollection = multiPatch as IGeometryCollection;
            IPointCollection    pointCollection    = new TriangleStrip();

            Utils3D.MakeZMAware(pointCollection as IGeometry, true);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_2, zMin), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_2, zMax), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_3, double_2, zMin), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_3, double_2, zMax), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_3, double_4, zMin), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_3, double_4, zMax), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_4, zMin), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_4, zMax), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_2, zMin), ref value, ref value);
            pointCollection.AddPoint(Utils3D.Create3DPoint(double_, double_2, zMax), ref value, ref value);
            geometryCollection.AddGeometry(pointCollection as IGeometry, ref value, ref value);
            return(multiPatch);
        }
예제 #6
0
 public static IGeometry GetSelectFeatureGeom(IMap pMap)
 {
     try
     {
         object              obj          = System.Reflection.Missing.Value;
         IGeometryBag        pGeometryBag = new GeometryBagClass();
         IGeometryCollection pGeomtryCol  = (IGeometryCollection)pGeometryBag;
         ISelection          pSelection   = pMap.FeatureSelection;
         IEnumFeature        pEnumFea     = pSelection as IEnumFeature;
         IFeature            pFea         = pEnumFea.Next();
         while (pFea != null)
         {
             if (pFea.Shape != null && pFea.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
             {
                 pGeomtryCol.AddGeometry(pFea.Shape, ref obj, ref obj);
             }
             pFea = pEnumFea.Next();
         }
         ITopologicalOperator pTopo = new PolygonClass();
         pTopo.ConstructUnion(pGeomtryCol as IEnumGeometry);
         IGeometry pGeometry = pTopo as IGeometry;
         return(pGeometry);
     }
     catch { return(null); }
 }
예제 #7
0
        /// <summary>
        /// 把geometry合并起来,组成一个新的geometry,在缓冲buffer个单位
        /// </summary>
        /// <param name="lstGeo">Geo列表</param>
        /// <param name="buffer">缓冲单位</param>
        /// <returns></returns>
        public static IGeometry GetUnionGeometry(IList <IGeometry> lstGeo, double buffer)
        {
            if (lstGeo.Count == 0)
            {
                return(null);
            }
            IGeometryBag pGeometryBag = new GeometryBagClass();

            pGeometryBag.SpatialReference = lstGeo[0].SpatialReference;
            IGeometryCollection pGeometryCollection = pGeometryBag as IGeometryCollection;
            object obj = Type.Missing;

            foreach (IGeometry geo in lstGeo)
            {
                pGeometryCollection.AddGeometry(geo, ref obj, ref obj);
            }

            ITopologicalOperator UnionPolygon = new PolygonClass();

            UnionPolygon.ConstructUnion(pGeometryCollection as ESRI.ArcGIS.Geometry.IEnumGeometry);
            IGeometry            geoResult    = UnionPolygon as IGeometry;
            ITopologicalOperator operatorTopo = geoResult as ITopologicalOperator;

            return(operatorTopo.Buffer(buffer));
        }
예제 #8
0
        private void GetQueryGeometry()
        {
            if (queryFeatureClass == null)
            {
                return;
            }
            queryGeometry = null;
            object missing = Type.Missing;

            switch (strGeometryType)
            {
            case "点":
                queryGeometry = new MultipointClass();
                break;

            case "线":
                queryGeometry = new PolylineClass();
                break;

            case "多边形":
            case "矩形":
            case "圆":
                queryGeometry = new PolygonClass();
                break;

            default:
                break;
            }

            for (int i = 0; i < queryFeatureClass.FeatureCount(null); i++)
            {
                queryGeometry.AddGeometry(queryFeatureClass.GetFeature(i).Shape, ref missing, ref missing);
            }
        }
예제 #9
0
        /// <summary>
        /// 获得当前视图上的选择要素
        /// ZQ 2011 1203 将点要素自动去除 只合并线和面要素
        /// </summary>
        /// <param name="pMap"></param>
        /// <returns></returns>
        private IGeometry ConstructUnion(IMap pMap)
        {
            IGeometry pGeometry = null;

            try
            {
                IGeometryBag        pGeometryBag = new GeometryBagClass();
                IGeometryCollection pGeometryCol = pGeometryBag as IGeometryCollection;
                object       obj          = System.Type.Missing;
                ISelection   pSelection   = pMap.FeatureSelection;
                IEnumFeature pEnumFeature = pSelection as IEnumFeature;
                IFeature     pFeature     = pEnumFeature.Next();
                while (pFeature != null)
                {
                    ///排除点要素
                    if (pFeature.ShapeCopy.GeometryType != esriGeometryType.esriGeometryPoint && pFeature.ShapeCopy.GeometryType != esriGeometryType.esriGeometryMultipoint)
                    {
                        if (!pFeature.ShapeCopy.IsEmpty)
                        {
                            pGeometryCol.AddGeometry(pFeature.ShapeCopy, ref obj, ref obj);
                        }
                    }
                    pFeature = pEnumFeature.Next();
                }
                //构造合并
                ITopologicalOperator pTopo = new PolygonClass();
                pTopo.ConstructUnion(pGeometryCol as IEnumGeometry);
                pGeometry = pTopo as IGeometry;
                return(pGeometry);
            }
            catch
            { return(pGeometry = null); }
        }
        //Function: Judging whether regional breaks have occurred
        public bool isRegionalBreak(IFeatureClass featureClass, int elementId)
        {
            IGeometry    geometryBag = new GeometryBagClass();
            IQueryFilter queryFilter = new QueryFilterClass();

            queryFilter.WhereClause = "id = " + elementId;
            IFeatureCursor featureCursor = featureClass.Search(queryFilter, false);

            IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;
            IFeature            currentFeature     = featureCursor.NextFeature();

            while (currentFeature != null)
            {
                object missing = Type.Missing;
                geometryCollection.AddGeometry(currentFeature.Shape, ref missing, ref missing);
                currentFeature = featureCursor.NextFeature();
            }

            ITopologicalOperator unionedPolygon = new PolygonClass();

            unionedPolygon.ConstructUnion(geometryBag as IEnumGeometry);

            IGeometryCollection geoCol = unionedPolygon as IGeometryCollection;

            if (geoCol.GeometryCount > 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #11
0
        /// <summary>
        /// 更新半径 千米
        /// </summary>
        /// <param name="radius"></param>
        public void UpdatePosition(double radius)
        {
            this.Dosomething((Action) delegate()
            {
                pRadius = radius;

                MapLngLat center          = new MapLngLat(centerPoint.X, centerPoint.Y);
                MapLngLat around          = MapFrame.Core.Common.Utils.GetPointByDistanceAndAngle((float)radius, center, 180);
                INewLineFeedback backline = new NewLineFeedbackClass();
                centerPoint = new PointClass()
                {
                    X = center.Lng, Y = center.Lat
                };
                IPoint aroundPoint = new PointClass()
                {
                    X = around.Lng, Y = around.Lat
                };
                backline.Start(centerPoint);
                backline.AddPoint(aroundPoint);
                var geo = backline.Stop();
                iSeg.SetCircle(centerPoint, geo.Length);
                object o = System.Type.Missing;
                pRing    = iSeg as IRing;
                pRing.Close();

                pGeometryColl = new PolygonClass();
                pGeometryColl.AddGeometry(pRing, ref o, ref o);
                pGeometry = pGeometryColl as IGeometry;

                base.Symbol   = fillSymbol;
                base.Geometry = pGeometry;
            }, true);

            Update();
        }
예제 #12
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);
        }
예제 #13
0
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            try
            {
                IPolyline chain_geom = new PolylineClass();

                ISegmentCollection path1 = new PathClass();

                foreach (Range r in Errors.CenterlineChains[select_chain_name])
                {
                    ISegmentCollection segcoll = r.Shape as ISegmentCollection;
                    path1.AddSegmentCollection(segcoll);
                }

                object obj = Type.Missing;

                IGeometryCollection gCollection = chain_geom as IGeometryCollection;

                gCollection.AddGeometry((IGeometry)path1, obj, obj);

                chain_geom = (IPolyline)gCollection;

                FlashGeometry(chain_geom);
            }
            catch { }
        }
예제 #14
0
    //----------------------------------------------------------------------------------

    public static IPolyline MaakPolyline()
    {
        //Declaraties en initialisaties
        IPolyline           pPolyline = new PolylineClass();
        IGeometryCollection pGCol     = (IGeometryCollection)pPolyline;
        IZAware             pZAware   = (IZAware)pPolyline;

        pZAware.ZAware = ImportInArcscene.ZBoolean;

        int aantalpaths = ImportInArcscene.binReader.ReadInt32();

        for (int i = 1; i <= aantalpaths; i++)
        {
            IPath            pPath     = new PathClass();
            IPointCollection pPointCol = (IPointCollection)pPath;

            int aantalvertices = ImportInArcscene.binReader.ReadInt32();

            for (int k = 1; k <= aantalvertices; k++)
            {
                double ptx = ImportInArcscene.binReader.ReadSingle();
                double pty = ImportInArcscene.binReader.ReadSingle();
                double ptz = ImportInArcscene.binReader.ReadSingle();
                pPointCol.AddPoint(PuntTransformatie(ptx, pty, ptz), ref _missing, ref _missing);
            }
            pGCol.AddGeometry(pPath, ref _missing, ref _missing);
        }
        return(pPolyline);
    }
예제 #15
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);
        }
        private IPolyline ConvertFrom(GeoAPI.Geometries.IMultiLineString lines)
        {
            if (lines == null)
            {
                return(null);
            }

            IPolyline           polyline = new PolylineClass();
            IGeometryCollection paths    = lines as IGeometryCollection;

            foreach (GeoAPI.Geometries.ILineString line in lines.Geometries)
            {
                IPath            path            = new PathClass();
                IPointCollection pointCollection = path as IPointCollection;
                object           Missing         = Type.Missing;
                IPoint           point           = new PointClass();
                foreach (GeoAPI.Geometries.ICoordinate coordinate in line.Coordinates)
                {
                    point.X = coordinate.X;
                    point.Y = coordinate.Y;
                    point.Z = coordinate.Z;
                    pointCollection.AddPoint(point, ref Missing, ref Missing);
                }
                paths.AddGeometry(path, ref Missing, ref Missing);
            }
            return(polyline);
        }
예제 #17
0
        public static IGeometry GetSelectGeometry(IMap pMap)
        {
            if (pMap == null)
            {
                return(null);
            }
            if (pMap.SelectionCount == 0)
            {
                return(null);
            }

            IGeometryBag        pGeometryBag = new GeometryBagClass();
            IGeometryCollection pGeomtryCol  = (IGeometryCollection)pGeometryBag;
            IEnumFeature        pEnumFeature = (IEnumFeature)pMap.FeatureSelection;
            IFeature            pFeature     = pEnumFeature.Next();

            object obj = System.Reflection.Missing.Value;

            while (pFeature != null)
            {
                pGeomtryCol.AddGeometry(pFeature.ShapeCopy, ref obj, ref obj);
                pFeature = pEnumFeature.Next();
            }
            pGeometryBag.Project(pMap.SpatialReference);
            return((IGeometry)pGeometryBag);
        }
예제 #18
0
        public static IGeometry CreateConvexHull(IFeatureCursor pFeatureCursor)
        {
            IGeometryCollection pGeomCollection = (IGeometryCollection) new Polygon();
            IGeometryCollection pGeomCollectionIn;

            IFeature pFeature = pFeatureCursor.NextFeature();

            while (pFeature != null)
            {
                pGeomCollectionIn = (IGeometryCollection)pFeature.ShapeCopy;

                for (int i = 0; i < pGeomCollectionIn.GeometryCount; i++)
                {
                    pGeomCollection.AddGeometry(pGeomCollectionIn.get_Geometry(i));
                }

                pFeature = pFeatureCursor.NextFeature();
            }

            ITopologicalOperator pTopOp = (ITopologicalOperator)pGeomCollection;
            //pTopOp.Simplify();
            IGeometry pGeom = pTopOp.ConvexHull();

            return(pGeom);
        }
        //删除节点事件
        void btnRemovePoint_Click(object sender, EventArgs e)
        {
            try
            {
                object misobj = Type.Missing;
                m_Editor.StartOperation();

                IGeometry        ring = (cbxRings.SelectedItem as CommonComboBoxItem).Tag as IGeometry;
                IPointCollection pc   = ring as IPointCollection;
                pc.RemovePoints((int)listPointCollection.SelectedItems[0].Tag, 1);

                IFeature            feature = (treeFeatures.SelectedNode.Tag as IFeature);
                IGeometryCollection geoCol  = cbxRings.Tag as IGeometryCollection;
                geoCol.AddGeometry(ring, ref misobj, ref misobj);
                geoCol.RemoveGeometries(cbxRings.SelectedIndex, 1);
                feature.Shape = geoCol as IGeometry;
                feature.Store();

                int removePointIndex = listPointCollection.SelectedItems[0].Index;
                listPointCollection.SelectedItems[0].Remove();

                m_Editor.StopOperation("RemovePoint");
                this.cbxRings_SelectedIndexChanged(sender, e);
                if (listPointCollection.Items.Count > removePointIndex)
                {
                    listPointCollection.Items[removePointIndex].Selected = true;
                    listPointCollection.TopItem = listPointCollection.SelectedItems[0];
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #20
0
        private void iSpatialFilterGeometryBagToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Stopwatch myWatch = Stopwatch.StartNew();

            //从MapControl中获取的点图层
            IFeatureLayer     pointFeatureLayer     = axMapControl1.get_Layer(0) as IFeatureLayer;
            IFeatureSelection pointFeatureSelection = pointFeatureLayer as IFeatureSelection;
            //从MapControl中获取的面图层
            IFeatureLayer polygonFeatureLayer = axMapControl1.get_Layer(1) as IFeatureLayer;

            //构建GeometryBag
            IGeometryBag        geometryBag        = new GeometryBagClass();
            IGeometryCollection geometryCollection = (IGeometryCollection)geometryBag;
            IGeoDataset         geoDataset         = (IGeoDataset)polygonFeatureLayer;
            ISpatialReference   spatialReference   = geoDataset.SpatialReference;

            //一定要给GeometryBag赋空间参考
            geometryBag.SpatialReference = spatialReference;

            IQueryFilter queryFilter = new QueryFilterClass();

            //Search如果返回属性值的话设置SubFields会提高效率
            queryFilter.SubFields = "Shape";

            //遍历面要素类,逐一获取Geometry并添加到GeometryBag中
            IFeatureCursor cursor = polygonFeatureLayer.Search(queryFilter, true);

            IFeature polygonFeature = null;

            while ((polygonFeature = cursor.NextFeature()) != null)
            {
                geometryCollection.AddGeometry(polygonFeature.ShapeCopy);
            }
            //为GeometryBag生成空间索引,以提高效率
            ISpatialIndex spatialIndex = (ISpatialIndex)geometryBag;

            spatialIndex.AllowIndexing = true;
            spatialIndex.Invalidate();
            //构建空间查询
            ISpatialFilter spatialFilter = new SpatialFilterClass();

            spatialFilter.Geometry      = geometryBag;
            spatialFilter.GeometryField = pointFeatureLayer.FeatureClass.ShapeFieldName;
            spatialFilter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelContains;
            //选择的话可以不设置SubFields
            pointFeatureSelection.SelectFeatures(spatialFilter as IQueryFilter, esriSelectionResultEnum.esriSelectionResultAdd, false);

            int count = pointFeatureSelection.SelectionSet.Count;

            axMapControl1.Refresh();
            //释放游标
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(cursor);

            myWatch.Stop();
            string time = myWatch.Elapsed.TotalSeconds.ToString();

            MessageBox.Show("The selected point count is " + count.ToString() + "! and " + time + " Seconds");
        }
예제 #21
0
        public static IPolygon MergePolygons(IGeometry polygon1, IGeometry polygon2, IFeatureClass fc_for_spatial_reference)
        {
            IGeometry   geometry_bag = new GeometryBag();
            IGeoDataset ds           = fc_for_spatial_reference as IGeoDataset;

            geometry_bag.SpatialReference = ds.SpatialReference;
            IGeometryCollection gc = geometry_bag as IGeometryCollection;
            object missing         = Type.Missing;

            gc.AddGeometry(polygon1, ref missing, ref missing);
            gc.AddGeometry(polygon2, ref missing, ref missing);
            ITopologicalOperator union_polygon = new Polygon() as ITopologicalOperator;

            union_polygon.ConstructUnion(geometry_bag as IEnumGeometry);
            IPolygon new_polygon = union_polygon as IPolygon;

            return(new_polygon);
        }
예제 #22
0
        //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;

            geometryCollection.AddGeometry(CGeoFunc.GetIrgFromCptLt(this.CptLt));
            //add the holes
            if (this.HoleCpgLt != null)
            {
                foreach (var holecpg in this.HoleCpgLt)
                {
                    geometryCollection.AddGeometry(CGeoFunc.GetIrgFromCptLt(holecpg.CptLt));
                }
            }

            this.pPolygon = polygon;
            return(polygon);
        }
예제 #23
0
        /// <summary>
        /// 由环构成多边形
        /// </summary>
        /// <param name="rings"></param>
        /// <returns></returns>
        public static IPolygon CreatePolygon(IEnumerable <IRing> rings)
        {
            IPolygon            polygon      = new PolygonClass();
            IGeometryCollection geometryColl = (IGeometryCollection)polygon;

            foreach (var ring in rings)
            {
                geometryColl.AddGeometry(ring);
            }
            return(polygon);
        }
예제 #24
0
        /// <summary>
        /// 将多个图形合并(Union)成一个图形(使用GeometryBag提高合并效率)
        /// </summary>
        /// <param name="geometries">需要合并的几何图形(注意这些图形必须是相同的几何类型)</param>
        /// <returns></returns>
        public static IGeometry UnionGeometryEx(this IEnumerable <IGeometry> geometries)
        {
            IGeometry geometryBag = new GeometryBagClass();

            geometryBag.SpatialReference = geometries.First().SpatialReference;
            IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;

            foreach (var geometry in geometries)
            {
                object missing = Type.Missing;
                geometryCollection.AddGeometry(geometry, ref missing, ref missing);
            }
            return(UnionGeometryEx(geometryBag, geometries.First().GeometryType));
        }
예제 #25
0
        /// <summary>
        /// 将多个图形合并(Union)成一个图形(使用GeometryBag提高合并效率)
        /// </summary>
        /// <param name="featureClass">从中查询图形的要素类</param>
        /// <param name="whereCluase">查询条件</param>
        /// <returns></returns>
        public static IGeometry UnionGeometryEx(this IFeatureClass featureClass, string whereCluase = null)
        {
            IGeometry geometryBag = new GeometryBagClass();

            geometryBag.SpatialReference = ((IGeoDataset)featureClass).SpatialReference;
            IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;

            featureClass.QueryFeatures(whereCluase, f =>
            {
                object missing = Type.Missing;
                geometryCollection.AddGeometry(f.ShapeCopy, ref missing, ref missing);
            });
            return(UnionGeometryEx(geometryBag, featureClass.ShapeType));
        }
예제 #26
0
        /// <summary>
        /// 合并几何体
        /// </summary>
        /// <returns></returns>
        private IGeometry GetMergeGeometry(string str)
        {
            IGeometryBag pGeometryBag = new GeometryBag() as IGeometryBag;
            pGeometryBag.SpatialReference = GetSpatialReference();
            IGeometryCollection pGeometryCollection = pGeometryBag as IGeometryCollection;

            // 属性过滤
            IQueryFilter pQueryFilter = new QueryFilter();
            pQueryFilter.WhereClause = str;

            IFeatureLayer pFeatureLayer = mLayer as IFeatureLayer;
            IFeatureClass in_FeatureClass = pFeatureLayer.FeatureClass;

            // 要素游标
            IFeatureCursor pFeatureCursor = in_FeatureClass.Search(pQueryFilter, true);
            IFeature pFeature = pFeatureCursor.NextFeature();
            if (pFeature == null)
            {
                return null;
            }

            // 遍历游标
            object missing = Type.Missing;
            while (pFeature != null)
            {
                pGeometryCollection.AddGeometry(pFeature.ShapeCopy, ref missing, ref missing);
                pFeature = pFeatureCursor.NextFeature();
            }
            Marshal.ReleaseComObject(pFeatureCursor);

            // 合并要素
            ITopologicalOperator pTopologicalOperator = null;
            if (in_FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
            {
                pTopologicalOperator = new Multipoint() as ITopologicalOperator;
                pTopologicalOperator.ConstructUnion(pGeometryCollection as IEnumGeometry);
            }
            else if (in_FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
            {
                pTopologicalOperator = new Polyline() as ITopologicalOperator;
                pTopologicalOperator.ConstructUnion(pGeometryCollection as IEnumGeometry);
            }
            else
            {
                pTopologicalOperator = new Polygon() as ITopologicalOperator;
                pTopologicalOperator.ConstructUnion(pGeometryCollection as IEnumGeometry);
            }
            return pTopologicalOperator as IGeometry;
        }
예제 #27
0
 public void SaveEdit()
 {
     try
     {
         Editor.UniqueInstance.StartEditOperation();
         object before  = new object();
         object missing = Type.Missing;
         foreach (LinkArgs args in this._las)
         {
             if (args.PartIndex >= 0)
             {
                 IFeature            feature   = args.feature;
                 IGeometryCollection shapeCopy = feature.ShapeCopy as IGeometryCollection;
                 IPointCollection    points    = shapeCopy.get_Geometry(args.PartIndex) as IPointCollection;
                 for (int i = 0; i < this._editInfoList.Count; i++)
                 {
                     EditInfo info  = this._editInfoList[i] as EditInfo;
                     int      index = args.VertexIndex[i];
                     IPoint   p     = (info.NewPoint as IClone).Clone() as IPoint;
                     if (p.SpatialReference != (EditTask.EditLayer.FeatureClass as IGeoDataset).SpatialReference)
                     {
                         p.Project((EditTask.EditLayer.FeatureClass as IGeoDataset).SpatialReference);
                         p.SpatialReference = (EditTask.EditLayer.FeatureClass as IGeoDataset).SpatialReference;
                     }
                     if (index == 0)
                     {
                         points.UpdatePoint(0, p);
                     }
                     else
                     {
                         points.ReplacePoints(index, 1, 1, ref p);
                     }
                 }
                 shapeCopy.RemoveGeometries(args.PartIndex, 1);
                 before = args.PartIndex;
                 shapeCopy.AddGeometry(points as IGeometry, ref before, ref missing);
                 IGeometry geometry = (IGeometry)shapeCopy;
                 feature.Shape = geometry;
                 feature.Store();
             }
         }
         Editor.UniqueInstance.StopEditOperation("Linkage Edit");
     }
     catch (Exception exception)
     {
         Editor.UniqueInstance.AbortEditOperation();
         this._mErrOpt.ErrorOperate(this._mSubSysName, "ShapeEdit.LinkageEdit", "SaveEdit", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
     }
 }
예제 #28
0
        private static void AddRing(IGeometryCollection multiPatch,
                                    List <WKSPointZ> ringPoints)
        {
            if (ringPoints.Count <= 0)
            {
                return;
            }

            object            missing = Type.Missing;
            IPointCollection4 ring    = new RingClass();

            WKSPointZ[] points = ringPoints.ToArray();
            GeometryUtils.SetWKSPointZs(ring, points);

            multiPatch.AddGeometry((IRing)ring, ref missing, ref missing);
        }
예제 #29
0
        /// <summary>
        /// 筛选要素类中,与指定图形满足一定空间关系的要素(空间筛选时添加空间索引)
        /// (参考:http://blog.csdn.net/lanpy88/article/details/7173063)
        /// </summary>
        /// <param name="featureClass">从中筛选要素的要素类(A)</param>
        /// <param name="geometry">过滤条件图形(B)</param>
        /// <param name="spatialRefEnum">空间关系类型(举例:esriSpatialRelContains表示A包含B)</param>
        /// <param name="whereClause">查询条件</param>
        /// <returns></returns>
        public static List <IFeature> FilterFeaturesEx(this IFeatureClass featureClass, IGeometry geometry, esriSpatialRelEnum spatialRefEnum, string whereClause = "")
        {
            IGeometryBag        geometryBag        = new GeometryBagClass();
            IGeometryCollection geometryCollection = (IGeometryCollection)geometryBag;

            geometryBag.SpatialReference = ((IGeoDataset)featureClass).SpatialReference; //一定要给GeometryBag赋空间参考
            geometryCollection.AddGeometry(geometry);

            //为GeometryBag生成空间索引,以提高效率
            ISpatialIndex spatialIndex = (ISpatialIndex)geometryBag;

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

            return(FilterFeatures(featureClass, geometry, spatialRefEnum, whereClause));
        }
예제 #30
0
        private List <IElement> CreateElementAois(List <IPolygon> polygons, out IEnvelope encompassingEnvelope)
        {
            var rgbColor = new RgbColorClass {
                Red = 0, Green = 0, Blue = 255, Transparency = 200
            };

            var geometryBag = new GeometryBagClass();

            geometryBag.SpatialReference = ArcMap.Document.FocusMap.SpatialReference;
            IGeometryCollection geometryCollection = geometryBag;
            var elements = new List <IElement>();

            foreach (var polygon in polygons)
            {
                geometryCollection.AddGeometry(polygon);
                IElement element = null;

                // Polygon elements
                ILineSymbol lineSymbol = new SimpleLineSymbolClass();
                lineSymbol.Color = rgbColor;
                lineSymbol.Width = 2.0;

                ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
                simpleFillSymbol.Color   = rgbColor;
                simpleFillSymbol.Style   = esriSimpleFillStyle.esriSFSNull;
                simpleFillSymbol.Outline = lineSymbol;

                IFillShapeElement fillShapeElement = new PolygonElementClass();
                fillShapeElement.Symbol = simpleFillSymbol;
                element = (IElement)fillShapeElement; // Explicit Cast

                element.Geometry = polygon;
                elements.Add(element);
            }

            // Create the polygon that will be the union of the features returned from the search cursor.
            // The spatial reference of this feature does not need to be set ahead of time. The
            // ConstructUnion method defines the constructed polygon's spatial reference to be the same as
            // the input geometry bag.
            ITopologicalOperator unionedPolygon = new PolygonClass();

            unionedPolygon.ConstructUnion(geometryBag);
            var masterPoly = (IPolygon)unionedPolygon;

            encompassingEnvelope = masterPoly.Envelope;
            return(elements);
        }
        public bool DeleteRowsByFIDSetReturnGeomCollection(ITable inTable, IFIDSet pFIDSet,
  IStepProgressor StepProgressor, ITrackCancel TrackCancel, ref IGeometryCollection GeomCollection)
        {
            //this routine uses the GetRows method, avoids the need to break up the InClause.
              if (pFIDSet == null)
            return false;
              IMouseCursor pMouseCursor = new MouseCursorClass();
              pMouseCursor.SetCursor(2);
              try
              {
            pFIDSet.Reset();
            int[] iID = { };
            bool bCont = true;
            iID = RedimPreserveInt(ref iID, pFIDSet.Count());
            for (int iCount = 0; iCount <= pFIDSet.Count() - 1; iCount++)
              pFIDSet.Next(out iID[iCount]);
            ICursor pCursor = inTable.GetRows(iID, false);
            IRow row = pCursor.NextRow();
            if (StepProgressor != null)
            {
              if (StepProgressor.Position < StepProgressor.MaxRange)
            StepProgressor.Step();
            }
            while (row != null)
            {
              IFeature pFeat = row as IFeature;
              IGeometry pGeom = pFeat.ShapeCopy;
              if (pGeom != null)
              {
            if (!pGeom.IsEmpty)
            {
              object obj = Type.Missing;
              IEnvelope2 pEnv = (IEnvelope2)pGeom.Envelope;
              pEnv.Expand(0.1, 0.1, false);
              GeomCollection.AddGeometry(pEnv, ref obj, ref obj);
            }
              }
              //Check if the cancel button was pressed. If so, stop process
              if (StepProgressor != null)
              {
            if (TrackCancel != null)
              bCont = TrackCancel.Continue();
            if (!bCont)
              break;
              }
              row.Delete();
              Marshal.ReleaseComObject(row);
              row = pCursor.NextRow();
              if (StepProgressor != null)
              {
            if (StepProgressor.Position < StepProgressor.MaxRange)
              StepProgressor.Step();
              }
            }
            Marshal.ReleaseComObject(pCursor);
            inTable = null;
            iID = null;
            if (!bCont)
              return false;
            return true;
              }
              catch (COMException ex)
              {
            StepProgressor = null;
            if (ex.ErrorCode == -2147217400)
              //MessageBox.Show(ex.ErrorCode + Environment.NewLine + ex.Message +
              //  Environment.NewLine + "This error indicates that the fabric may not have been correctly upgraded.");
              //TODO: need to confirm this.
              m_LastErrorCode = ex.ErrorCode;
            else
              MessageBox.Show(ex.Message + Environment.NewLine + ex.ErrorCode);

            m_LastErrorCode = ex.ErrorCode;
            return false;
              }
        }