• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

gisoracle

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

Engine中如何截取线上指定两点间的线段?

//调用 
IPolyline newLine = GetSubCurve(polyline, p1, p2); 

ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = axMapControl1.ActiveView.ScreenDisplay; 
screenDisplay.StartDrawing(screenDisplay.hDC, System.Convert.ToInt16(ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache)); 
IRgbColor rgbColor = new RgbColorClass(); 
rgbColor.Red = 255; 
ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit Cast 
ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass(); 
simpleLineSymbol.Color = color; 
ESRI.ArcGIS.Display.ISymbol symbol = (ESRI.ArcGIS.Display.ISymbol)simpleLineSymbol; // Explicit Cast 
screenDisplay.SetSymbol(symbol); 
screenDisplay.DrawPolyline(newLine); 
screenDisplay.FinishDrawing(); 


private IPolyline GetSubCurve(IPolyline inpolyLine, IPoint pnt1, IPoint pnt2) 
{ 
double d1 = GetDistAlong(inpolyLine, pnt1); 
double d2 = GetDistAlong(inpolyLine, pnt2); 

var c = inpolyLine as ICurve; 
ICurve outCurve; 
c.GetSubcurve(d1, d2, false, out outCurve); 
if (c == null || c.IsEmpty) 
throw new Exception(fail); 
var outPolyline = outCurve as IPolyline; 
if (outPolyline == null) 
{ 
outPolyline = new PolylineClass() as IPolyline; 
var sc = outPolyline as ISegmentCollection; 
sc.AddSegment((ISegment)outCurve); 
((IGeometry)sc).SpatialReference = outCurve.SpatialReference; 
} 
return outPolyline; 
} 

private double GetDistAlong(IPolyline polyLine, IPoint pnt) 
{ 
var outPnt = new PointClass() as IPoint; 
double distAlong = double.NaN; 
double distFrom = double.NaN; 
bool bRight = false; 
polyLine.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pnt, false, outPnt, 
ref distAlong, ref distFrom, ref bRight); 
return distAlong; 
} 

posted on 2016-02-23 10:44  gisai  阅读(738)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3