private static List <WKSPointVA> GetFromEnumVertex([NotNull] IMultiPatch multiPatch) { var pts = (IPointCollection)multiPatch; int pointCount = pts.PointCount; var result = new List <WKSPointVA>(pointCount); IEnumVertex enumVertex = pts.EnumVertices; enumVertex.Reset(); IPoint p = new PointClass(); int part; int vertex; for (enumVertex.QueryNext(p, out part, out vertex); vertex >= 0; enumVertex.QueryNext(p, out part, out vertex)) { var pnt = new WKSPointVA(); double x; double y; p.QueryCoords(out x, out y); pnt.m_x = x; pnt.m_y = y; pnt.m_z = p.Z; pnt.m_m = p.M; pnt.m_id = p.ID; result.Add(pnt); } return(result); }
public void QueryCoords(int index, out double x, out double y) { WKSPointVA p = _points[index]; x = p.m_x; y = p.m_y; }
public IPoint GetPoint(int index) { WKSPointVA p = _points[index]; IPoint ret = new PointClass(); ret.PutCoords(p.m_x, p.m_y); ret.Z = p.m_z; return(ret); }
public static WKSPointVA CreateWksPointVa(WKSPointZ wksPointZ) { var wksPoint = new WKSPointVA { m_x = wksPointZ.X, m_y = wksPointZ.Y, m_z = wksPointZ.Z }; return(wksPoint); }
public static WKSPointVA CreateWksPointVa(IPoint point) { var wksPoint = new WKSPointVA { m_x = point.X, m_y = point.Y, m_z = point.Z, m_m = point.M }; return(wksPoint); }
public static string ToString(WKSPointVA point, int numberOfDecimals = 3) { try { string format = string.Format( "X: {{0:N{0}}} Y: {{1:N{0}}} Z: {{2:N{0}}} M: {{3:N{0}}}", numberOfDecimals); return(string.Format(format, point.m_x, point.m_y, point.m_z, point.m_m)); } catch (Exception e) { return(HandleToStringException(e)); } }
public static IPolygon GetPolygon([NotNull] IEnumerable <WKSPointVA> points) { Assert.ArgumentNotNull(points, nameof(points)); IPointCollection5 mps = new MultipointClass(); foreach (WKSPointVA point in points) { WKSPointVA p = point; mps.InsertWKSPointVA(0, 1, ref p); } IPointCollection poly = new PolygonClass(); poly.AddPointCollection(mps); return((IPolygon)poly); }
/// <summary> /// Determines whether an envelope contains a point, i.e. the point is not disjoint and not /// on the envelope's boundary. No tolerance is applied. /// </summary> /// <param name="envelope">The envelope (containing)</param> /// <param name="point">The point (contained)</param> /// <returns> /// <c>true</c> if the envelope contains the point; otherwise, <c>false</c>. /// </returns> public static bool Contains2D(WKSEnvelope envelope, WKSPointVA point) { if (point.m_x < envelope.XMin) { return(false); } if (point.m_y < envelope.YMin) { return(false); } if (point.m_x > envelope.XMax) { return(false); } if (point.m_y > envelope.YMax) { return(false); } return(true); }
public void Add(WKSPointVA wksPoint, string error) { Points.Add(wksPoint); if (StringUtils.IsNotEmpty(error)) { if (Errors == null) { Errors = new HashSet <string>(); } if (Errors.Count > maxErrors) { } else if (Errors.Count == maxErrors) { Errors.Add("..."); } else if (!Errors.Contains(error)) { Errors.Add(error); } } }
public static List <List <WKSPointVA> > GetRings([NotNull] IMultiPatch multiPatch) { Assert.ArgumentNotNull(multiPatch, nameof(multiPatch)); IPointCollection5 mps = new MultipointClass(); mps.AddPointCollection((IPointCollection)multiPatch); var parts = (IGeometryCollection)multiPatch; int partCount = parts.GeometryCount; var rings = new List <List <WKSPointVA> >(partCount); int pointIndex = 0; for (int partIndex = 0; partIndex < partCount; partIndex++) { IGeometry part = parts.Geometry[partIndex]; var partPoints = (IPointCollection)part; if (part is IRing) { int ringCount = partPoints.PointCount; var ringPoints = new List <WKSPointVA>(ringCount); for (int iRingPoint = 0; iRingPoint < ringCount; iRingPoint++) { ringPoints.Add(GetWKSPointVA(mps, ref pointIndex)); } rings.Add(ringPoints); } else if (part is ITriangleFan) { int fanCount = partPoints.PointCount; WKSPointVA center = GetWKSPointVA(mps, ref pointIndex); WKSPointVA first = GetWKSPointVA(mps, ref pointIndex); for (int i = 2; i < fanCount; i++) { WKSPointVA second = GetWKSPointVA(mps, ref pointIndex); var trainglePoints = new List <WKSPointVA> { center, first, second, center }; rings.Add(trainglePoints); first = second; } } else if (part is ITriangleStrip) { int stripCount = partPoints.PointCount; WKSPointVA first = GetWKSPointVA(mps, ref pointIndex); WKSPointVA second = GetWKSPointVA(mps, ref pointIndex); for (int i = 2; i < stripCount; i++) { WKSPointVA third = GetWKSPointVA(mps, ref pointIndex); var tri = new List <WKSPointVA> { first, second, third, first }; rings.Add(tri); first = second; second = third; } } else if (part is ITriangles) { int trianglePointsCount = partPoints.PointCount; Assert.AreEqual(trianglePointsCount % 3, 0, string.Format("{0} points in ITriangles", trianglePointsCount)); int triangleCount = trianglePointsCount / 3; for (int i = 0; i < triangleCount; i++) { WKSPointVA first = GetWKSPointVA(mps, ref pointIndex); WKSPointVA second = GetWKSPointVA(mps, ref pointIndex); WKSPointVA third = GetWKSPointVA(mps, ref pointIndex); var trianglePoints = new List <WKSPointVA> { first, second, third, first }; rings.Add(trianglePoints); } } else { throw new InvalidOperationException(string.Format("{0} not handled", part.GeometryType)); } Marshal.ReleaseComObject(part); } return(rings); }
public void MultiPointPerformanceTest() { IWorkspace ws = TestDataUtils.OpenTopgisTlm(); IFeatureClass mpFc = ((IFeatureWorkspace)ws).OpenFeatureClass("TOPGIS_TLM.TLM_DTM_MASSENPUNKTE"); var watch = new Stopwatch(); WKSPointVA[] sourcePointsArray = null; watch.Start(); long sumArray = 0; long sumSingle = 0; long sumPoints = 0; int limit = 1000 * 120; var featureCount = 0; foreach (IFeature feature in new EnumCursor((ITable)mpFc, null, recycle: true)) { var points = (IPointCollection5)feature.Shape; int pointCount = points.PointCount; sumPoints += pointCount; // Console.WriteLine(pointCount); if (sourcePointsArray == null || sourcePointsArray.Length < points.PointCount) { const int margin = 2000; sourcePointsArray = new WKSPointVA[pointCount + margin]; } long start = watch.ElapsedTicks; double sumMArray = 0; points.QueryWKSPointVA(0, pointCount, out sourcePointsArray[0]); for (var i = 0; i < pointCount; i++) { double currentM = sourcePointsArray[i].m_m; sumMArray += currentM; } long stop = watch.ElapsedTicks; sumArray += stop - start; double sumMSingle = 0; start = watch.ElapsedTicks; for (var i = 0; i < pointCount; i++) { WKSPointVA currentPoint; points.QueryWKSPointVA(i, 1, out currentPoint); double currentM = currentPoint.m_m; sumMSingle += currentM; } stop = watch.ElapsedTicks; sumSingle += stop - start; Assert.AreEqual(sumMArray, sumMSingle); featureCount++; if (watch.ElapsedMilliseconds > limit) { break; } } Console.WriteLine(string.Format("Points: " + sumPoints)); Console.WriteLine(string.Format("Array Tics: " + sumArray)); Console.WriteLine(string.Format("Single Tics:" + sumSingle)); }
private int ReportInvalidPoints([NotNull] IPointCollection points, [NotNull] IRow row) { var points5 = points as IPointCollection5; if (points5 == null) { points5 = new MultipointClass(); points5.AddPointCollection(points); } int pointCount = points.PointCount; if (_sourcePoints == null || _sourcePoints.Length < points.PointCount) { const int margin = 2000; _sourcePoints = new WKSPointVA[pointCount + margin]; } points5.QueryWKSPointVA(0, pointCount, out _sourcePoints[0]); // This would be fast, but about 4* slower then the statement above //for (int i = 0; i < pointCount; i++) //{ // WKSPointVA wksPoint; // points5.QueryWKSPointVA(i, 1, out wksPoint); Dictionary <IssueCode, ErrorPoints> errorPointsDict = null; for (var i = 0; i < pointCount; i++) { WKSPointVA wksPoint = _sourcePoints[i]; string error; bool isNewRow = i == 0; IssueCode code; if (IsInvalidValue(wksPoint.m_m, row, isNewRow, out error, out code)) { if (errorPointsDict == null) { errorPointsDict = new Dictionary <IssueCode, ErrorPoints>(); } Assert.NotNull(code); ErrorPoints errorPoints; if (!errorPointsDict.TryGetValue(code, out errorPoints)) { errorPoints = new ErrorPoints(); errorPointsDict.Add(code, errorPoints); } errorPoints.Add(wksPoint, error); } } //ICollection<IPoint> errorPoints = MeasureUtils.GetPointsWithInvalidM( // points, _queryPoint, invalidValue); if (errorPointsDict == null) { return(NoError); } var errorCount = 0; foreach (KeyValuePair <IssueCode, ErrorPoints> pair in errorPointsDict) { IssueCode issueCode = pair.Key; ErrorPoints errorPoints = pair.Value; IPointCollection5 errorGeometry = new MultipointClass(); errorGeometry.AddWKSPointVA(errorPoints.Points.Count, ref errorPoints.Points.ToArray()[0]); ((IGeometry)errorGeometry).SpatialReference = ((IGeometry)points).SpatialReference; string errorDescription = GetErrorDescription(issueCode, errorPoints.Points.Count, errorPoints.Errors); errorCount += ReportError(errorDescription, (IGeometry)errorGeometry, issueCode, _shapeFieldName, row); } return(errorCount); }