private List <IRecordSet2> AnalisiSpazialiBufferOper(Dictionary <long, IPolygon> dizBuffer) { List <IRecordSet2> listaRecordSetPunti = new List <IRecordSet2>(); try { #region Analizzo tutti i punti che ricadono nel primo buffer // Primo buffer è un cerchio! ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = dizBuffer[0] as IGeometry; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; listaRecordSetPunti.Add(Helper.ConvertToRecordset(fcClienti, spatialFilter)); #endregion #region Analizzo secondo Buffer! // Ricavo buffer simmetrico (ciambella) di differenza tra il primo ed il secondo cerchio! ITopologicalOperator topologicalOperator = dizBuffer[1] as ITopologicalOperator; IGeometry geomDiff1 = topologicalOperator.Difference(dizBuffer[0] as IGeometry); spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = geomDiff1; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; listaRecordSetPunti.Add(Helper.ConvertToRecordset(fcClienti, spatialFilter)); #endregion #region Analizzo terzo Buffer! // Ricavo buffer simmetrico (ciambella) di differenza tra il primo ed il secondo cerchio! topologicalOperator = dizBuffer[2] as ITopologicalOperator; IGeometry geomDiff2 = topologicalOperator.Difference(dizBuffer[1] as IGeometry); spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = geomDiff2; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains; listaRecordSetPunti.Add(Helper.ConvertToRecordset(fcClienti, spatialFilter)); #endregion } catch (Exception errore) { logger.LogMessage(ServerLogger.msgType.error, "Construct", 8000, $@"SOE GeoMarketing GiancaGIS: {errore.Message}"); } return(listaRecordSetPunti); }
/// <summary> /// 按照指定的各部分的权重将一个多边形切分成多个 /// </summary> /// <param name="polygon">被切分的多边形</param> /// <param name="weights">切分后的多边形各个部分的权重</param> /// <param name="direction">切分多边形的方向,0为横向,1为纵向</param> /// <param name="tolerance">面积容差</param> /// <returns></returns> public static List <IPolygon> SplitPolygonByAreaWeights(IPolygon polygon, double[] weights, int direction, double tolerance = 0.001) { if (polygon.IsEmpty) { throw new Exception("几何图形不能为空(Empty)!"); } if (tolerance < 0) { throw new Exception("指定的容差不能小于0"); } var resultPolygons = new List <IPolygon>(); var tmpPolygon = polygon; for (int i = 0; i < weights.Length; i++) { var rate = weights[i] / weights.Skip(i).Sum(); if (rate == 1) { resultPolygons.Add(tmpPolygon); continue; } var resultPolygon = SplitPolygonByAreaRate(tmpPolygon, rate, direction, tolerance) as IPolygon; //截取多边形 ITopologicalOperator logicalOpt = (ITopologicalOperator)tmpPolygon; tmpPolygon = logicalOpt.Difference(resultPolygon) as IPolygon; //获取多边形截取后的剩余部分 resultPolygons.Add(resultPolygon); } return(resultPolygons); }
public void EraseOper() { ISpatialFilter tSF = new SpatialFilterClass(); tSF.Geometry = _Envelope; tSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; //求出与裁切框相交要素 IFeatureCursor tFeatureCursor = _FeatureClass.Search(tSF, false); IFeature tFeature = tFeatureCursor.NextFeature(); while (tFeature != null) { IGeometry tGeo2 = tFeature.ShapeCopy; ITopologicalOperator tTope2 = tGeo2 as ITopologicalOperator; tTope2.Simplify(); IGeometry tGeo = tFeature.ShapeCopy; ITopologicalOperator tTope = tGeo as ITopologicalOperator; tTope.Simplify(); //用Envelope对要素进行裁切 tTope.Clip(this._Envelope); IGeometry tGeoClip = (IGeometry)tTope; //用裁切出来的要素,再与其源要素进行求差处理,即得到外围要素 IGeometry tGeoDe = tTope2.Difference(tGeoClip); //把外围要素赋予源要素 tFeature.Shape = tGeoDe; tFeature.Store(); tFeature = tFeatureCursor.NextFeature(); } ReleaseCom(tFeatureCursor); }
/// <summary> /// Will take a given polygon and 'cookie cut' it into the chosen layer /// </summary> /// <param name="homesite_polygon"></param> private void StampPolygonIntoHomesiteLayer(IPolygon homesite_polygon) { try { IFeatureLayer featureLayer = _utilitiesArcMap.FeatureLayer(cbo_featureclass.Text); IFeatureClass featureClass = featureLayer.FeatureClass; _editor.StartOperation(); ISpatialFilter spatialFilter = new SpatialFilter(); spatialFilter.GeometryField = featureClass.ShapeFieldName; spatialFilter.Geometry = homesite_polygon; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false); IFeature feature = null; while ((feature = featureCursor.NextFeature()) != null) { ITopologicalOperator topologicalOperator = feature.Shape as ITopologicalOperator; IGeometry geometry = topologicalOperator.Difference(homesite_polygon); IPolygon polygon = geometry as IPolygon; IFeature newFeature = featureClass.CreateFeature(); newFeature.Shape = polygon as IPolygon; // This caused a problem with memory allocation. It would not delete the orignal data. ArrayList fields = _utilitiesArcMap.NumberFieldsWithDomain(featureLayer); // Set the attribute back to the old ones. foreach (string field in fields) { newFeature.set_Value(newFeature.Fields.FindField(field), feature.get_Value(feature.Fields.FindField(field))); } newFeature.Store(); feature.Delete(); } IFeature homesite = featureClass.CreateFeature(); homesite.Shape = homesite_polygon; homesite.Store(); _editor.StopOperation("Homesite"); } catch (Exception ex) { RS_Tools.Utilities.Utilities_MessageBox.ErrorBox(ex.Message, MB_TITLE); } }
/// <summary> /// 获取polygon1超出polygon2部分的面积 /// </summary> /// <param name="polygon1"></param> /// <param name="polygon2"></param> /// <returns></returns> public static double GetDifferenceeArea(IPolygon polygon1, IPolygon polygon2) { try { ITopologicalOperator topo = polygon1 as ITopologicalOperator; IGeometry differGeom = topo.Difference(polygon2); IArea area = differGeom as IArea; return(area.Area); } catch (Exception ex) { LOG.Error(ex); } return(0); }
/// <summary> /// 获取一个面相对于另一个面差异的部分,实现擦除分析功能(Erase) /// </summary> /// <param name="polygon1">是个面对象</param> /// <param name="polygon2">是个面对象</param> /// <returns>获取polygon1中去掉polygon1和polygon2重合部分的部分</returns> public static IGeometry GetDifference(IPolygon polygon1, IPolygon polygon2) { try { ITopologicalOperator topo = polygon1 as ITopologicalOperator; IGeometry differGeom = topo.Difference(polygon2); return(differGeom); } catch (Exception ex) { LOG.Error(ex); } return(null); }
public IGeometry Erase(IGeometry source, IGeometry other) { ITopologicalOperator @operator = source as ITopologicalOperator; if ([email protected]) { @operator.Simplify(); } IGeometry geometry = @operator.Difference(other); @operator = geometry as ITopologicalOperator; if ([email protected]) { @operator.Simplify(); } return(geometry); }
public void EraseOper() { //空间查询 ISpatialFilter tSF = new SpatialFilterClass(); tSF.Geometry = pEnvelope; tSF.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor tFeatureCursor = pFeatureClass.Search(tSF, false); IFeature tFeature = tFeatureCursor.NextFeature(); while (tFeature != null) { if (tFeature.Shape.SpatialReference != pEnvelope.SpatialReference) //sourceGeometry为被裁剪的图形 { pEnvelope.Project(tFeature.Shape.SpatialReference); } //此处应保持裁剪与被裁剪图层的空间参考一致,否则容易发生异常 switch (tFeature.Shape.GeometryType) { case esriGeometryType.esriGeometryPolygon: ITopologicalOperator tTope1 = pEnvelope as ITopologicalOperator; tTope1.Simplify(); ITopologicalOperator tTope2 = tFeature.ShapeCopy as ITopologicalOperator; tTope2.Simplify(); IGeometry tGeoDe = tTope2.Difference((IGeometry)tTope1); if (tFeature.Fields.get_Field(tFeature.Fields.FindField("Shape")).GeometryDef.HasZ) { IZAware zAware = (IZAware)tGeoDe; zAware.ZAware = true; IZ iz = (IZ)tGeoDe; iz.SetConstantZ(0); } tFeature.Shape = tGeoDe; tFeature.Store(); tFeature = tFeatureCursor.NextFeature(); break; default: break; } tFeature = tFeatureCursor.NextFeature(); } ReleaseCom(tFeatureCursor); }
/// <summary> /// Gets the difference in shape between the original and existing shape. /// </summary> /// <param name="source">The source.</param> /// <returns> /// Returns a <see cref="IGeometry" /> representing the difference in the shape; otherwise <c>null</c> /// </returns> public static IGeometry GetDifference(this IFeature source) { if (source == null) { return(null); } IFeatureChanges featureChanges = (IFeatureChanges)source; if (featureChanges.ShapeChanged && featureChanges.OriginalShape != null) { ITopologicalOperator topologicalOperator = (ITopologicalOperator)source.ShapeCopy; return(topologicalOperator.Difference(featureChanges.OriginalShape)); } return(null); }
/// <summary> /// source与other 对象比较不同的地方 /// return source-other; /// </summary> /// <param name="source"></param> /// <param name="other"></param> /// <returns></returns> public virtual IGeometry[] Erase(IGeometry source, IGeometry other) { ITopologicalOperator topoOper = source as ITopologicalOperator; if (!topoOper.IsSimple) { topoOper.Simplify(); } IGeometry geo = topoOper.Difference(other); topoOper = geo as ITopologicalOperator; if (!topoOper.IsSimple) { topoOper.Simplify(); } return(new IGeometry[] { geo }); }
/// <summary> /// 按照指定的各部分的面积将一个多边形切分成多个 /// (注意:指定的各部分的面积总和大于原多边形面积时,抛出异常;小于原多边形面积时,剩余的部分也将加入返回结果中) /// </summary> /// <param name="polygon">被切分的多边形</param> /// <param name="areas">切分后的多边形各个部分的面积,面积不能小于容差</param> /// <param name="direction">切分多边形的方向,0为横向,1为纵向</param> /// <param name="tolerance">面积容差</param> /// <returns></returns> public static List <IPolygon> SplitPolygonByAreas(IPolygon polygon, double[] areas, int direction, double tolerance = 0.001) { if (polygon.IsEmpty) { throw new Exception("几何图形不能为空(Empty)!"); } if (tolerance < 0) { throw new Exception("指定的容差不能小于0"); } var polygonArea = ((IArea)polygon).Area; if (areas.Sum() - polygonArea > tolerance * areas.Length) { throw new Exception("指定的各部分的面积总和,大于原多边形面积!"); } if (areas.Any(v => v <= tolerance)) { throw new Exception("指定的各部分的面积,存在小于容差的面积!"); } var resultPolygons = new List <IPolygon>(); var tmpPolygon = polygon; for (int i = 0; i < areas.Length; i++) { var resultPolygon = SplitPolygonByArea(tmpPolygon, areas[i], direction, tolerance) as IPolygon; //截取多边形 ITopologicalOperator logicalOpt = tmpPolygon as ITopologicalOperator; tmpPolygon = logicalOpt.Difference(resultPolygon) as IPolygon; //获取多边形截取后的剩余部分 resultPolygons.Add(resultPolygon); } //剩余部分也加入返回结果中 if (!tmpPolygon.IsEmpty) { resultPolygons.Add(tmpPolygon); } return(resultPolygons); }
/// <summary> /// 两个要素类进行擦除操作 /// </summary> /// <param name="sourceFeatureClass">源要素类</param> /// <param name="eraseFeatureClass">用于擦除的要素类,必须是个面要素类</param> public static void Erase(IFeatureClass sourceFeatureClass, IFeatureClass eraseFeatureClass) { if (eraseFeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon) { throw new Exception("EraseFeatureClass不是个面要素类"); } if (esriGeometryType.esriGeometryPoint == sourceFeatureClass.ShapeType) { throw new Exception("SourceFeatureClass不能是个点要素类"); } // 先要临时复制一个要素类 // 遍历用于擦除的要素 IFeatureCursor eraseFeatureCursor = eraseFeatureClass.Search(null, false); IFeature eraseFeature = null; while ((eraseFeature = eraseFeatureCursor.NextFeature()) != null) { ISpatialFilter spatialFilter = new SpatialFilterClass { Geometry = eraseFeature.Shape, SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects }; IFeatureCursor sourceFeatureCursor = sourceFeatureClass.Update(spatialFilter, false); IFeature sourceFeature = null; while ((sourceFeature = sourceFeatureCursor.NextFeature()) != null) { IGeometry geometry = sourceFeature.ShapeCopy; ITopologicalOperator topoOper = geometry as ITopologicalOperator; IGeometry geoDifference = topoOper.Difference(eraseFeature.Shape); sourceFeature.Shape = geoDifference; sourceFeatureCursor.UpdateFeature(sourceFeature); } // 释放游标 WorkspaceUtil.ReleaseComObject(sourceFeatureCursor); } }
/// <summary> /// 利用图形对指定要素进行图形求差(小面掏空大面) /// </summary> /// <param name="pFeatueCls">要素类</param> /// <param name="strCon">指定要素条件</param> /// <param name="pGeometry">求差图形</param> private void UpdateFeatureByOverlapArea(IFeatureClass pFeatueCls, string strCon, IGeometry pGeometry, out Exception err) { err = null; try { IQueryFilter pQf = new QueryFilterClass(); pQf.WhereClause = strCon; IFeatureCursor pFcursor = pFeatueCls.Update(pQf, false); IFeature pFeatTemp = pFcursor.NextFeature(); if (pFeatTemp != null) { ITopologicalOperator pTop = pFeatTemp.Shape as ITopologicalOperator; pTop.Simplify(); pFeatTemp.Shape = pTop.Difference(pGeometry); pFcursor.UpdateFeature(pFeatTemp); } System.Runtime.InteropServices.Marshal.ReleaseComObject(pFcursor); } catch (Exception exError) { err = exError; } }
/// <summary> /// 重复线 /// </summary> private void Line_redo(object para) { Plugin.Application.IAppFormRef pAppForm = para as Plugin.Application.IAppFormRef; System.Data.DataTable Datatable = new System.Data.DataTable(); //手动建立一个数据表,将得到的数据邦定到检查结果当中显示 Datatable.Columns.Add("重复线", typeof(string)); //创建一列 ///如果检查结果提示内有内容就清除 ClearDataCheckGrid ClearGrid = new ClearDataCheckGrid(); ClearGrid.Operate(pAppForm, _AppHk); #region 打开要操作的数据集 if (_AppHk.MapControl.LayerCount == 0) { return; //如果MAP上打开的图层为空,就返回 } SetCheckState.CheckShowTips(pAppForm, "重复线检查开始,准备载入检查数据,请稍后....."); int L_count = _AppHk.MapControl.LayerCount;//MAP上总图层数 if (L_count == 0) { return; //当MAP上是空,就返回 } IGeoDataset pGeoDataset = SetCheckState.Geodatabase; ITopologyRuleContainer pRuleCont = SetCheckState.pT as ITopologyRuleContainer;//引入拓扑规则接口对象,将拓扑转成对应的规则接口对象 #endregion try { #region 遍历整个数据集要素 ArrayList list_line = new ArrayList();//用动态的数组来接收满足线要素类的对象,以后面实现遍历拓扑检查 for (int l = 0; l < L_count; l++) { ILayer layer_1 = _AppHk.MapControl.get_Layer(l); //通过索引得到对应的层 #region //判别是不是组,如果是,就从组中取一个层 if (layer_1 is IGroupLayer && layer_1.Name == SetCheckState.CheckDataBaseName) { ICompositeLayer grouplayer_1 = layer_1 as ICompositeLayer;//把组图层转成组合图层 int group_count = grouplayer_1.Count; if (group_count == 0) { return; } for (int g = 0; g < group_count; g++) { ILayer layer_temp = grouplayer_1.get_Layer(g); IFeatureLayer pFeaturelayer = layer_temp as IFeatureLayer; IFeatureClass pFeatureClass = pFeaturelayer.FeatureClass; #region 将符合线要素的类加入到拓扑中 if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline && pFeatureClass.FeatureType != esriFeatureType.esriFTAnnotation && pFeatureClass.Search(null, false).NextFeature() != null) { list_line.Add(pFeatureClass);//将符合的要素类加入动态数组当中 } #endregion } break; } #endregion } #endregion SetCheckState.CheckShowTips(pAppForm, "数据准备完毕,准备进度显示数据,请稍后....."); #region 通过过滤后的要素类来进行拓扑检查 int Count = list_line.Count;//总要遍历的层数 if (Count == 0) { _AppHk.CurrentThread = null; SetCheckState.CheckShowTips(pAppForm, "重复线检查完成!"); SetCheckState.Message(pAppForm, "提示", "线重复检查完成!"); //选中检查出错列表 ClearGrid.CheckDataGridShow(pAppForm, _AppHk); return; } SetCheckState.TreeIni_Fun(list_line, _AppHk);//初始化树 SetCheckState.CheckShowTips(pAppForm, "进度数据准备完毕,马上进入拓扑分析,请稍后....."); for (int N = 0; N < Count; N++) { IFeatureClass TempClass = list_line[N] as IFeatureClass; //将对象转成相应的要素类 IDataset ds = TempClass as IDataset; SetCheckState.TreeCheckFun(ds.Name, N, _AppHk); //调用树节点选中 ITopologyRule topologyRule = new TopologyRuleClass(); //实例一个拓扑规则类 topologyRule.TopologyRuleType = esriTopologyRuleType.esriTRTLineNoOverlap; //使用规则的类型(线不重叠) topologyRule.Name = "www"; //给规则取个名 topologyRule.OriginClassID = TempClass.FeatureClassID; topologyRule.AllOriginSubtypes = true; pRuleCont.AddRule(topologyRule); ISegmentCollection pLocation = new PolygonClass(); //使用多边形接口 实例一个面的片段 pLocation.SetRectangle(pGeoDataset.Extent); //将我们用来操作验证的要素类利用SETRECTANGLE来构造一个完整的几何形体 IPolygon pPoly = SetCheckState.pT.get_DirtyArea(pLocation as IPolygon); IEnvelope pAreaValidated = SetCheckState.pT.ValidateTopology(pPoly.Envelope); //返回利用拓扑规则验证后的出错结果 SetCheckState.CheckShowTips(pAppForm, "拓扑分析中,请稍后....."); IErrorFeatureContainer pErrFeatCon = SetCheckState.pT as IErrorFeatureContainer; //实例一个拓扑出错的容器 IEnumTopologyErrorFeature pEnumTopoErrFeat = pErrFeatCon.get_ErrorFeatures(pGeoDataset.SpatialReference, topologyRule, pGeoDataset.Extent, true, false); //将所有的拓扑出错进行枚举 int num = N + 1; //由于层的索引是从0开始的,所以得加1 ITopologyErrorFeature Topo_ErrFeat = pEnumTopoErrFeat.Next(); //开始遍历拓扑错误,表示下一个s ArrayList TempTopList = new ArrayList(); //将当前层的所有出错要素放入动态数组当中 while (Topo_ErrFeat != null) { TempTopList.Add(Topo_ErrFeat);//将出错的要素存入动态数组 Topo_ErrFeat = pEnumTopoErrFeat.Next(); } SetCheckState.CheckShowTips(pAppForm, "拓扑分析完毕,进行具体检查操作,请稍后....."); int P_count = TempTopList.Count;//每个层的总出错记录 if (P_count == 0) { SetCheckState.CheckShowTips(pAppForm, "无重复线准备进行下一个图层操作,请稍后...."); continue; } SetCheckState.CheckShowTips(pAppForm, "正在进行" + TempClass.AliasName + "图层操作,请稍后...."); pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { true, pAppForm });//是否显示进度条,加载让它显示 #region 遍历出错 for (int p = 0; p < P_count; p++) { int i = p + 1; //方便计算 pAppForm.MainForm.Invoke(new ProcessBar(ControlProcessBar), new object[] { P_count, 0, 1, i, pAppForm }); //给进度条传需要的值 ITopologyErrorFeature pTopoErrFeat = TempTopList[p] as ITopologyErrorFeature; int OriginOID = pTopoErrFeat.OriginOID; //源ID int DestinationOID = pTopoErrFeat.DestinationOID; //目标ID IFeature source_fe = TempClass.GetFeature(OriginOID); //源要素 IFeature des_fe = TempClass.GetFeature(DestinationOID); //目标要素 ///求几何空间差值,必须要两种情况考虑:a->b b->a,如果同时都为空,说明两个重复 ITopologicalOperator Origin_0 = des_fe.Shape as ITopologicalOperator; //空间几何运算 IGeometry difference_0 = Origin_0.Difference(source_fe.Shape as IGeometry); //求两个面的差值 ITopologicalOperator Origin = source_fe.Shape as ITopologicalOperator; //空间几何运算 IGeometry difference = Origin.Difference(des_fe.Shape as IGeometry); //求两个面的差值 if (difference.IsEmpty && difference_0.IsEmpty) { StringBuilder origin_temp = new StringBuilder(); //除了SHAPE外的字段对比源 StringBuilder destination_temp = new StringBuilder(); //除了SHAPE外的字段对比目标 ArrayList list = Foreach(); //得到我们需要遍历的对比字段 int count = list.Count; if (count > 0) { for (int n = 0; n < count; n++) { int index = TempClass.GetFeature(OriginOID).Fields.FindFieldByAliasName(list[n].ToString()); //查看我们要对比的字段名是不是存在 源 int index1 = TempClass.GetFeature(DestinationOID).Fields.FindFieldByAliasName(list[n].ToString()); //查看我们要对比的字段名是不是存在 目标 if (index >= 0 && index1 >= 0) { origin_temp.Append(TempClass.GetFeature(OriginOID).get_Value(index)); destination_temp.Append(TempClass.GetFeature(DestinationOID).get_Value(index1)); } } if (origin_temp.Equals(destination_temp) && origin_temp != null && destination_temp != null) { string temp = ds.Name + " ID:" + OriginOID.ToString() + " 目标ID:" + DestinationOID.ToString(); System.Data.DataRow Row = Datatable.NewRow(); Row[0] = temp; Datatable.Rows.Add(Row); SetCheckState.CheckShowTips(pAppForm, temp); } else { pTopoErrFeat = pEnumTopoErrFeat.Next(); continue; } } else { string temp = ds.Name + " ID:" + OriginOID.ToString() + " 目标ID:" + DestinationOID.ToString(); System.Data.DataRow Row = Datatable.NewRow(); Row[0] = temp; Datatable.Rows.Add(Row); SetCheckState.CheckShowTips(pAppForm, temp); } } } #endregion pRuleCont.DeleteRule(topologyRule);//移除拓扑规则 if (num == Count) { SetCheckState.CheckShowTips(pAppForm, "重复线检查马上完成,请稍后...."); break; } } pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { false, pAppForm }); //显示完成隐藏进度条 pAppForm.MainForm.Invoke(new Update_data(Bind), new object[] { Datatable, _AppHk }); //将窗体控件进行方法的委托,因为得让它成为安全的 _AppHk.CurrentThread = null; //将线程置空 SetCheckState.CheckShowTips(pAppForm, "重复线检查完成!"); SetCheckState.Message(pAppForm, "提示", "线重复检查完成!"); //选中检查出错列表 ClearGrid.CheckDataGridShow(pAppForm, _AppHk); #endregion } catch (Exception ex) { _AppHk.CurrentThread = null;//将线程置空 MessageBox.Show(ex.ToString()); return; } }
//to be improved, a vertical cutter may cause unexpected problems // public void CreateBufferWithoutEnds(IGeometry fBufferGeo, double dblBuffer) { //StartCutPolyline ILine pStartNormal = new LineClass(); this.pPolyline.QueryNormal(esriSegmentExtension.esriNoExtension, 0, true, dblBuffer, pStartNormal); IPoint StartFrPt = new PointClass(); pStartNormal.QueryPoint(esriSegmentExtension.esriExtendAtFrom, -1.5, true, StartFrPt); IPoint StartToPt = new PointClass(); pStartNormal.QueryPoint(esriSegmentExtension.esriExtendAtTo, 1.5, true, StartToPt); IPointCollection4 pStartCutterCol = new PolylineClass(); pStartCutterCol.AddPoint(StartFrPt); pStartCutterCol.AddPoint(StartToPt); IPolyline5 pStartCutter = pStartCutterCol as IPolyline5; //EndCutPolyline ILine pEndNormal = new LineClass(); this.pPolyline.QueryNormal(esriSegmentExtension.esriNoExtension, 1, true, dblBuffer, pEndNormal); IPoint EndFrPt = new PointClass(); pEndNormal.QueryPoint(esriSegmentExtension.esriExtendAtFrom, -1.5, true, EndFrPt); IPoint EndToPt = new PointClass(); pEndNormal.QueryPoint(esriSegmentExtension.esriExtendAtTo, 1.5, true, EndToPt); IPointCollection4 pEndCutterCol = new PolylineClass(); pEndCutterCol.AddPoint(EndFrPt); pEndCutterCol.AddPoint(EndToPt); IPolyline5 pEndCutter = pEndCutterCol as IPolyline5; //TopologicalOperators ITopologicalOperator pStartPtTop = this.pPolyline.FromPoint as ITopologicalOperator; IGeometry pStartPtBuffer = pStartPtTop.Buffer(dblBuffer); ITopologicalOperator pEndPtTop = this.pPolyline.ToPoint as ITopologicalOperator; IGeometry pEndPtBuffer = pEndPtTop.Buffer(dblBuffer); //Cut ITopologicalOperator pStartPtBufferTop = pStartPtBuffer as ITopologicalOperator; IGeometry StartLeftOutGeometry; IGeometry StartRightOutGeometry; pStartPtBufferTop.Cut(pStartCutter, out StartLeftOutGeometry, out StartRightOutGeometry); ITopologicalOperator pEndPtBufferTop = pEndPtBuffer as ITopologicalOperator; IGeometry EndLeftOutGeometry; IGeometry EndRightOutGeometry; pEndPtBufferTop.Cut(pEndCutter, out EndLeftOutGeometry, out EndRightOutGeometry); //Difference ITopologicalOperator pBufferTop = fBufferGeo as ITopologicalOperator; IGeometry pDiffStart = pBufferTop.Difference(StartRightOutGeometry); ITopologicalOperator pDiffStartTop = pDiffStart as ITopologicalOperator; IGeometry pDiffEnd = pDiffStartTop.Difference(EndLeftOutGeometry); _pBufferGeoWithoutEnds = pDiffEnd; }
public void GenerateDeadArea() { try { IGeometry pCoverageGeom = null; IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)_workspace; IWorkspaceEdit pWorspaceEdit = (IWorkspaceEdit)pFeatureWorkspace; ServiceTerritory pST = new ServiceTerritory(_workspace, "Main"); if (pST.ServiceTerritoryFeature != null) { if (pCoverageGeom == null) { pCoverageGeom = pST.ServiceTerritoryFeature.Shape; } else { ITopologicalOperator pTopoUnion = (ITopologicalOperator)pCoverageGeom; pCoverageGeom = pTopoUnion.Union(pST.ServiceTerritoryFeature.Shape); } } IFeatureClass pServiceFC = pFeatureWorkspace.OpenFeatureClass("ServiceTerritory"); IFeatureCursor pServiceCursor = pServiceFC.Search(null, false); IFeature pServiceFeature = pServiceCursor.NextFeature(); ITopologicalOperator pTopoClip = (ITopologicalOperator)pServiceFeature.Shape; IGeometry pDeadArea = pTopoClip.Difference(pCoverageGeom); IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)_workspace; pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); IFeatureClass pDeadFC = pFeatureWorkspace.OpenFeatureClass("DeadArea"); IFeatureCursor pDeleteCursor = pDeadFC.Search(null, false); IFeature pExistingFeature = pDeleteCursor.NextFeature(); while (pExistingFeature != null) { pExistingFeature.Delete(); pExistingFeature = pDeleteCursor.NextFeature(); } IFeature pDeadFeature = pDeadFC.CreateFeature(); pDeadFeature.Shape = pDeadArea; //pDeadFeature.set_Value(pDeadFeature.Fields.FindField("COVERAGE_PCT"), dead_pct); pDeadFeature.Store(); pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); int dead_pct = (int)(100 * ((IArea)pDeadFeature.Shape).Area / ((IArea)pServiceFeature.Shape).Area); int reception_pct = 100 - dead_pct; //pST.UpdateCoveragePct(dead_pct, reception_pct); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void GetTowerCoverage(Towers pTowers) { IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)_workspace; IFeatureClass pRangeFC = pFeatureWorkspace.OpenFeatureClass("TowerRanges"); IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)_workspace; try { pWorkspaceEdit.StartEditing(true); pWorkspaceEdit.StartEditOperation(); IFeatureCursor pRangeCursor = pRangeFC.Update(null, false); //IFeature pFeature = pRangeCursor.NextFeature(); while (pRangeCursor.NextFeature() != null) { //pFeature.Delete(); //pFeature = pRangeCursor.NextFeature(); pRangeCursor.DeleteFeature(); } foreach (Tower pTower in pTowers.Items) { //Tower pTower = tm.GetTowerByID("T04"); double towerRange = pTower.towerCoverage; ITopologicalOperator pTopo = (ITopologicalOperator)pTower.towerLocation; IPolygon range3Bars = (IPolygon)pTopo.Buffer(towerRange / 3); IPolygon range2BarsWhole = (IPolygon)pTopo.Buffer(towerRange * 2 / 3); ITopologicalOperator p2BarTopo = (ITopologicalOperator)range2BarsWhole; IPolygon range2BarsDonut = (IPolygon)p2BarTopo.Difference(range3Bars); IPolygon range1BarWhole = (IPolygon)pTopo.Buffer(towerRange); ITopologicalOperator p1BarTopo = (ITopologicalOperator)range1BarWhole; IPolygon range1BarDonut = (IPolygon)p1BarTopo.Difference(range2BarsWhole); //IFeatureWorkspace pFWorkspace = (IFeatureWorkspace)pWorkspaceEdit; //IFeatureClass pTowerRangeFC = pFWorkspace.OpenFeatureClass("TowerRanges"); IFeature pFeature = pRangeFC.CreateFeature(); pFeature.set_Value(pFeature.Fields.FindField("TOWERID"), pTower.ID); pFeature.set_Value(pFeature.Fields.FindField("RANGE"), 3); pFeature.Shape = range3Bars; pFeature.Store(); IFeature p2BarsFeature = pRangeFC.CreateFeature(); p2BarsFeature.set_Value(pFeature.Fields.FindField("TOWERID"), pTower.ID); p2BarsFeature.set_Value(pFeature.Fields.FindField("RANGE"), 2); p2BarsFeature.Shape = range2BarsDonut; p2BarsFeature.Store(); IFeature p1BarsFeature = pRangeFC.CreateFeature(); p1BarsFeature.set_Value(pFeature.Fields.FindField("TOWERID"), pTower.ID); p1BarsFeature.set_Value(pFeature.Fields.FindField("RANGE"), 1); p1BarsFeature.Shape = range1BarDonut; p1BarsFeature.Store(); } pWorkspaceEdit.StopEditOperation(); pWorkspaceEdit.StopEditing(true); } catch (Exception ex) { pWorkspaceEdit.AbortEditOperation(); MessageBox.Show(ex.ToString()); } }
/// <summary> /// 重复面 /// </summary> private void Cover(object para) { Plugin.Application.IAppFormRef pAppForm = para as Plugin.Application.IAppFormRef; System.Data.DataTable Datatable = new System.Data.DataTable();//手动建立一个数据表,将得到的数据邦定到检查结果当中显示 ///如果检查结果提示内有内容就清除 ClearDataCheckGrid ClearGrid = new ClearDataCheckGrid(); ClearGrid.Operate(pAppForm, _AppHk); Datatable.Columns.Add("重复面", typeof(string));//创建一列 #region 打开要操作的数据集 int L_count = _AppHk.MapControl.LayerCount;//MAP上总图层数 if (L_count == 0) { return; //当MAP上是空,就返回 } SetCheckState.CheckShowTips(pAppForm, "面重复检查开始......"); IGeoDataset pGeoDataset = SetCheckState.Geodatabase; ITopologyRuleContainer pRuleCont = SetCheckState.pRuleCont;//引入拓扑规则接口对象,将拓扑转成对应的规则接口对象 #endregion try { #region 遍历整个数据集要素 ArrayList list_line = new ArrayList();//用动态的数组来接收满足线要素类的对象,以后面实现遍历拓扑检查 for (int l = 0; l < L_count; l++) { ILayer layer_1 = _AppHk.MapControl.get_Layer(l); //通过索引得到对应的层 #region //判别是不是组,如果是,就从组中取一个层 if (layer_1 is IGroupLayer && layer_1.Name == SetCheckState.CheckDataBaseName) { ICompositeLayer grouplayer_1 = layer_1 as ICompositeLayer;//把组图层转成组合图层 int group_count = grouplayer_1.Count; if (group_count == 0) { return; } for (int g = 0; g < group_count; g++) { ILayer layer_temp = grouplayer_1.get_Layer(g); IFeatureLayer pFeaturelayer = layer_temp as IFeatureLayer; IFeatureClass pFeatureClass = pFeaturelayer.FeatureClass; #region 将符合线要素的类加入到拓扑中 if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon && pFeatureClass.FeatureType != esriFeatureType.esriFTAnnotation && pFeatureClass.Search(null, false).NextFeature() != null) { list_line.Add(pFeatureClass);//将符合的要素类加入动态数组当中 } #endregion } } #endregion } #endregion int Count = list_line.Count; if (Count == 0) { SetCheckState.CheckShowTips(pAppForm, "重复面检查完成!"); _AppHk.CurrentThread = null; SetCheckState.Message(pAppForm, "提示", "面重复检查完成!"); //选中检查出错列表 ClearGrid.CheckDataGridShow(pAppForm, _AppHk); return; } if (Count == 0) { return; } SetCheckState.TreeIni_Fun(list_line, _AppHk);//初始化树图 SetCheckState.CheckShowTips(pAppForm, "检查数据准备完毕,请稍后........"); #region 通过过滤后的要素类来进行拓扑检查 for (int N = 0; N < Count; N++) { int num = N + 1;//由于层的索引是从0开始的,所以得加1 #region 创建拓扑并验证拓扑 IFeatureClass TempClass = list_line[N] as IFeatureClass; //将对象转成相应的要素类 IDataset ds = TempClass as IDataset; SetCheckState.TreeCheckFun(ds.Name, N, _AppHk); //调用树节点选中方法 ITopologyRule topologyRule = new TopologyRuleClass(); //实例一个拓扑规则类 topologyRule.TopologyRuleType = esriTopologyRuleType.esriTRTAreaNoOverlap; //使用规则的类型(面不相交) topologyRule.Name = "www"; //给规则取个名 topologyRule.OriginClassID = TempClass.FeatureClassID; topologyRule.AllOriginSubtypes = true; pRuleCont.AddRule(topologyRule); ISegmentCollection pLocation = new PolygonClass(); //使用多边形接口 pLocation.SetRectangle(pGeoDataset.Extent); //将我们用来操作验证的要素类利用SETRECTANGLE来构造一个完整的几何形体 IPolygon pPoly = SetCheckState.pT.get_DirtyArea(pLocation as IPolygon); IEnvelope pAreaValidated = SetCheckState.pT.ValidateTopology(pPoly.Envelope); //验证拓扑 SetCheckState.CheckShowTips(pAppForm, "正在进行拓扑分析,请稍后........"); IErrorFeatureContainer pErrFeatCon = SetCheckState.pT as IErrorFeatureContainer; //实例一个拓扑出错的容器 IEnumTopologyErrorFeature pEnumTopoErrFeat = pErrFeatCon.get_ErrorFeatures(pGeoDataset.SpatialReference, topologyRule, pGeoDataset.Extent, true, false); //将所有的拓扑出错进行枚举 #endregion ITopologyErrorFeature Topo_ErrFeat = pEnumTopoErrFeat.Next();//开始遍历拓扑错误,表示下一个s ArrayList TempTopList = new ArrayList(); //将当前层的所有出错要素放入动态数组当中 while (Topo_ErrFeat != null) { TempTopList.Add(Topo_ErrFeat);//将出错的要素存入动态数组 Topo_ErrFeat = pEnumTopoErrFeat.Next(); } int P_count = TempTopList.Count;//每个层的总出错记录 if (P_count == 0) { SetCheckState.CheckShowTips(pAppForm, "图层完好,准备进行下一个图层,请稍后........"); continue; } pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { true, pAppForm });//是否显示进度条,加载让它显示 #region 遍历出错 for (int p = 0; p < P_count; p++) { int i = p + 1; //方便计算 pAppForm.MainForm.Invoke(new ProcessBar(ControlProcessBar), new object[] { P_count, 0, 1, i, pAppForm }); //给进度条传需要的值 ITopologyErrorFeature pTopoErrFeat = TempTopList[p] as ITopologyErrorFeature; int OriginOID = pTopoErrFeat.OriginOID; //源ID int DestinationOID = pTopoErrFeat.DestinationOID; //目标ID IFeature source_fe = TempClass.GetFeature(OriginOID); //源要素 IFeature des_fe = TempClass.GetFeature(DestinationOID); //目标要素 #region 通过拓扑出来的错进行再次分析求重复面 ///求几何空间差值,必须要两种情况考虑:a->b b->a,如果同时都为空,说明两个重复 ITopologicalOperator Origin_0 = des_fe.Shape as ITopologicalOperator; //空间几何运算 IGeometry difference_0 = Origin_0.Difference(source_fe.Shape as IGeometry); //求两个面的差值 ITopologicalOperator Origin = source_fe.Shape as ITopologicalOperator; //空间几何运算 IGeometry difference = Origin.Difference(des_fe.Shape as IGeometry); //求两个面的差值 if (difference.IsEmpty && difference_0.IsEmpty) { #region MyRegion // StringBuilder origin_temp = new StringBuilder();//除了SHAPE外的字段对比源 // StringBuilder destination_temp = new StringBuilder();//除了SHAPE外的字段对比目标 // //IDataset ds = TempClass as IDataset; // ArrayList list = Foreach();//调用要对比的XML文件里的字段名 // int count = list.Count; // #region 通过拓扑出错及对出错的对象再次的进行差值及字段对比,得出最终的结果是否一样 // if (count > 0) // { // #region 得到要实际比较的字段值 // for (int n = 0; n < count; n++) // { // int index = TempClass.GetFeature(OriginOID).Fields.FindFieldByAliasName(list[n].ToString());//得到源的列ID // int index1 = TempClass.GetFeature(DestinationOID).Fields.FindFieldByAliasName(list[n].ToString());//得到目标的列ID // if (index > 0 && index1 > 0) // { // origin_temp.Append(TempClass.GetFeature(OriginOID).get_Value(index));//在对应的要素类当中取出源对应ID列的值,加入BUILDER中 // destination_temp.Append(TempClass.GetFeature(DestinationOID).get_Value(index1));//在对应的要素类当中取出目标对应的ID列值,加入目录的BUILDER中 // } // } // #endregion // #region 比较两个值是否一样 // if (origin_temp.ToString() == destination_temp.ToString() && origin_temp != null && destination_temp != null)//将两个列的值进行对比 // { #endregion string temp = ds.Name + " ID:" + OriginOID.ToString() + " 目标ID:" + DestinationOID.ToString(); System.Data.DataRow Row = Datatable.NewRow(); //新创建一个行 Row[0] = temp; Datatable.Rows.Add(Row); //将行加入到表数据集中 SetCheckState.CheckShowTips(pAppForm, temp); #region // } // else // { // pTopoErrFeat = pEnumTopoErrFeat.Next();//遍历下一个错误 // continue; // } // #endregion // } // else // { // string temp = ds.Name + " ID:" + OriginOID.ToString() + " 目标ID:" + DestinationOID.ToString();//将结果组织起来,放到一个字符串当中 // System.Data.DataRow Row = Datatable.NewRow();//新创建一个行 // Row[0] = temp; // Datatable.Rows.Add(Row);//将行加入到表数据集中 // } #endregion } #endregion } pRuleCont.DeleteRule(topologyRule); #endregion if (num == Count) { string Case = "马上完成请稍后.....";//状态栏显示 SetCheckState.CheckShowTips(pAppForm, Case); } } #endregion pAppForm.MainForm.Invoke(new Update_data(Bind), new object[] { Datatable, _AppHk }); //将窗体控件使用委托 pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { false, pAppForm }); //是否显示进度条,加载让它显示 _AppHk.CurrentThread = null; SetCheckState.Message(pAppForm, "提示", "面重复检查完成!"); //选中检查出错列表 SetCheckState.CheckShowTips(pAppForm, "面重复检查完成!"); ClearGrid.CheckDataGridShow(pAppForm, _AppHk); } catch (Exception ex) { _AppHk.CurrentThread = null; SetCheckState.Message(pAppForm, "错误", ex.ToString()); return; } }
public static void Subtract(ITopology pTopology, ITopologyErrorFeature pTopoErrorFeat) { IGeometry geometry; string[] strArray; frmSelectMergeFeature feature3; IFeatureClass class2 = (pTopology as IFeatureClassContainer).get_ClassByID(pTopoErrorFeat.OriginClassID); IFeatureClass class3 = null; try { if (pTopoErrorFeat.DestinationClassID != 0) { class3 = (pTopology as IFeatureClassContainer).get_ClassByID(pTopoErrorFeat.DestinationClassID); } } catch { } IFeature feature = null; IFeature feature2 = null; ITopologicalOperator shapeCopy = null; switch (pTopoErrorFeat.TopologyRuleType) { case esriTopologyRuleType.esriTRTAreaNoOverlap: feature = class2.GetFeature(pTopoErrorFeat.OriginOID); feature2 = class2.GetFeature(pTopoErrorFeat.DestinationOID); geometry = (feature.ShapeCopy as ITopologicalOperator).Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); break; } feature.Delete(); break; case esriTopologyRuleType.esriTRTAreaCoveredByAreaClass: feature = class2.GetFeature(pTopoErrorFeat.OriginOID); shapeCopy = feature.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); return; } feature.Delete(); return; case esriTopologyRuleType.esriTRTAreaAreaCoverEachOther: strArray = new string[] { class2.AliasName + "-" + pTopoErrorFeat.OriginOID, class3.AliasName + "-" + pTopoErrorFeat.DestinationOID }; feature3 = new frmSelectMergeFeature { FeatureInfos = strArray, Text = "删除" }; if (feature3.ShowDialog() == DialogResult.OK) { feature = class2.GetFeature(pTopoErrorFeat.OriginOID); feature2 = class3.GetFeature(pTopoErrorFeat.DestinationOID); if (feature3.SelectedIndex != 0) { shapeCopy = feature2.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature2.Delete(); } else { feature2.Shape = geometry; feature2.Store(); } return; } shapeCopy = feature.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); return; } feature.Delete(); } return; case ((esriTopologyRuleType)6): case (esriTopologyRuleType.esriTRTAreaNoOverlapArea | esriTopologyRuleType.esriTRTAreaNoGaps): return; case esriTopologyRuleType.esriTRTAreaCoveredByArea: if (pTopoErrorFeat.OriginOID <= 0) { feature2 = class3.GetFeature(pTopoErrorFeat.DestinationOID); geometry = (feature2.ShapeCopy as ITopologicalOperator).Difference((pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature2.Delete(); } else { feature2.Shape = geometry; feature2.Store(); } return; } feature = class2.GetFeature(pTopoErrorFeat.OriginOID); geometry = (feature.ShapeCopy as ITopologicalOperator).Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); return; } feature.Delete(); return; case esriTopologyRuleType.esriTRTAreaNoOverlapArea: feature = class2.GetFeature(pTopoErrorFeat.OriginOID); feature2 = class3.GetFeature(pTopoErrorFeat.DestinationOID); geometry = (feature.ShapeCopy as ITopologicalOperator).Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); } else { feature.Delete(); } geometry = (feature2.ShapeCopy as ITopologicalOperator).Difference((pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature2.Delete(); } else { feature2.Shape = geometry; feature2.Store(); } return; case esriTopologyRuleType.esriTRTLineCoveredByAreaBoundary: feature = class2.GetFeature(pTopoErrorFeat.OriginOID); shapeCopy = feature.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); return; } feature.Delete(); return; case esriTopologyRuleType.esriTRTLineNoOverlap: strArray = new string[] { class2.AliasName + "-" + pTopoErrorFeat.OriginOID, class2.AliasName + "-" + pTopoErrorFeat.DestinationOID }; feature3 = new frmSelectMergeFeature { FeatureInfos = strArray }; if (feature3.ShowDialog() == DialogResult.OK) { feature = class2.GetFeature(pTopoErrorFeat.OriginOID); feature2 = class2.GetFeature(pTopoErrorFeat.DestinationOID); if (feature3.SelectedIndex != 0) { shapeCopy = feature2.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature2.Delete(); } else { feature2.Shape = geometry; feature2.Store(); } return; } shapeCopy = feature.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); return; } feature.Delete(); } return; case esriTopologyRuleType.esriTRTLineNoIntersection: strArray = new string[] { class2.AliasName + "-" + pTopoErrorFeat.OriginOID, class2.AliasName + "-" + pTopoErrorFeat.DestinationOID }; feature3 = new frmSelectMergeFeature { FeatureInfos = strArray }; if (feature3.ShowDialog() == DialogResult.OK) { feature = class2.GetFeature(pTopoErrorFeat.OriginOID); feature2 = class2.GetFeature(pTopoErrorFeat.DestinationOID); if (feature3.SelectedIndex != 0) { shapeCopy = feature2.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature2.Delete(); } else { feature2.Shape = geometry; feature2.Store(); } return; } shapeCopy = feature.ShapeCopy as ITopologicalOperator; geometry = shapeCopy.Difference((pTopoErrorFeat as IFeature).Shape); if (!geometry.IsEmpty) { feature.Shape = geometry; feature.Store(); return; } feature.Delete(); } return; case esriTopologyRuleType.esriTRTLineNoIntersectOrInteriorTouch: strArray = new string[] { class2.AliasName + "-" + pTopoErrorFeat.OriginOID, class2.AliasName + "-" + pTopoErrorFeat.DestinationOID }; feature3 = new frmSelectMergeFeature { FeatureInfos = strArray, Text = "删除" }; if (feature3.ShowDialog() == DialogResult.OK) { feature = class2.GetFeature(pTopoErrorFeat.OriginOID); feature2 = class2.GetFeature(pTopoErrorFeat.DestinationOID); if (feature3.SelectedIndex != 0) { geometry = (feature2.ShapeCopy as ITopologicalOperator).Difference( (pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature2.Delete(); } else { feature2.Shape = geometry; feature2.Store(); } return; } geometry = (feature.ShapeCopy as ITopologicalOperator).Difference((pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature.Delete(); } else { feature.Shape = geometry; feature.Store(); } } return; default: return; } geometry = (feature2.ShapeCopy as ITopologicalOperator).Difference((pTopoErrorFeat as IFeature).Shape); if (geometry.IsEmpty) { feature2.Delete(); } else { feature2.Shape = geometry; feature2.Store(); } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button != (int)Keys.LButton) { return; } ILayer layer = m_engineEditor.TargetLayer; if (layer == null) { MessageBox.Show("请先启动编辑!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } m_activeView = m_hookHelper.ActiveView; m_map = m_hookHelper.FocusMap; if (m_map == null || m_activeView == null) { return; } IPoint pPoint = m_activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); ISelectionEnvironment pSelectionEnvironment = new SelectionEnvironmentClass(); pSelectionEnvironment.PointSelectionMethod = esriSpatialRelEnum.esriSpatialRelWithin; m_map.SelectByShape(pPoint as IGeometry, pSelectionEnvironment, false); if (m_map.SelectionCount != 2) { MessageBox.Show("选择的多边形个数应该为2!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, m_activeView.Extent); bool deleteInteriorPolygon = false; DialogResult pDialogResult = MessageBox.Show("是否要删除内多边形?", "操作提示", MessageBoxButtons.YesNo); if (pDialogResult == DialogResult.Yes) { deleteInteriorPolygon = true; } IEnumFeature pEnumFeature = m_map.FeatureSelection as IEnumFeature; IEnumFeatureSetup pEnumFeatureSetup = pEnumFeature as IEnumFeatureSetup; pEnumFeatureSetup.AllFields = true; IFeature firstFeature = pEnumFeature.Next(); IFeature secondFeature = pEnumFeature.Next(); IArea pAreaFirst = firstFeature.Shape as IArea; IArea pAreaSecond = secondFeature.Shape as IArea; IGeometry pGeometry = null; bool firstPolygonIsLarge = false; IRelationalOperator pRelationalOperator = firstFeature.Shape as IRelationalOperator; if (pAreaFirst.Area > pAreaSecond.Area) { if (pRelationalOperator.Contains(secondFeature.Shape)) { ITopologicalOperator pTopologicalOperator = firstFeature.Shape as ITopologicalOperator; pGeometry = pTopologicalOperator.Difference(secondFeature.Shape); firstPolygonIsLarge = true; } } else { pRelationalOperator = secondFeature.Shape as IRelationalOperator; if (pRelationalOperator.Contains(firstFeature.Shape)) { ITopologicalOperator pTopologicalOperator = secondFeature.Shape as ITopologicalOperator; pGeometry = pTopologicalOperator.Difference(firstFeature.Shape); firstPolygonIsLarge = false; } } IFeatureClass featureClass = firstFeature.Class as IFeatureClass; IDataset dataset = featureClass as IDataset; IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit; if (!(workspaceEdit.IsBeingEdited())) { return; } workspaceEdit.StartEditOperation(); if (firstPolygonIsLarge) { firstFeature.Shape = pGeometry; firstFeature.Store(); if (deleteInteriorPolygon) { secondFeature.Delete(); } } else { secondFeature.Shape = pGeometry; secondFeature.Store(); if (deleteInteriorPolygon) { firstFeature.Delete(); } } workspaceEdit.StopEditOperation(); m_map.ClearSelection(); m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent); }
/// <summary> /// Where all of the work is done. Override from TabBaseViewModel /// </summary> internal override void CreateMapElement() { try { IsRunning = true; if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null || string.IsNullOrWhiteSpace(SelectedSurfaceName)) { return; } //base.CreateMapElement(); var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName); if (surface == null) { return; } // Determine if selected surface is projected or geographic ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName); var geoDataset = surfaceLayer as IGeoDataset; SelectedSurfaceSpatialRef = geoDataset.SpatialReference; if (SelectedSurfaceSpatialRef is IGeographicCoordinateSystem) { MessageBox.Show(VisibilityLibrary.Properties.Resources.RLOSUserPrompt, VisibilityLibrary.Properties.Resources.RLOSUserPromptCaption); return; } if (geoDataset != null && ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode) { MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSDataFrameMatch, VisibilityLibrary.Properties.Resources.LOSSpatialReferenceCaption); return; } using (ComReleaser oComReleaser = new ComReleaser()) { // Create feature workspace IFeatureWorkspace workspace = CreateFeatureWorkspace("tempWorkspace"); StartEditOperation((IWorkspace)workspace); // Create feature class IFeatureClass pointFc = CreateObserversFeatureClass(workspace, SelectedSurfaceSpatialRef, "Output" + RunCount.ToString()); double finalObserverOffset = GetOffsetInZUnits(ObserverOffset.Value, surface.ZFactor, OffsetUnitType); double finalSurfaceOffset = GetOffsetInZUnits(SurfaceOffset, surface.ZFactor, OffsetUnitType); double conversionFactor = GetConversionFactor(SelectedSurfaceSpatialRef); double convertedMinDistance = MinDistance * conversionFactor; double convertedMaxDistance = MaxDistance * conversionFactor; double finalMinDistance = GetLinearDistance(ArcMap.Document.FocusMap, convertedMinDistance, OffsetUnitType); double finalMaxDistance = GetLinearDistance(ArcMap.Document.FocusMap, convertedMaxDistance, OffsetUnitType); double finalLeftHorizontalFOV = GetAngularDistance(ArcMap.Document.FocusMap, LeftHorizontalFOV, AngularUnitType); double finalRightHorizontalFOV = GetAngularDistance(ArcMap.Document.FocusMap, RightHorizontalFOV, AngularUnitType); double finalBottomVerticalFOV = GetAngularDistance(ArcMap.Document.FocusMap, BottomVerticalFOV, AngularUnitType); double finalTopVerticalFOV = GetAngularDistance(ArcMap.Document.FocusMap, TopVerticalFOV, AngularUnitType); // Out radius geometries List <IGeometry> radius2GeomList = new List <IGeometry>(); List <IGeometry> radius1_2GeomList = new List <IGeometry>(); List <IGeometry> donutGeomList = new List <IGeometry>(); foreach (var observerPoint in ObserverAddInPoints) { // Create buffer geometries for final Min/Max distance ITopologicalOperator topologicalOperator = observerPoint.Point as ITopologicalOperator; IGeometry geom = topologicalOperator.Buffer(finalMaxDistance); radius2GeomList.Add(geom); radius1_2GeomList.Add(geom); if (finalMinDistance > 0) { IGeometry geom2 = topologicalOperator.Buffer(finalMinDistance); ITopologicalOperator eraseTopo = geom as ITopologicalOperator; IGeometry erasedGeom = eraseTopo.Difference(geom2); donutGeomList.Add(erasedGeom); } else { radius1_2GeomList.Add(geom); } double z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset; //create a new point feature IFeature ipFeature = pointFc.CreateFeature(); // Set the field values for the feature SetFieldValues(finalObserverOffset, finalSurfaceOffset, finalMinDistance, finalMaxDistance, finalLeftHorizontalFOV, finalRightHorizontalFOV, finalBottomVerticalFOV, finalTopVerticalFOV, ipFeature); if (double.IsNaN(z1)) { System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.RLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled); return; } //Create shape IPoint point = new PointClass() { Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true }; ipFeature.Shape = point; ipFeature.Store(); } IFeatureClassDescriptor fd = new FeatureClassDescriptorClass(); fd.Create(pointFc, null, "OBJECTID"); StopEditOperation((IWorkspace)workspace); try { ILayer layer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName); string layerPath = GetLayerPath(layer); IFeatureLayer ipFeatureLayer = new FeatureLayerClass(); ipFeatureLayer.FeatureClass = pointFc; IDataset ipDataset = (IDataset)pointFc; string outputFcName = ipDataset.BrowseName + "_output"; string strPath = ipDataset.Workspace.PathName + "\\" + ipDataset.BrowseName; string outPath = ipDataset.Workspace.PathName + "\\" + outputFcName; IVariantArray parameters = new VarArrayClass(); parameters.Add(layerPath); parameters.Add(strPath); parameters.Add(outPath); esriLicenseStatus status = GetSpatialAnalystLicense(); if (status == esriLicenseStatus.esriLicenseUnavailable || status == esriLicenseStatus.esriLicenseFailure || status == esriLicenseStatus.esriLicenseNotInitialized || status == esriLicenseStatus.esriLicenseNotLicensed || status == esriLicenseStatus.esriLicenseUnavailable) { System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSSpatialAnalystLicenseInvalid, VisibilityLibrary.Properties.Resources.MsgCalcCancelled); return; } IGeoProcessor2 gp = new GeoProcessorClass(); gp.AddOutputsToMap = false; // Add a mask to buffer the output to selected distance SetGPMask(workspace, radius2GeomList, gp, "radiusMask"); object oResult = gp.Execute("Visibility_sa", parameters, null); IGeoProcessorResult ipResult = (IGeoProcessorResult)oResult; ComReleaser.ReleaseCOMObject(gp); gp = null; GC.Collect(); // Add buffer geometries to the map foreach (IGeometry geom in radius1_2GeomList) { var color = new RgbColorClass() { Blue = 255 } as IColor; AddGraphicToMap(geom, color, true); } IRasterLayer outputRasterLayer = new RasterLayerClass(); outputRasterLayer.CreateFromFilePath(outPath); string fcName = IntersectOutput(outputRasterLayer, ipDataset, workspace, donutGeomList); IFeatureClass finalFc = workspace.OpenFeatureClass(fcName); IFeatureLayer outputFeatureLayer = new FeatureLayerClass(); outputFeatureLayer.FeatureClass = finalFc; //Add it to a map if the layer is valid. if (outputFeatureLayer != null) { // set the renderer IFeatureRenderer featRend = UniqueValueRenderer(workspace, finalFc); IGeoFeatureLayer geoLayer = outputFeatureLayer as IGeoFeatureLayer; geoLayer.Renderer = featRend; geoLayer.Name = "RLOS_Visibility_" + RunCount.ToString(); // Set the layer transparency IDisplayFilterManager filterManager = (IDisplayFilterManager)outputFeatureLayer; ITransparencyDisplayFilter filter = new TransparencyDisplayFilter(); filter.Transparency = 80; filterManager.DisplayFilter = filter; ESRI.ArcGIS.Carto.IMap map = ArcMap.Document.FocusMap; map.AddLayer((ILayer)outputFeatureLayer); IEnvelope envelope = outputFeatureLayer.AreaOfInterest.Envelope; ZoomToExtent(envelope); } RunCount += 1; } catch (Exception ex) { System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled); } //Reset(true); } } catch (Exception ex) { System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled); } finally { IsRunning = false; } }
private void btnup_Click(object sender, EventArgs e) { //设置一个最小值 progressBarControl1.Properties.Minimum = 0; //设置步长,即每次增加的数 progressBarControl1.Properties.Step = 1; //设置进度条的样式 progressBarControl1.Properties.ProgressViewStyle = DevExpress.XtraEditors.Controls.ProgressViewStyle.Solid; progressBarControl1.Position = 0; //设置一个最小值 progressBarControl2.Properties.Minimum = 0; //设置一个最大值 progressBarControl2.Properties.Maximum = listView1.CheckedItems.Count * 2; //设置步长,即每次增加的数 progressBarControl2.Properties.Step = 1; //设置进度条的样式 progressBarControl2.Properties.ProgressViewStyle = DevExpress.XtraEditors.Controls.ProgressViewStyle.Solid; progressBarControl2.Position = 0; ////设置一个最小值 //progressBar2.Minimum = 0; ////设置一个最大值 //progressBar2.Maximum = listView1.CheckedItems.Count * 2; ////设置步长,即每次增加的数 //progressBar2.Step = 1; //progressBar2.Value = 0; IFeatureClass tFeatureClass = pFeatureLayer_QYYJY.FeatureClass; DataEditCommon.DeleteFeatureByWhereClause(tFeatureClass, ""); IGeometryArray pgeoArrayHong = new GeometryArrayClass(); IGeometryArray pgeoArrayHang = new GeometryArrayClass(); for (int i = 0; i < listView1.CheckedItems.Count; i++) { string layer = listView1.CheckedItems[i].SubItems[1].Text.ToString(); ILayer pLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, layer); IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; if (pFeatureLayer == null) { continue; } IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; //设置一个最大值 progressBarControl1.Properties.Maximum = pFeatureClass.FeatureCount(null); IFeatureCursor pCursor = pFeatureClass.Search(null, false); IFeature pFeature = pCursor.NextFeature(); while (pFeature != null) { ITopologicalOperator pTopo = (ITopologicalOperator)pFeature.Shape; IGeometry pGeo = pTopo.Buffer(hongse); pgeoArrayHong.Add(pGeo); IGeometry pGeoH = pTopo.Buffer(huangse); if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) { pTopo = (ITopologicalOperator)pGeoH; pGeoH = pTopo.Difference(pGeo); } pgeoArrayHang.Add(pGeoH); pFeature = pCursor.NextFeature(); this.progressBarControl1.PerformStep(); Application.DoEvents(); } List <ziduan> list = new List <ziduan>(); list.Add(new ziduan("dengji", "1")); list.Add(new ziduan("layername", layer)); list.Add(new ziduan("BID", "0")); DataEditCommon.CreateFeature(tFeatureClass, pgeoArrayHong, list); this.progressBarControl2.PerformStep(); //progressBar2.Value += 1; Application.DoEvents(); List <ziduan> listH = new List <ziduan>(); listH.Add(new ziduan("dengji", "2")); listH.Add(new ziduan("layername", layer)); listH.Add(new ziduan("BID", "0")); DataEditCommon.CreateFeature(tFeatureClass, pgeoArrayHang, listH); this.progressBarControl2.PerformStep(); //progressBar2.Value += 1; Application.DoEvents(); } if (pFeatureLayer_QYYJY.Visible == false) { pFeatureLayer_QYYJY.Visible = true; } DataEditCommon.g_pMyMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); MessageBox.Show("完成!"); }