博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
线捕捉、打断线(代码
阅读量:5267 次
发布时间:2019-06-14

本文共 3255 字,大约阅读时间需要 10 分钟。

来自esri社区:地址忘了。。。见谅

using System;

/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
public Class1()
{
    }
    //找到点击点离要素最近的那个点(用于线边缘捕捉)
private IPoint ReturnNearestPoint(IFeatureClass t_pBaseFeatureClass,IPoint t_pInPoint)
{
 
  IFeatureClass pBaseFeatureClass=t_pBaseFeatureClass;
  IPoint pInPoint=t_pInPoint;
  IFeatureCursor pFeatureCursor;
  IFeature pFeature;
  IGeometry pGeometry;
  double dblDistance=10;//容差
  IProximityOperator pProximityOperator;
  IPoint pNearestPoint=null;
  //MessageBox.Show("return2");
  pFeatureCursor=pBaseFeatureClass.Search(null,false);
  pFeature=pFeatureCursor.NextFeature();
 
  while (pFeature!=null)
  {
   //MessageBox.Show("return4");
   pGeometry=pFeature.Shape;
   pProximityOperator=(IProximityOperator)pGeometry;

   if (dblDistance>pProximityOperator.ReturnDistance(pInPoint))

   {
    dblDistance=pProximityOperator.ReturnDistance(pInPoint);
    //MessageBox.Show("dblDistance");
    pNearestPoint=pProximityOperator.ReturnNearestPoint(pInPoint,esriSegmentExtension.esriNoExtension);
    //MessageBox.Show("pNearestPoint");
   }
   pFeature=pFeatureCursor.NextFeature();
  }
 
  return pNearestPoint;
}
    //打断线,用于在点击点处,打断该条线
    private void SplitePolylineByHitPoint(IFeatureClass t_pLineFeatureClass,IPoint t_pPoint)
{
 
  IFeatureClass pFeatureClass=t_pLineFeatureClass;
  IFeatureCursor pFeatureCursor;
  IFeature pFeature;
  pFeatureCursor=pFeatureClass.Search(null,false);
  pFeature=pFeatureCursor.NextFeature();
  IRelationalOperator  pRelationalOperator ;
  //遍历featureClass找到点中的那条线
  while (pFeature!=null)
  {
   pRelationalOperator=(IRelationalOperator)pFeature.Shape;
   bool bHasCrosses=pRelationalOperator.Contains(t_pPoint);
   if (bHasCrosses)
   {
    //对那条线在点击点处,进行打断
    IPolycurve pPolycurve=(IPolycurve)pFeature.Shape;
    bool HasSplitHappened ;
    int newPartIndex;
    int newSegmentIndex;
    //打断
    pPolycurve.SplitAtPoint(t_pPoint,false,true,out HasSplitHappened,out newPartIndex,out newSegmentIndex);
    if (HasSplitHappened)
    {
     //从GeometryCollection中分离出打断后的要素,并生成新的要素,并赋于属性
     IFeature pNewFeature;
     IGeometryCollection pGeometryCollection=(IGeometryCollection)pPolycurve;

     for (int i=0;i<pGeometryCollection.GeometryCount;i++)

     {
      //生成新的要素
      m_pWorkspaceEdit.StartEditing(false);
      m_pWorkspaceEdit.StartEditOperation();
      pNewFeature=pFeatureClass.CreateFeature();
      IGeometryCollection pline=new PolylineClass();
      IGeometry pGeo=pGeometryCollection.get_Geometry(i);
      pline.AddGeometries(1,ref pGeo);
      pNewFeature.Shape=(IPolyline)pline;
      pNewFeature.Store();
      m_pWorkspaceEdit.StopEditOperation();
      m_pWorkspaceEdit.StopEditing(true);
      IRow pRow =(IRow)pFeature;
      int intIndex=pRow.Fields.FindField("CRoadID");
      //进行属性复制
      for(int k=2;k<pRow.Fields.FieldCount-3;k++)//前后几个属性字段不添加
      {
       if (pRow.Fields.get_Field(k).Name=="Shape_Length")
       {
        continue;
       }
       if (k!=intIndex)
       {
       
        if (!pRow.get_Value(k).ToString().Equals(""))
        {
        
         pNewFeature.set_Value(k,pRow.get_Value(k));
        }
       }
       else
       {
        if (k==0)
        {
         if (!pRow.get_Value(k).ToString().Equals(""))
         {
          pNewFeature.set_Value(k,pRow.get_Value(k));
         }
        }
        else
        {
        
         if (!pRow.get_Value(k).ToString().Equals(""))
         {
          int intNO=System.Convert.ToInt32(pRow.get_Value(k).ToString())+1000*i;
          pNewFeature.set_Value(k,intNO);
         }
        }
       }
      }
      pNewFeature.Store();
     }
     pFeature.Delete();
    }
   }
   pFeature=pFeatureCursor.NextFeature();
  }
}

}

转载于:https://www.cnblogs.com/liangyuhuidespace/archive/2013/04/17/3026919.html

你可能感兴趣的文章
【翻译自mos文章】当点击完 finishbutton后,dbca 或者dbua hang住
查看>>
Linux编程简介——gcc
查看>>
2019年春季学期第四周作业
查看>>
MVC4.0 利用IActionFilter实现简单的后台操作日志功能
查看>>
windows下mongodb安装与使用
查看>>
rotate the clock
查看>>
bugku 变量
查看>>
Python 环境傻瓜式搭建 :Anaconda概述
查看>>
数据库01 /Mysql初识以及基本命令操作
查看>>
数据库02 /MySQL基础数据类型以及多表之间建立联系
查看>>
Python并发编程04/多线程
查看>>
CF461B Appleman and Tree
查看>>
CF219D Choosing Capital for Treeland
查看>>
杂七杂八的小笔记本
查看>>
51Nod1353 树
查看>>
CF1215E Marbles
查看>>
fish redux 个人理解
查看>>
BZOJ2339 HNOI2011卡农(动态规划+组合数学)
查看>>
octave基本操作
查看>>
axure学习点
查看>>