• 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; 
    } 
  • 相关阅读:
    编程语言最终的目标
    浅谈编程语言的类型系统
    编程语言的五大系统
    Java Array、List、Set互相转化
    java 集合类 列表
    Java检查异常、非检查异常、运行时异常、非运行时异常的区别
    java 的枚举变量只能使用枚举常量来初始化--带有关联数据的枚举
    观察与思考

    种田与投资
  • 原文地址:https://www.cnblogs.com/gisoracle/p/5209133.html
Copyright © 2020-2023  润新知