/// <summary> /// 计算延长线上的距离 /// </summary> /// <params name="startP"></params> /// <params name="endP"></params> /// <params name="jjcd"></params> /// <returns></returns> public IPoint CalculateExtendPointNew(IPolyline plin, IPoint pntTo, double jjcd, out bool bres) { bres = false; IPoint pntOut = new PointClass(); double distfrom = 0.0, distto = 0.0; double outdistfrom = 0.0, outdistto = 0.0; bool boolfrom = false; plin.QueryPointAndDistance(esriSegmentExtension.esriExtendAtFrom, pntTo, false, pntOut, ref distfrom, ref outdistfrom, ref boolfrom); plin.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pntTo, false, pntOut, ref distto, ref outdistto, ref boolfrom); if (distfrom < distto)//反向的 { bres = true; plin.ReverseOrientation(); plin.QueryPoint(esriSegmentExtension.esriExtendAtTo, jjcd + plin.Length, false, pntOut); } else//正向 { bres = false; plin.QueryPoint(esriSegmentExtension.esriExtendAtTo, jjcd + plin.Length, false, pntOut); } return pntOut; }
private void SetPINValue() { //The Theory. //Select polygons that intersect the sketch. //Construct one polyline from the boundaries and intersect with sketch. //Sort resulting intersection locations (multipoint) by distance of the intersect // from the start of the sketch and create new ordered multipoint. //Loop through new ordered multipoint, select underlying parcel and calc pin. IFeatureLayer featLayer = m_editLayers.CurrentLayer; m_curve = m_edSketch.Geometry as IPolyline; //Search parcel polys by graphic to get feature cursor ISpatialFilter spatialFilter = new SpatialFilter(); spatialFilter.Geometry = m_curve; spatialFilter.GeometryField = m_editLayers.CurrentLayer.FeatureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; IFeatureCursor featCursor = featLayer.Search(spatialFilter,true); IFeature feature = featCursor.NextFeature(); //If we have no intersects then exit if (feature == null) return; //Make a GeomBag of the polygons boundaries (polylines) IGeometryCollection geomBag = new GeometryBagClass(); object missing = Type.Missing; while (feature != null) { ITopologicalOperator poly = feature.Shape as ITopologicalOperator; geomBag.AddGeometry(poly.Boundary,ref missing,ref missing); feature = featCursor.NextFeature(); } //Make one polyline from the boundaries IPolyline polyLineU = new PolylineClass(); ITopologicalOperator topoOp = polyLineU as ITopologicalOperator; topoOp.ConstructUnion(geomBag as IEnumGeometry); //Get the intersections of the boundaries and the curve IPointCollection pointCol = topoOp.Intersect(m_curve, esriGeometryDimension.esriGeometry0Dimension) as IPointCollection; //The point collection is not ordered by distance along the curve so //need to create a new collection with this info int[] pointOrder = new int[pointCol.PointCount]; double dac = 0, dfc = 0; bool bRS = false; for (int i = 0; i < pointCol.PointCount; i++) { IPoint queryPoint = new PointClass(); pointCol.QueryPoint(i, queryPoint); m_curve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, queryPoint, false, null,ref dac,ref dfc,ref bRS); pointOrder[i] = (int)dac; } //use built in bubble sort System.Array.Sort(pointOrder); //Loop through the sorted array and calc midpoint between parcel boundaries IPointCollection midPoints = new MultipointClass(); for (int i = 0; i < pointOrder.Length -1; i++) { //Get the midpoint distance double midPointDist = (pointOrder[i] + pointOrder[i + 1]) / 2; //create a point at the distance and store in point collection IPoint queryPoint = new PointClass(); m_curve.QueryPoint(esriSegmentExtension.esriNoExtension, midPointDist, false, queryPoint); midPoints.AddPoint(queryPoint,ref missing,ref missing); } //If ends of sketch are included then add them as points if (chkEnds.Checked) { object before = 0 as object; midPoints.AddPoint(m_curve.FromPoint, ref before, ref missing); midPoints.AddPoint(m_curve.ToPoint, ref missing, ref missing); } m_editor.StartOperation(); //Loop through calculated midpoints, select polygon and calc pin for (int i = 0; i < midPoints.PointCount; i++) { IPoint midPoint = midPoints.get_Point(i); spatialFilter = new SpatialFilter(); spatialFilter.Geometry = midPoint; spatialFilter.GeometryField = m_editLayers.CurrentLayer.FeatureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin; featCursor = featLayer.Search(spatialFilter, false); while ((feature = featCursor.NextFeature()) != null) { feature.set_Value(feature.Fields.FindField(cmbPINField.Text), m_lotNum); feature.Store(); m_lotNum += int.Parse(txtlotinc.Text); } } m_editor.StopOperation("ViperPIN"); txtlot.Text = m_lotNum.ToString(); }
internal static IList <double[]> GetLimits([NotNull] SegmentProxy segmentProxy, [NotNull] IPolygon buffer) { // TODO this method would be extremely expensive when called on WksSegmentProxy instances var result = new List <double[]>(); // Remark: segmentLine is altered by ITopologicalOperator.Intersect in such a way // that equal segments may not be considered as equal anymore IPolyline segmentLine = segmentProxy.GetPolyline(true); //IPolyline segmentLine = segmentProxy.GetPolyline(); var intersects = (IGeometryCollection) ((ITopologicalOperator)buffer).Intersect( segmentLine, esriGeometryDimension.esriGeometry1Dimension); int intersectCount = intersects.GeometryCount; for (var i = 0; i < intersectCount; i++) { var part = (IPath)intersects.Geometry[i]; double t0 = 0; double t1 = 0; double offset = 0; var rightSide = false; // TODO if called frequently, create abstract GetSegmentDistance(IPoint) on SegmentProxy, // with custom implementation on WksSegmentProxy. // Currently this seems to be called for AoSegmentProxys only, but this is not obvious. // TODO use a template point and part.QueryFromPoint() / part.QueryToPoint()? segmentLine.QueryPointAndDistance(esriSegmentExtension.esriExtendTangents, part.FromPoint, true, HelpPoint, ref t0, ref offset, ref rightSide); segmentLine.QueryPointAndDistance(esriSegmentExtension.esriExtendTangents, part.ToPoint, true, HelpPoint, ref t1, ref offset, ref rightSide); double tMin = Math.Min(t0, t1); double tMax = Math.Max(t0, t1); result.Add(new[] { tMin, tMax }); } // Handle spatial tolerance problems for segments near tolerance size! if (intersectCount == 0 && !((IRelationalOperator)buffer).Disjoint(segmentLine)) { ((ITopologicalOperator)segmentLine).Simplify(); if (segmentLine.IsEmpty) { result.Add(new[] { 0.0, 1.0 }); } } return(result); }
/// <summary> /// 向pline两侧指定距离做平行线,比较与point 的距离,返回距离近的偏移线做为偏移后的巷道 /// </summary> /// <params name="pline"></params> /// <params name="distance"></params> /// <params name="point"></params> /// <returns></returns> private IPolyline GetConstructOffsetHD(IPolyline pline, double distance, IPoint point) { IPolyline line1 = ConstructOffset(pline, distance); IPolyline line2 = ConstructOffset(pline, distance * -1); //CreateFeature(line1, GetLayerByName("testline")); //CreateFeature(line2, GetLayerByName("testline")); object obj = Type.Missing; double dis1 = 0; double dis2 = 0; double alongdis1 = 0; double alongdis2 = 0; IPoint outPoint = new PointClass(); Boolean bright1 = false; Boolean bright2 = false; line1.QueryPointAndDistance(esriSegmentExtension.esriExtendEmbedded, point, false, outPoint, ref alongdis1, ref dis1, ref bright1); IPoint outPoint2 = new PointClass(); line2.QueryPointAndDistance(esriSegmentExtension.esriExtendEmbedded, point, false, outPoint2, ref alongdis2, ref dis2, ref bright2); if (dis1 < dis2) { return(line1); } else { return(line2); } }
/// <summary> /// Construct Offset /// </summary> /// <param name="polyline">object polyline</param> /// <param name="point">value of offset</param> /// <param name="offset">offset point</param> /// <returns>point with offset</returns> internal static IPoint ConstructOffset(IPolyline polyline, IPoint point, double?offset) { if (polyline == null || polyline.IsEmpty) { return(null); } if (point == null || point.IsEmpty) { return(null); } if ((!offset.HasValue) || double.IsNaN(offset.Value) || offset.Value == 0.0) { return(point); } double distanceAlongCurve = 0; double distanceFromCurve = 0; bool rightSide = false; IPoint outPoint = new PointClass(); polyline.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, outPoint, ref distanceAlongCurve, ref distanceFromCurve, ref rightSide); IConstructPoint constructPoint = outPoint as IConstructPoint; constructPoint.ConstructOffset(polyline, esriSegmentExtension.esriNoExtension, distanceAlongCurve, false, offset.Value); return(constructPoint as IPoint); }
/// <summary> /// 计算两点之间的空间距离 /// </summary> /// <param name="pnt0">起点</param> /// <param name="pnt1">终点</param> /// <returns>返回距离</returns> public double CalculateDistance(IPoint pnt0, IGeometry geom) { double dist0 = 0.0, dist1 = 0.0; double distance = 0.0; IPoint outPoint = new PointClass(); IPoint pnt1 = new PointClass(); if (geom.GeometryType == esriGeometryType.esriGeometryPolygon) { IPolygon polygon = (IPolygon)geom; polygon.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pnt0, false, outPoint, ref dist0, ref dist1, false); distance = dist1; } else if (geom.GeometryType == esriGeometryType.esriGeometryPolyline) { IPolyline polyline = (IPolyline)geom; polyline.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pnt0, false, outPoint, ref dist0, ref dist1, false); distance = dist1; } else if (geom.GeometryType == esriGeometryType.esriGeometryPoint) { pnt1 = (IPoint)geom; double xstep = pnt1.X - pnt0.X; double ystep = pnt1.Y - pnt0.Y; distance = Math.Sqrt(xstep * xstep + ystep * ystep); } return(distance); }
public static IPoint GetNearPoint(IPolyline polyline, IPoint point) { IPoint outPoint = new PointClass(); double distanceAlongCurve = 0.0, distanceFromCurve = 0.0; bool bRightSide = false; polyline.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, outPoint, ref distanceAlongCurve, ref distanceFromCurve, ref bRightSide); return(outPoint); }
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); }
static private Dictionary <IPoint, double> ReturnMinDistancePt(IPolyline line, IPoint point) { Dictionary <IPoint, double> dic = new Dictionary <IPoint, double>(); double distanceAlongCurve = 0; double distanceFromCurve = 0; bool bRightSide = false; IPoint outPt = new PointClass(); line.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, outPt, ref distanceAlongCurve, ref distanceFromCurve, ref bRightSide); dic.Add(outPt, distanceFromCurve); return(dic); }
private static double GetDistanceAlongPolyline([NotNull] IPolyline polyline, [NotNull] IPoint point) { double distanceAlong = 0; double distanceFrom = 0; var rightSide = false; const bool asRatio = true; polyline.QueryPointAndDistance( esriSegmentExtension.esriNoExtension, point, asRatio, _alongPoint.Value, ref distanceAlong, ref distanceFrom, ref rightSide); return(distanceAlong); }
public static bool IsFromPoint(IPolyline polyline, IPoint point) { IPoint outPoint = new PointClass(); double distanceAlongCurve = 0.0, distanceFromCurve = 0.0; bool bRightSide = false; polyline.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, outPoint, ref distanceAlongCurve, ref distanceFromCurve, ref bRightSide); if (distanceFromCurve > 0.001) { return(false); } if (distanceAlongCurve > 0.001) { return(false); } return(true); }
public static IPoint GetAnotherPoint(IPolyline polyline, IPoint point) { IPoint outPoint = new PointClass(); double distAlongCurveFrom = 0; double disFromCurve = 0; bool isRightSide = false; polyline.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, outPoint, ref distAlongCurveFrom, ref disFromCurve, ref isRightSide); if (distAlongCurveFrom < 0.0001) { return(polyline.ToPoint); } else { return(polyline.FromPoint); } }
/// <summary> /// Returns M values at the distance along the polyline. An array of one or two Ms is returned. Two Ms can be returned /// if the given distance is exactly at the beginning or ending of a part. /// </summary> /// <param name="source">The source.</param> /// <param name="point">The point.</param> /// <returns>Returns a <see cref="double" /> array of the m values.</returns> /// <remarks> /// Does not assume that the point is on top of the polyline. If the point is equally distant from more that one /// location along the polyline, then returns the all the M values. /// </remarks> public static double[] GetMsAtPoint(this IPolyline source, IPoint point) { IMAware aware = (IMAware)source; if (aware.MAware) { double distanceAlongCurve = 0.0; double distanceFromCurve = 0.0; bool rightSide = false; IPoint queryPoint = new PointClass(); source.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, queryPoint, ref distanceAlongCurve, ref distanceFromCurve, ref rightSide); IMSegmentation segmentation = (IMSegmentation)source; var values = segmentation.GetMsAtDistance(distanceAlongCurve, false) as double[]; return(values); } return(null); }
static private IPolyline GetaSectionPly(IPolyline ply, IPoint point) { IPolyline radioPly = new PolylineClass(); double distanceAlongCurve = 0; double distanceFromCurve = 0; bool bRightSide = false; IPoint outPt = new PointClass(); ply.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, outPt, ref distanceAlongCurve, ref distanceFromCurve, ref bRightSide); ILine beforeLine = new LineClass(); beforeLine.FromPoint = point; beforeLine.ToPoint = outPt; IPolyline temperply1 = ExtendLineFun(point, beforeLine.Angle); IPolyline temperply2 = ExtendLineFun(point, beforeLine.Angle - Math.PI); radioPly.FromPoint = temperply1.ToPoint; radioPly.ToPoint = temperply2.ToPoint; return(radioPly); }
//根据输入点和输入的线要素,获取该点距离最近的线的点、该线从起点到该点的距离以及该要素 public void GetMindistanceandpoint(IPoint inputpoint, List <IFeature> pFeatureline, ref double X, ref double Y, ref IFeature pFeature, ref double pFrompointtoOutpointLength) { try { IPoint outpoint = new PointClass(); double disAlongCurveFrom = 0.0; double disFromCurve = 0.0; bool isRighside = false; double minDistance = 0.0; IPolyline Startline = pFeatureline[0].Shape as IPolyline; Startline.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, inputpoint, false, outpoint, ref disAlongCurveFrom, ref disFromCurve, ref isRighside); minDistance = disFromCurve; pFrompointtoOutpointLength = disAlongCurveFrom; pFeature = pFeatureline[0]; X = outpoint.X; Y = outpoint.Y; for (int i = 1; i < pFeatureline.Count; i++) { IPolyline ppolyline = pFeatureline[i].Shape as IPolyline; ppolyline.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, inputpoint, false, outpoint, ref disAlongCurveFrom, ref disFromCurve, ref isRighside); if (minDistance > disFromCurve) { pFeature = pFeatureline[i]; X = outpoint.X; Y = outpoint.Y; minDistance = disFromCurve; pFrompointtoOutpointLength = disAlongCurveFrom; } } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常"); } }
public static double GetClosestPointFraction([NotNull] SegmentProxy segmentProxy, [NotNull] Pnt nearPoint, out double?offset, out bool?onRightSide, bool as3D) { if (segmentProxy.IsLinear) { Pnt p0s = segmentProxy.GetStart(as3D); Pnt p0e = segmentProxy.GetEnd(as3D); Pnt l0 = p0e - p0s; offset = null; onRightSide = null; return(GetAlongFraction(nearPoint - p0s, l0)); } const bool forceCreation = true; IPolyline segmentLine = segmentProxy.GetPolyline(forceCreation); IPoint near = new PointClass(); near.PutCoords(nearPoint.X, nearPoint.Y); IPoint onPoint = new PointClass(); double fraction = 0; double offsetValue = 0; var rightSide = false; const bool asRatio = true; segmentLine.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, near, asRatio, onPoint, ref fraction, ref offsetValue, ref rightSide); offset = offsetValue; onRightSide = rightSide; return(fraction); }
private void button2_Click(object sender, EventArgs e) { IFeatureLayer layer = axMapControl1.get_Layer(0) as IFeatureLayer; IFeatureClass pFeatCla = layer.FeatureClass; IFeature pFeature = pFeatCla.GetFeature(0); IGeometry pGeometry = pFeature.Shape; IPolyline pPoly = pGeometry as IPolyline; ISegmentCollection pSegCol = pGeometry as ISegmentCollection; ILine pLine = pSegCol.get_Segment(0) as ILine; IPoint inPoint = new Point(); //已知点 inPoint.X = pPoly.FromPoint.X + 5; inPoint.Y = pPoly.FromPoint.Y + 2; IPoint outPoint = new PointClass(); //曲线上到输入点距离最小的点; double distAlongCurveFrom = 0; //曲线其实点到输出点部分的长度 double distFromCurve = 0; //输出点到输入点的距离 bool isRightSide = true; //输入点是否在曲线的右边 pPoly.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, inPoint, false, outPoint, ref distAlongCurveFrom, ref distFromCurve, ref isRightSide); double lineHeading = pLine.Angle * 180 / PI; //因为当前角度是以四象限X为起点的逆时针角度,对应的是地图东部 //故需要转成以北为起点的顺时针角度 if (lineHeading <= 90) { //1、3、4象限 lineHeading = 90 - lineHeading; } else { //2象限 lineHeading = 360 + (90 - lineHeading); } textBox1.Text = lineHeading.ToString(); //textBox1.Text = string.Format("{0},{1}", distAlongCurveFrom, distFromCurve); //double len = pPoly.Length; //textBox2.Text = len.ToString(); }
/// <summary> /// 通过IPolyline.QueryPointAndDistance获取最近点和距离 /// </summary> /// <param name="pLine">线</param> /// <param name="point">输入点</param> /// <param name="disAloneFrom">最近点到线段起始点的距离</param> /// <param name="dis">最近距离</param> /// <param name="disNum">在线段上的位置集合,1在右方,2在左方,0在线上</param> /// <returns>线上的最近点</returns> public static IPoint GetNearestLine(IPolyline pLine, IPoint point, ref double disAloneFrom, ref double dis, ref int disNum) { IPoint outPoint = new PointClass(); bool isRightSide = false; pLine.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, outPoint, ref disAloneFrom, ref dis, ref isRightSide); if (isRightSide) { disNum = 1; } else { if (dis == 0) { disNum = 0; } else { disNum = 2; } } return(outPoint); }
private void SetPINValue() { //The Theory. //Select polygons that intersect the sketch. //Construct one polyline from the boundaries and intersect with sketch. //Sort resulting intersection locations (multipoint) by distance of the intersect // from the start of the sketch and create new ordered multipoint. //Loop through new ordered multipoint, select underlying parcel and calc pin. IFeatureLayer featLayer = m_editLayers.CurrentLayer; m_curve = m_edSketch.Geometry as IPolyline; //Search parcel polys by graphic to get feature cursor ISpatialFilter spatialFilter = new SpatialFilter(); spatialFilter.Geometry = m_curve; spatialFilter.GeometryField = m_editLayers.CurrentLayer.FeatureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelCrosses; IFeatureCursor featCursor = featLayer.Search(spatialFilter, true); IFeature feature = featCursor.NextFeature(); //If we have no intersects then exit if (feature == null) { return; } //Make a GeomBag of the polygons boundaries (polylines) IGeometryCollection geomBag = new GeometryBagClass(); object missing = Type.Missing; while (feature != null) { ITopologicalOperator poly = feature.Shape as ITopologicalOperator; geomBag.AddGeometry(poly.Boundary, ref missing, ref missing); feature = featCursor.NextFeature(); } //Make one polyline from the boundaries IPolyline polyLineU = new PolylineClass(); ITopologicalOperator topoOp = polyLineU as ITopologicalOperator; topoOp.ConstructUnion(geomBag as IEnumGeometry); //Get the intersections of the boundaries and the curve IPointCollection pointCol = topoOp.Intersect(m_curve, esriGeometryDimension.esriGeometry0Dimension) as IPointCollection; //The point collection is not ordered by distance along the curve so //need to create a new collection with this info int[] pointOrder = new int[pointCol.PointCount]; double dac = 0, dfc = 0; bool bRS = false; for (int i = 0; i < pointCol.PointCount; i++) { IPoint queryPoint = new PointClass(); pointCol.QueryPoint(i, queryPoint); m_curve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, queryPoint, false, null, ref dac, ref dfc, ref bRS); pointOrder[i] = (int)dac; } //use built in bubble sort System.Array.Sort(pointOrder); //Loop through the sorted array and calc midpoint between parcel boundaries IPointCollection midPoints = new MultipointClass(); for (int i = 0; i < pointOrder.Length - 1; i++) { //Get the midpoint distance double midPointDist = (pointOrder[i] + pointOrder[i + 1]) / 2; //create a point at the distance and store in point collection IPoint queryPoint = new PointClass(); m_curve.QueryPoint(esriSegmentExtension.esriNoExtension, midPointDist, false, queryPoint); midPoints.AddPoint(queryPoint, ref missing, ref missing); } //If ends of sketch are included then add them as points if (chkEnds.Checked) { object before = 0 as object; midPoints.AddPoint(m_curve.FromPoint, ref before, ref missing); midPoints.AddPoint(m_curve.ToPoint, ref missing, ref missing); } m_editor.StartOperation(); //Loop through calculated midpoints, select polygon and calc pin for (int i = 0; i < midPoints.PointCount; i++) { IPoint midPoint = midPoints.get_Point(i); spatialFilter = new SpatialFilter(); spatialFilter.Geometry = midPoint; spatialFilter.GeometryField = m_editLayers.CurrentLayer.FeatureClass.ShapeFieldName; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelWithin; featCursor = featLayer.Search(spatialFilter, false); while ((feature = featCursor.NextFeature()) != null) { feature.set_Value(feature.Fields.FindField(cmbPINField.Text), m_lotNum); feature.Store(); m_lotNum += int.Parse(txtlotinc.Text); } } m_editor.StopOperation("ViperPIN"); txtlot.Text = m_lotNum.ToString(); }
/// <summary> /// clip a polyline at the specified lengths /// </summary> public static IPolyline ClipContour(IPoint npsPoint, IPolyline npsPolyline, double RangeLeft, double RangeRight) { ICurve NewPolyline = null, pl2, pl1; IPoint npsExactPoint; double PolylineLength, DistanceFromStart = 0, DistanceFromCurve = 0, NewLineEnd, AmountOver, start1 = 0, start2 = 0, end1 = 0, end2 = 0, NewLineStart; bool npsRightSide = false, IsOutOfBoundsLeft, IsOutOfBoundsRight; ISegmentCollection newpl = null; if (npsPolyline == null) return null; PolylineLength = npsPolyline.Length; //get the distance of the point from the start of the contour npsExactPoint = new PointClass(); npsPolyline.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, npsPoint, false, npsExactPoint, ref DistanceFromStart, ref DistanceFromCurve, ref npsRightSide); //if (contour)polyline is not a closed line if (npsPolyline.IsClosed == false) { IsOutOfBoundsLeft = false; IsOutOfBoundsRight = false; NewLineStart = DistanceFromStart - RangeLeft; NewLineEnd = DistanceFromStart + RangeRight; if (NewLineStart < 0) IsOutOfBoundsLeft = true; if (NewLineEnd > PolylineLength) IsOutOfBoundsRight = true; //if contour is outbound to the left, then try to shift it to the right if (IsOutOfBoundsLeft == true && IsOutOfBoundsRight == false) { AmountOver = (DistanceFromStart - RangeLeft) * -1; if (((DistanceFromStart + RangeRight) + AmountOver) < PolylineLength) { NewLineStart = 0; NewLineEnd = (DistanceFromStart + RangeRight) + AmountOver; } else { NewLineStart = -1; NewLineEnd = -1; } } //if contour is out of bounds to the right, then try to shift it to the left if (IsOutOfBoundsLeft == false && IsOutOfBoundsRight == true) { AmountOver = (DistanceFromStart + RangeRight) - PolylineLength; if (((DistanceFromStart - RangeLeft) - AmountOver) >= 0) { NewLineStart = (DistanceFromStart - RangeLeft) - AmountOver; NewLineEnd = PolylineLength; } else { NewLineStart = -1; NewLineEnd = -1; } } //since the contour is to short on both ends to create the new polyline,abound operation if (IsOutOfBoundsLeft == true && IsOutOfBoundsRight == true) { NewLineStart = -1; NewLineEnd = -1; } if (NewLineStart != -1 && NewLineEnd != -1) { NewPolyline = new PolylineClass(); npsPolyline.GetSubcurve(NewLineStart, NewLineEnd, false, out NewPolyline); } } else //if polyline is closed { if ((RangeLeft + RangeRight) < PolylineLength) { pl1 = new PolylineClass(); pl2 = new PolylineClass(); newpl = new PolylineClass(); //if desired subcurve does not cross the start/end point of the closed polyline(circular) then get //a sub curve as normal if ((DistanceFromStart - RangeLeft) >= 0 && (DistanceFromStart + RangeRight) < PolylineLength) { NewLineStart = DistanceFromStart - RangeLeft; NewLineEnd = DistanceFromStart + RangeRight; NewPolyline = new PolylineClass(); npsPolyline.GetSubcurve(NewLineStart, NewLineEnd, false, out NewPolyline); } else { //if desired subcurve does cross the start/end point of the closed polyline(circular) //then two subcurves will have to be formed each ending at the start/end point of the circle //if left range oversteps start/end then... if ((DistanceFromStart - RangeLeft) < 0) { start1 = PolylineLength - ((DistanceFromStart - RangeLeft) * -1); end1 = PolylineLength; start2 = 0; end2 = DistanceFromStart + RangeRight; } //if right range oversteps start/end then... if ((DistanceFromStart + RangeRight) > PolylineLength) { start1 = DistanceFromStart - RangeLeft; end1 = PolylineLength; start2 = 0; end2 = (DistanceFromStart + RangeRight) - PolylineLength; } //combine sub curves npsPolyline.GetSubcurve(start1, end1, false, out pl1); npsPolyline.GetSubcurve(start2, end2, false, out pl2); newpl.AddSegmentCollection(pl1 as ISegmentCollection); newpl.AddSegmentCollection(pl2 as ISegmentCollection); NewPolyline = newpl as ICurve; } } } return NewPolyline as IPolyline; }
/// <summary> /// object polyline. Distance negative -> upstream /// </summary> /// <param name="geometricNetwork">object geometricNetwork</param> /// <param name="resultEdges">objects resultEdges</param> /// <param name="distance">value of distance</param> /// <param name="point">object point</param> /// <param name="offset">offset of polyline</param> /// <param name="messageInfo">info on result</param> /// <returns>object IGeometry (polyline or point)</returns> internal static IGeometry GetPolylinePosAlong(ESRI.ArcGIS.Geodatabase.IGeometricNetwork geometricNetwork, IEnumNetEID resultEdges, double distance, IPoint point, double?offset, ref string messageInfo) { IGeometry geometryBag = new GeometryBagClass(); geometryBag.SpatialReference = point.SpatialReference; IGeometryCollection geometryCollection = geometryBag as IGeometryCollection; IEIDHelper eidHelper = new EIDHelperClass(); eidHelper.GeometricNetwork = geometricNetwork; eidHelper.ReturnGeometries = true; eidHelper.ReturnFeatures = false; IEnumEIDInfo enumEIDinfo = eidHelper.CreateEnumEIDInfo(resultEdges); enumEIDinfo.Reset(); IEIDInfo eidInfo = enumEIDinfo.Next(); while (eidInfo != null) { IGeometry geometry = eidInfo.Geometry; geometryCollection.AddGeometry(geometry); eidInfo = enumEIDinfo.Next(); } ITopologicalOperator unionedPolyline = new PolylineClass(); unionedPolyline.ConstructUnion(geometryBag as IEnumGeometry); IPolyline pl = unionedPolyline as IPolyline; if (distance < 0) { pl.ReverseOrientation(); distance = Math.Abs(distance); } IMAware mAware = pl as IMAware; mAware.MAware = true; IMSegmentation3 mSegmentation = unionedPolyline as IMSegmentation3; mSegmentation.SetMsAsDistance(false); IPoint ptTmp = new PointClass(); double distanceAlong = 0; double distanceFromCurve = 0; bool rightSide = false; pl.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, point, false, ptTmp, ref distanceAlong, ref distanceFromCurve, ref rightSide); object mStartArray = mSegmentation.GetMsAtDistance(distanceAlong, false); double[] mStart = mStartArray as double[]; double distanceDownStream = distanceAlong + distance; IPolyline resultPolyline = mSegmentation.GetSubcurveBetweenMs(mStart[0], distanceDownStream) as IPolyline; if (resultPolyline.IsEmpty) { return(point); } if (mSegmentation.MMax < distanceDownStream) { messageInfo = "The set distance exceeds the length of network"; } return(Helper.ConstructOffset(resultPolyline, offset)); }
/// <summary> /// 获得回采多边形点列表,最后点为切眼中心点 /// </summary> /// <params name="pline1"></巷道1> /// <params name="pline2"></巷道2> /// <params name="pline3"></切眼> /// <params name="widthhd"></巷道宽度> /// <params name="widthqy"></切眼宽度> /// <params name="hcDis"></回采距离> /// <params name="direct"></回采方向,pline3 from-to方向,返回1-切眼右侧, 返回-1-切眼左侧(),只在中间回采时使用此参数,开始回采时值为0> /// <returns></returns> public IPointCollection GetBackPolygonArea(IPolyline pline1, IPolyline pline2, IPolyline pline3, double widthhd, double widthhd1, double widthqy, double hcDis, int direct) { object obj = Type.Missing; //ESRI.ArcGIS.Geometry.IPolyline polylineall = new ESRI.ArcGIS.Geometry.PolylineClass(); IPolyline offsetqy = null; Boolean bright = false; //交点1(切眼与巷道1交点) IPoint point1 = GetIntersectPointExtend(pline3, pline1); //交点2(切眼与巷道2交点) IPoint point2 = GetIntersectPointExtend(pline3, pline2); //CreateFeature(pline3, GetLayerByName("中心线全")); int iDirect; //依据切眼与巷道的关系判断回采方向,切眼为巷道起点时使用 if (direct != 0) //中心点回采 { IPoint outpnt = new PointClass(); iDirect = direct; offsetqy = GetExtentQy(pline1, pline2, pline3); } else { iDirect = GetBackDirection(pline3, 200, pline1, pline2); offsetqy = ConstructOffset(pline3, widthqy / 2.0 * iDirect); } //切眼平移后的线 IPoint pointCent = ConstructMiddlePoint(offsetqy, offsetqy.Length / 2);//取平移后线的中点 //平移两侧巷道 //CreateFeature(pointCent, GetLayerByName("testpoint")); //CreateFeature(offsetqy, GetLayerByName("中心线全")); IPolyline offsethd1 = GetConstructOffsetHD(pline1, widthhd / 2, pointCent); IPolyline offsethd2 = GetConstructOffsetHD(pline2, widthhd1 / 2, pointCent); //取两条巷道与切眼交点 IPoint pnt1 = GetIntersectPoint(offsethd1, offsetqy); IPoint pnt2 = GetIntersectPoint(offsethd2, offsetqy); ////理顺巷道线的方向 IPoint outpoint = new PointClass(); IPolyline offsethd1dir = GetPointPos(pline3.FromPoint, pline3.ToPoint, offsethd1, iDirect); IPolyline offsethd2dir = GetPointPos(pline3.FromPoint, pline3.ToPoint, offsethd2, iDirect); double dishd1 = 0; double alonghd1 = 0; offsethd1dir.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pnt1, false, outpoint, ref alonghd1, ref dishd1, ref bright); double dishd2 = 0; double alonghd2 = 0; offsethd2dir.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, pnt2, false, outpoint, ref alonghd2, ref dishd2, ref bright); ICurve newhd1 = new PolylineClass(); offsethd1dir.GetSubcurve(alonghd1, hcDis + alonghd1, false, out newhd1); ICurve newhd2 = new PolylineClass(); offsethd2dir.GetSubcurve(alonghd2, hcDis + alonghd2, false, out newhd2); IPointCollection pntPolycol = new PolygonClass() as IPointCollection; IPointCollection pntlinecol = newhd1 as IPointCollection; int i = 0; IPoint point = null; for (i = 0; i < pntlinecol.PointCount; i++) { point = pntlinecol.get_Point(i); pntPolycol.AddPoint(point, ref obj, ref obj); } pntlinecol = newhd2 as IPointCollection; //取回采后切眼的中点 IPolyline polylineendqy = new PolylineClass(); if (point == null) { polylineendqy.FromPoint = point1; polylineendqy.ToPoint = point2; } else { polylineendqy.FromPoint = point; polylineendqy.ToPoint = pntlinecol.get_Point(pntlinecol.PointCount - 1); } IPoint pointendqyCent = ConstructMiddlePoint(polylineendqy, polylineendqy.Length / 2);//终点切眼的中点 for (i = pntlinecol.PointCount - 1; i >= 0; i--) { point = pntlinecol.get_Point(i); pntPolycol.AddPoint(point, ref obj, ref obj); } pntPolycol.AddPoint(pointendqyCent, ref obj, ref obj); return(pntPolycol); }