private static int _isPointInPolygonInternalWithQuadTree(com.epl.geometry.Polygon inputPolygon, com.epl.geometry.QuadTreeImpl quadTree, com.epl.geometry.Point2D inputPoint, double tolerance) { com.epl.geometry.Envelope2D envPoly = new com.epl.geometry.Envelope2D(); inputPolygon.QueryLooseEnvelope(envPoly); envPoly.Inflate(tolerance, tolerance); bool bAltenate = inputPolygon.GetFillRule() == com.epl.geometry.Polygon.FillRule.enumFillRuleOddEven; com.epl.geometry.PointInPolygonHelper helper = new com.epl.geometry.PointInPolygonHelper(bAltenate, inputPoint, tolerance); com.epl.geometry.MultiPathImpl mpImpl = (com.epl.geometry.MultiPathImpl)inputPolygon._getImpl(); com.epl.geometry.SegmentIteratorImpl iter = mpImpl.QuerySegmentIterator(); com.epl.geometry.Envelope2D queryEnv = new com.epl.geometry.Envelope2D(); queryEnv.SetCoords(envPoly); queryEnv.xmax = inputPoint.x + tolerance; // no need to query segments to // the right of the point. // Only segments to the left // matter. queryEnv.ymin = inputPoint.y - tolerance; queryEnv.ymax = inputPoint.y + tolerance; com.epl.geometry.QuadTreeImpl.QuadTreeIteratorImpl qiter = quadTree.GetIterator(queryEnv, tolerance); for (int qhandle = qiter.Next(); qhandle != -1; qhandle = qiter.Next()) { iter.ResetToVertex(quadTree.GetElement(qhandle)); if (iter.HasNextSegment()) { com.epl.geometry.Segment segment = iter.NextSegment(); if (helper.ProcessSegment(segment)) { return(-1); } } } // point on boundary return(helper.Result()); }
//dbgSaveToBitmap("c:/temp/_dbg.bmp"); internal bool TryRenderAsSmallEnvelope_(com.epl.geometry.Envelope2D env) { if (!env.IsIntersecting(m_geomEnv)) { return(true); } com.epl.geometry.Envelope2D envPix = new com.epl.geometry.Envelope2D(); envPix.SetCoords(env); m_transform.Transform(env); double strokeHalfWidthPixX = m_stroke_half_widthX_pix; double strokeHalfWidthPixY = m_stroke_half_widthY_pix; if (envPix.GetWidth() > 2 * strokeHalfWidthPixX + 1 || envPix.GetHeight() > 2 * strokeHalfWidthPixY + 1) { return(false); } // This envelope is too narrow/small, so that it can be just drawn as a // rectangle using only boundary color. envPix.Inflate(strokeHalfWidthPixX, strokeHalfWidthPixY); envPix.xmax += 1.0; envPix.ymax += 1.0; // take into account that it does not draw right and // bottom edges. m_callback.SetColor(m_rasterizer, 2); FillEnvelope(m_rasterizer, envPix); return(true); }
public com.epl.geometry.Envelope2D GetInflated(double dx, double dy) { com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); env.SetCoords(this.xmin, this.ymin, this.xmax, this.ymax); env.Inflate(dx, dy); return(env); }
internal static com.epl.geometry.QuadTreeImpl BuildQuadTree(com.epl.geometry.MultiPointImpl multipointImpl, com.epl.geometry.Envelope2D extentOfInterest) { com.epl.geometry.QuadTreeImpl quad_tree_impl = new com.epl.geometry.QuadTreeImpl(extentOfInterest, 8); com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D(); bool resized_extent = false; com.epl.geometry.Envelope2D boundingbox = new com.epl.geometry.Envelope2D(); for (int i = 0; i < multipointImpl.GetPointCount(); i++) { multipointImpl.GetXY(i, pt); if (!extentOfInterest.Contains(pt)) { continue; } boundingbox.SetCoords(pt); int element_handle = quad_tree_impl.Insert(i, boundingbox); if (element_handle == -1) { if (resized_extent) { throw com.epl.geometry.GeometryException.GeometryInternalError(); } // resize extent resized_extent = true; com.epl.geometry.Envelope2D extent = new com.epl.geometry.Envelope2D(); multipointImpl.CalculateEnvelope2D(extent, false); quad_tree_impl.Reset(extent, 8); i = -1; // resets the for-loop continue; } } return(quad_tree_impl); }
public static com.epl.geometry.Envelope MakeEnvelope3() { com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); env.SetCoords(5, 5, 6, 6); com.epl.geometry.Envelope envelope = new com.epl.geometry.Envelope(env); return(envelope); }
public virtual void QueryValidCoordinateRange(com.epl.geometry.Envelope2D env2D) { double delta = 0; switch (GetPrecision()) { case com.epl.geometry.SpatialReferenceImpl.Precision.Integer32: { delta = c_SULIMIT32 / GetGridUnitsXY(); break; } case com.epl.geometry.SpatialReferenceImpl.Precision.Integer64: { delta = c_SULIMIT64 / GetGridUnitsXY(); break; } default: { // TODO throw com.epl.geometry.GeometryException.GeometryInternalError(); } } env2D.SetCoords(GetFalseX(), GetFalseY(), GetFalseX() + delta, GetFalseY() + delta); }
internal virtual void AddRedEnvelope(int element, com.epl.geometry.Envelope2D red_envelope) { if (!m_b_add_red) { throw new com.epl.geometry.GeometryException("invalid call"); } com.epl.geometry.Envelope2D e = new com.epl.geometry.Envelope2D(); e.SetCoords(red_envelope); m_elements_red.Add(element); m_envelopes_red.Add(e); }
internal virtual void AddBlueEnvelope(int element, com.epl.geometry.Envelope2D blue_envelope) { if (!m_b_add_blue) { throw new com.epl.geometry.GeometryException("invalid call"); } com.epl.geometry.Envelope2D e = new com.epl.geometry.Envelope2D(); e.SetCoords(blue_envelope); m_elements_blue.Add(element); m_envelopes_blue.Add(e); }
public static void TestClipIssue258243() { com.epl.geometry.Polygon poly1 = new com.epl.geometry.Polygon(); poly1.StartPath(21.476191371901479, 41.267022001907215); poly1.LineTo(59.669186665158051, 36.62700518555863); poly1.LineTo(20.498578117352313, 30.363180148246094); poly1.LineTo(18.342565836615044, 46.303295352085627); poly1.LineTo(17.869569458621626, 23.886816966894159); poly1.LineTo(19.835465558090434, 20); poly1.LineTo(18.83911285048551, 43.515995498114791); poly1.LineTo(20.864485260298004, 20.235921201027757); poly1.LineTo(18.976127544787012, 20); poly1.LineTo(34.290201277718218, 61.801369014954794); poly1.LineTo(20.734727419368866, 20); poly1.LineTo(18.545865698148113, 20); poly1.LineTo(19.730260558565515, 20); poly1.LineTo(19.924806216827005, 23.780315893949187); poly1.LineTo(21.675168105421452, 36.699924873001258); poly1.LineTo(22.500527828912158, 43.703424859922983); poly1.LineTo(42.009527116514818, 36.995486982256089); poly1.LineTo(24.469729873835782, 58.365871758247039); poly1.LineTo(24.573736036545878, 36.268390409195824); poly1.LineTo(22.726502169802746, 20); poly1.LineTo(23.925834885228145, 20); poly1.LineTo(25.495346880936729, 20); poly1.LineTo(23.320941499288317, 20); poly1.LineTo(24.05655665646276, 28.659578774758632); poly1.LineTo(23.205940789341135, 38.491506888710504); poly1.LineTo(21.472847203385509, 53.057228182018044); poly1.LineTo(25.04257681654104, 20); poly1.LineTo(25.880572351149542, 25.16102863979474); poly1.LineTo(26.756283333879658, 20); poly1.LineTo(21.476191371901479, 41.267022001907215); com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); env.SetCoords(24.269517325186033, 19.999998900000001, 57.305574253225409, 61.801370114954793); try { com.epl.geometry.Geometry output_geom = com.epl.geometry.OperatorClip.Local().Execute(poly1, env, com.epl.geometry.SpatialReference.Create(4326), null); com.epl.geometry.Envelope envPoly = new com.epl.geometry.Envelope(); poly1.QueryEnvelope(envPoly); com.epl.geometry.Envelope e = new com.epl.geometry.Envelope(env); e.Intersect(envPoly); com.epl.geometry.Envelope clippedEnv = new com.epl.geometry.Envelope(); output_geom.QueryEnvelope(clippedEnv); NUnit.Framework.Assert.IsTrue(System.Math.Abs(clippedEnv.GetXMin() - e.GetXMin()) < 1e-10 && System.Math.Abs(clippedEnv.GetYMin() - e.GetYMin()) < 1e-10 && System.Math.Abs(clippedEnv.GetXMax() - e.GetXMax()) < 1e-10 && System.Math.Abs(clippedEnv.GetYMax() - e.GetYMax()) < 1e-10); } catch (System.Exception) { NUnit.Framework.Assert.IsTrue(false); } }
internal static com.epl.geometry.QuadTree BuildQuadTree_(com.epl.geometry.MultiPointImpl multipointImpl) { com.epl.geometry.Envelope2D extent = new com.epl.geometry.Envelope2D(); multipointImpl.QueryEnvelope2D(extent); com.epl.geometry.QuadTree quadTree = new com.epl.geometry.QuadTree(extent, 8); com.epl.geometry.Envelope2D boundingbox = new com.epl.geometry.Envelope2D(); com.epl.geometry.Point2D pt; for (int i = 0; i < multipointImpl.GetPointCount(); i++) { pt = multipointImpl.GetXY(i); boundingbox.SetCoords(pt.x, pt.y, pt.x, pt.y); quadTree.Insert(i, boundingbox, -1); } return(quadTree); }
internal static com.epl.geometry.Geometry SymmetricDifference(com.epl.geometry.Geometry geometry_a, com.epl.geometry.Geometry geometry_b, com.epl.geometry.SpatialReference spatial_reference, com.epl.geometry.ProgressTracker progress_tracker) { int dim_a = geometry_a.GetDimension(); int dim_b = geometry_b.GetDimension(); if (geometry_a.IsEmpty() && geometry_b.IsEmpty()) { return(dim_a > dim_b ? geometry_a : geometry_b); } if (geometry_a.IsEmpty()) { return(geometry_b); } if (geometry_b.IsEmpty()) { return(geometry_a); } com.epl.geometry.Envelope2D env_a = new com.epl.geometry.Envelope2D(); com.epl.geometry.Envelope2D env_b = new com.epl.geometry.Envelope2D(); com.epl.geometry.Envelope2D env_merged = new com.epl.geometry.Envelope2D(); geometry_a.QueryEnvelope2D(env_a); geometry_b.QueryEnvelope2D(env_b); env_merged.SetCoords(env_a); env_merged.Merge(env_b); double tolerance = com.epl.geometry.InternalUtils.CalculateToleranceFromGeometry(spatial_reference, env_merged, false); int type_a = geometry_a.GetType().Value(); int type_b = geometry_b.GetType().Value(); if (type_a == com.epl.geometry.Geometry.GeometryType.Point && type_b == com.epl.geometry.Geometry.GeometryType.Point) { return(PointSymDiffPoint_((com.epl.geometry.Point)(geometry_a), (com.epl.geometry.Point)(geometry_b), tolerance, progress_tracker)); } if (type_a != type_b) { if (dim_a > 0 || dim_b > 0) { return(dim_a > dim_b ? geometry_a : geometry_b); } // Multi_point/Point case if (type_a == com.epl.geometry.Geometry.GeometryType.MultiPoint) { return(MultiPointSymDiffPoint_((com.epl.geometry.MultiPoint)(geometry_a), (com.epl.geometry.Point)(geometry_b), tolerance, progress_tracker)); } return(MultiPointSymDiffPoint_((com.epl.geometry.MultiPoint)(geometry_b), (com.epl.geometry.Point)(geometry_a), tolerance, progress_tracker)); } return(com.epl.geometry.TopologicalOperations.SymmetricDifference(geometry_a, geometry_b, spatial_reference, progress_tracker)); }
public static void TestClipAttributes() { com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorClip clipOp = (com.epl.geometry.OperatorClip)engine.GetOperator(com.epl.geometry.Operator.Type.Clip); { com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); polygon.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); polygon.StartPath(0, 0); polygon.LineTo(30, 30); polygon.LineTo(60, 0); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 0); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 60); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 120); com.epl.geometry.Envelope2D clipper = new com.epl.geometry.Envelope2D(); clipper.SetCoords(10, 0, 50, 20); com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, clipper, com.epl.geometry.SpatialReference.Create(4326), null); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 100); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 19.999999999999996); // 20.0 NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 20); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 3, 0) == 40); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 4, 0) == 80); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 5, 0) == 100); } { com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(); polygon.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M); polygon.StartPath(0, 0); polygon.LineTo(0, 40); polygon.LineTo(20, 40); polygon.LineTo(20, 0); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 0, 0, 0); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 1, 0, 60); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 2, 0, 120); polygon.SetAttribute(com.epl.geometry.VertexDescription.Semantics.M, 3, 0, 180); com.epl.geometry.Envelope2D clipper = new com.epl.geometry.Envelope2D(); clipper.SetCoords(0, 10, 20, 20); com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, clipper, com.epl.geometry.SpatialReference.Create(4326), null); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 0, 0) == 15); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 1, 0) == 30); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 2, 0) == 150); NUnit.Framework.Assert.IsTrue(clippedPolygon.GetAttributeAsDbl(com.epl.geometry.VertexDescription.Semantics.M, 3, 0) == 165); } }
/// <summary>Sets the envelope from the attribute stream.</summary> /// <remarks> /// Sets the envelope from the attribute stream. The attribute stream stores /// interleaved x and y. The envelope will be set to empty if the pointCount /// is zero. /// </remarks> public void SetEnvelopeFromPoints(int pointCount, com.epl.geometry.Envelope2D inOutEnv) { if (pointCount == 0) { inOutEnv.SetEmpty(); return; } if (pointCount < 0) { pointCount = Size() / 2; } else { if (pointCount * 2 > Size()) { throw new System.ArgumentException(); } } inOutEnv.SetCoords(Read(0), Read(1)); for (int i = 1; i < pointCount; i++) { inOutEnv.MergeNE(Read(i * 2), Read(i * 2 + 1)); } }
internal static com.epl.geometry.Envelope2DIntersectorImpl GetEnvelope2DIntersectorForParts(com.epl.geometry.MultiPathImpl multipathImplA, com.epl.geometry.MultiPathImpl multipathImplB, double tolerance, bool bExteriorOnlyA, bool bExteriorOnlyB) { int type_a = multipathImplA.GetType().Value(); int type_b = multipathImplB.GetType().Value(); com.epl.geometry.Envelope2D env_a = new com.epl.geometry.Envelope2D(); com.epl.geometry.Envelope2D env_b = new com.epl.geometry.Envelope2D(); multipathImplA.QueryLooseEnvelope2D(env_a); multipathImplB.QueryLooseEnvelope2D(env_b); env_a.Inflate(tolerance, tolerance); env_b.Inflate(tolerance, tolerance); com.epl.geometry.Envelope2D envInter = new com.epl.geometry.Envelope2D(); envInter.SetCoords(env_a); envInter.Intersect(env_b); com.epl.geometry.Envelope2DIntersectorImpl intersector = new com.epl.geometry.Envelope2DIntersectorImpl(); intersector.SetTolerance(tolerance); bool b_found_red = false; intersector.StartRedConstruction(); for (int ipath_a = 0, npaths = multipathImplA.GetPathCount(); ipath_a < npaths; ipath_a++) { if (bExteriorOnlyA && type_a == com.epl.geometry.Geometry.GeometryType.Polygon && !multipathImplA.IsExteriorRing(ipath_a)) { continue; } multipathImplA.QueryPathEnvelope2D(ipath_a, env_a); if (!env_a.IsIntersecting(envInter)) { continue; } b_found_red = true; intersector.AddRedEnvelope(ipath_a, env_a); } intersector.EndRedConstruction(); if (!b_found_red) { return(null); } bool b_found_blue = false; intersector.StartBlueConstruction(); for (int ipath_b = 0, npaths = multipathImplB.GetPathCount(); ipath_b < npaths; ipath_b++) { if (bExteriorOnlyB && type_b == com.epl.geometry.Geometry.GeometryType.Polygon && !multipathImplB.IsExteriorRing(ipath_b)) { continue; } multipathImplB.QueryPathEnvelope2D(ipath_b, env_b); if (!env_b.IsIntersecting(envInter)) { continue; } b_found_blue = true; intersector.AddBlueEnvelope(ipath_b, env_b); } intersector.EndBlueConstruction(); if (!b_found_blue) { return(null); } return(intersector); }
internal static com.epl.geometry.Envelope2DIntersectorImpl GetEnvelope2DIntersector(com.epl.geometry.MultiPathImpl multipathImplA, com.epl.geometry.MultiPathImpl multipathImplB, double tolerance) { com.epl.geometry.Envelope2D env_a = new com.epl.geometry.Envelope2D(); com.epl.geometry.Envelope2D env_b = new com.epl.geometry.Envelope2D(); multipathImplA.QueryLooseEnvelope2D(env_a); multipathImplB.QueryLooseEnvelope2D(env_b); env_a.Inflate(tolerance, tolerance); env_b.Inflate(tolerance, tolerance); com.epl.geometry.Envelope2D envInter = new com.epl.geometry.Envelope2D(); envInter.SetCoords(env_a); envInter.Intersect(env_b); com.epl.geometry.SegmentIteratorImpl segIterA = multipathImplA.QuerySegmentIterator(); com.epl.geometry.SegmentIteratorImpl segIterB = multipathImplB.QuerySegmentIterator(); com.epl.geometry.Envelope2DIntersectorImpl intersector = new com.epl.geometry.Envelope2DIntersectorImpl(); intersector.SetTolerance(tolerance); bool b_found_red = false; intersector.StartRedConstruction(); while (segIterA.NextPath()) { while (segIterA.HasNextSegment()) { com.epl.geometry.Segment segmentA = segIterA.NextSegment(); segmentA.QueryEnvelope2D(env_a); if (!env_a.IsIntersecting(envInter)) { continue; } b_found_red = true; com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); env.SetCoords(env_a); intersector.AddRedEnvelope(segIterA.GetStartPointIndex(), env); } } intersector.EndRedConstruction(); if (!b_found_red) { return(null); } bool b_found_blue = false; intersector.StartBlueConstruction(); while (segIterB.NextPath()) { while (segIterB.HasNextSegment()) { com.epl.geometry.Segment segmentB = segIterB.NextSegment(); segmentB.QueryEnvelope2D(env_b); if (!env_b.IsIntersecting(envInter)) { continue; } b_found_blue = true; com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); env.SetCoords(env_b); intersector.AddBlueEnvelope(segIterB.GetStartPointIndex(), env); } } intersector.EndBlueConstruction(); if (!b_found_blue) { return(null); } return(intersector); }
public static void TestClipGeometries() { // RandomTest(); com.epl.geometry.OperatorFactoryLocal engine = com.epl.geometry.OperatorFactoryLocal.GetInstance(); com.epl.geometry.OperatorClip clipOp = (com.epl.geometry.OperatorClip)engine.GetOperator(com.epl.geometry.Operator.Type.Clip); com.epl.geometry.Polygon polygon = MakePolygon(); com.epl.geometry.SimpleGeometryCursor polygonCurs = new com.epl.geometry.SimpleGeometryCursor(polygon); com.epl.geometry.Polyline polyline = MakePolyline(); com.epl.geometry.SimpleGeometryCursor polylineCurs = new com.epl.geometry.SimpleGeometryCursor(polyline); com.epl.geometry.MultiPoint multipoint = MakeMultiPoint(); com.epl.geometry.SimpleGeometryCursor multipointCurs = new com.epl.geometry.SimpleGeometryCursor(multipoint); com.epl.geometry.Point point = MakePoint(); com.epl.geometry.SimpleGeometryCursor pointCurs = new com.epl.geometry.SimpleGeometryCursor(point); com.epl.geometry.SpatialReference spatialRef = com.epl.geometry.SpatialReference.Create(3857); com.epl.geometry.Envelope2D envelope = new com.epl.geometry.Envelope2D(); envelope.xmin = 0; envelope.xmax = 20; envelope.ymin = 5; envelope.ymax = 15; // Cursor implementation com.epl.geometry.GeometryCursor clipPolygonCurs = clipOp.Execute(polygonCurs, envelope, spatialRef, null); com.epl.geometry.Polygon clippedPolygon = (com.epl.geometry.Polygon)clipPolygonCurs.Next(); double area = clippedPolygon.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 25) < 0.00001); // Single Geometry implementation clippedPolygon = (com.epl.geometry.Polygon)clipOp.Execute(polygon, envelope, spatialRef, null); area = clippedPolygon.CalculateArea2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(area - 25) < 0.00001); // Cursor implementation com.epl.geometry.GeometryCursor clipPolylineCurs = clipOp.Execute(polylineCurs, envelope, spatialRef, null); com.epl.geometry.Polyline clippedPolyline = (com.epl.geometry.Polyline)clipPolylineCurs.Next(); double length = clippedPolyline.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(length - 10 * System.Math.Sqrt(2.0)) < 1e-10); // Single Geometry implementation clippedPolyline = (com.epl.geometry.Polyline)clipOp.Execute(polyline, envelope, spatialRef, null); length = clippedPolyline.CalculateLength2D(); NUnit.Framework.Assert.IsTrue(System.Math.Abs(length - 10 * System.Math.Sqrt(2.0)) < 1e-10); // Cursor implementation com.epl.geometry.GeometryCursor clipMulti_pointCurs = clipOp.Execute(multipointCurs, envelope, spatialRef, null); com.epl.geometry.MultiPoint clipped_multi_point = (com.epl.geometry.MultiPoint)clipMulti_pointCurs.Next(); int pointCount = clipped_multi_point.GetPointCount(); NUnit.Framework.Assert.IsTrue(pointCount == 2); // Cursor implementation com.epl.geometry.GeometryCursor clipPointCurs = clipOp.Execute(pointCurs, envelope, spatialRef, null); com.epl.geometry.Point clippedPoint = (com.epl.geometry.Point)clipPointCurs.Next(); NUnit.Framework.Assert.IsTrue(clippedPoint != null); // RandomTest(); com.epl.geometry.Polyline _poly = new com.epl.geometry.Polyline(); _poly.StartPath(2, 2); _poly.LineTo(0, 0); com.epl.geometry.Envelope2D _env = new com.epl.geometry.Envelope2D(); _env.SetCoords(2, 1, 5, 3); com.epl.geometry.Polyline _clippedPolyline = (com.epl.geometry.Polyline)clipOp.Execute(_poly, _env, spatialRef, null); NUnit.Framework.Assert.IsTrue(_clippedPolyline.IsEmpty()); { com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(); poly.AddEnvelope(new com.epl.geometry.Envelope2D(0, 0, 100, 100), false); poly.AddEnvelope(new com.epl.geometry.Envelope2D(5, 5, 95, 95), true); com.epl.geometry.Polygon clippedPoly = (com.epl.geometry.Polygon)clipOp.Execute(poly, new com.epl.geometry.Envelope2D(-10, -10, 110, 50), spatialRef, null); NUnit.Framework.Assert.IsTrue(clippedPoly.GetPathCount() == 1); NUnit.Framework.Assert.IsTrue(clippedPoly.GetPointCount() == 8); } }
public static com.epl.geometry.Envelope2D Construct(com.epl.geometry.Envelope2D other) { com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); env.SetCoords(other); return(env); }
public Envelope(com.epl.geometry.Envelope2D env2D) { m_description = com.epl.geometry.VertexDescriptionDesignerImpl.GetDefaultDescriptor2D(); m_envelope.SetCoords(env2D); m_envelope.Normalize(); }
public static int IsPointInRing(com.epl.geometry.MultiPathImpl inputPolygonImpl, int iRing, com.epl.geometry.Point2D inputPoint, double tolerance, com.epl.geometry.QuadTree quadTree) { com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); inputPolygonImpl.QueryLooseEnvelope2D(env); env.Inflate(tolerance, tolerance); if (!env.Contains(inputPoint)) { return(0); } bool bAltenate = true; com.epl.geometry.PointInPolygonHelper helper = new com.epl.geometry.PointInPolygonHelper(bAltenate, inputPoint, tolerance); if (quadTree != null) { com.epl.geometry.Envelope2D queryEnv = new com.epl.geometry.Envelope2D(); queryEnv.SetCoords(env); queryEnv.xmax = inputPoint.x + tolerance; // no need to query // segments to // the right of the // point. // Only segments to the // left // matter. queryEnv.ymin = inputPoint.y - tolerance; queryEnv.ymax = inputPoint.y + tolerance; com.epl.geometry.SegmentIteratorImpl iter = inputPolygonImpl.QuerySegmentIterator(); com.epl.geometry.QuadTree.QuadTreeIterator qiter = quadTree.GetIterator(queryEnv, tolerance); for (int qhandle = qiter.Next(); qhandle != -1; qhandle = qiter.Next()) { iter.ResetToVertex(quadTree.GetElement(qhandle), iRing); if (iter.HasNextSegment()) { if (iter.GetPathIndex() != iRing) { continue; } com.epl.geometry.Segment segment = iter.NextSegment(); if (helper.ProcessSegment(segment)) { return(-1); } } } // point on boundary return(helper.Result()); } else { com.epl.geometry.SegmentIteratorImpl iter = inputPolygonImpl.QuerySegmentIterator(); iter.ResetToPath(iRing); if (iter.NextPath()) { while (iter.HasNextSegment()) { com.epl.geometry.Segment segment = iter.NextSegment(); if (helper.ProcessSegment(segment)) { return(-1); } } } // point on boundary return(helper.Result()); } }
internal void Init(com.epl.geometry.MultiVertexGeometryImpl geom, double toleranceXY, int rasterSizeBytes) { // _ASSERT(CanUseAccelerator(geom)); m_width = System.Math.Max((int)(System.Math.Sqrt(rasterSizeBytes) * 2 + 0.5), 64); m_scanLineSize = (m_width * 2 + 31) / 32; // 2 bits per pixel m_geomEnv = new com.epl.geometry.Envelope2D(); m_toleranceXY = toleranceXY; // calculate bitmap size int size = 0; int width = m_width; int scanLineSize = m_scanLineSize; while (width >= 8) { size += width * scanLineSize; width /= 2; scanLineSize = (width * 2 + 31) / 32; } // allocate the bitmap, that contains the base and the mip-levels m_bitmap = new int[size]; for (int i = 0; i < size; i++) { m_bitmap[i] = 0; } m_rasterizer = new com.epl.geometry.SimpleRasterizer(); com.epl.geometry.RasterizedGeometry2DImpl.ScanCallbackImpl callback = new com.epl.geometry.RasterizedGeometry2DImpl.ScanCallbackImpl(this, m_bitmap, m_scanLineSize); m_callback = callback; m_rasterizer.Setup(m_width, m_width, callback); geom.QueryEnvelope2D(m_geomEnv); if (m_geomEnv.GetWidth() > m_width * m_geomEnv.GetHeight() || m_geomEnv.GetHeight() > m_geomEnv.GetWidth() * m_width) { } // the geometry is thin and the rasterizer is not needed. m_geomEnv.Inflate(toleranceXY, toleranceXY); com.epl.geometry.Envelope2D worldEnv = new com.epl.geometry.Envelope2D(); com.epl.geometry.Envelope2D pixEnv = com.epl.geometry.Envelope2D.Construct(1, 1, m_width - 2, m_width - 2); double minWidth = toleranceXY * pixEnv.GetWidth(); // min width is such // that the size of // one pixel is // equal to the // tolerance double minHeight = toleranceXY * pixEnv.GetHeight(); worldEnv.SetCoords(m_geomEnv.GetCenter(), System.Math.Max(minWidth, m_geomEnv.GetWidth()), System.Math.Max(minHeight, m_geomEnv.GetHeight())); m_stroke_half_widthX_pix = worldEnv.GetWidth() / pixEnv.GetWidth(); m_stroke_half_widthY_pix = worldEnv.GetHeight() / pixEnv.GetHeight(); // The stroke half width. Later it will be inflated to account for // pixels size. m_stroke_half_width = m_toleranceXY; m_transform = new com.epl.geometry.Transformation2D(); m_transform.InitializeFromRect(worldEnv, pixEnv); // geom to pixels com.epl.geometry.Transformation2D identityTransform = new com.epl.geometry.Transformation2D(); switch (geom.GetType().Value()) { case com.epl.geometry.Geometry.GeometryType.MultiPoint: { callback.SetColor(m_rasterizer, 2); FillPoints(m_rasterizer, (com.epl.geometry.MultiPointImpl)geom, m_stroke_half_width); break; } case com.epl.geometry.Geometry.GeometryType.Polyline: { callback.SetColor(m_rasterizer, 2); StrokeDrawPolyPath(m_rasterizer, (com.epl.geometry.MultiPathImpl)geom._getImpl(), m_stroke_half_width); break; } case com.epl.geometry.Geometry.GeometryType.Polygon: { bool isWinding = false; // NOTE: change when winding is supported callback.SetColor(m_rasterizer, 1); FillMultiPath(m_rasterizer, m_transform, (com.epl.geometry.MultiPathImpl)geom, isWinding); callback.SetColor(m_rasterizer, 2); StrokeDrawPolyPath(m_rasterizer, (com.epl.geometry.MultiPathImpl)geom._getImpl(), m_stroke_half_width); break; } } m_dx = m_transform.xx; m_dy = m_transform.yy; m_x0 = m_transform.xd; m_y0 = m_transform.yd; BuildLevels(); }
public override void QueryEnvelope2D(com.epl.geometry.Envelope2D env) { env.SetCoords(m_xStart, m_yStart, m_xEnd, m_yEnd); env.Normalize(); }
public static void TestEnvelope2Dintersector() { System.Collections.Generic.List <com.epl.geometry.Envelope2D> envelopes = new System.Collections.Generic.List <com.epl.geometry.Envelope2D>(0); com.epl.geometry.Envelope2D env0 = new com.epl.geometry.Envelope2D(2, 3, 4, 4); com.epl.geometry.Envelope2D env1 = new com.epl.geometry.Envelope2D(5, 13, 9, 15); com.epl.geometry.Envelope2D env2 = new com.epl.geometry.Envelope2D(6, 9, 11, 12); com.epl.geometry.Envelope2D env3 = new com.epl.geometry.Envelope2D(8, 10, 9, 17); com.epl.geometry.Envelope2D env4 = new com.epl.geometry.Envelope2D(11.001, 12, 14, 14); com.epl.geometry.Envelope2D env5 = new com.epl.geometry.Envelope2D(1, 3, 3, 4); com.epl.geometry.Envelope2D env6 = new com.epl.geometry.Envelope2D(0, 2, 5, 10); com.epl.geometry.Envelope2D env7 = new com.epl.geometry.Envelope2D(4, 7, 5, 10); com.epl.geometry.Envelope2D env8 = new com.epl.geometry.Envelope2D(3, 15, 15, 15); com.epl.geometry.Envelope2D env9 = new com.epl.geometry.Envelope2D(0, 9, 14, 9); com.epl.geometry.Envelope2D env10 = new com.epl.geometry.Envelope2D(0, 8.999, 14, 8.999); envelopes.Add(env0); envelopes.Add(env1); envelopes.Add(env2); envelopes.Add(env3); envelopes.Add(env4); envelopes.Add(env5); envelopes.Add(env6); envelopes.Add(env7); envelopes.Add(env8); envelopes.Add(env9); envelopes.Add(env10); com.epl.geometry.Envelope2DIntersectorImpl intersector = new com.epl.geometry.Envelope2DIntersectorImpl(); intersector.SetTolerance(0.001); intersector.StartConstruction(); for (int i = 0; i < envelopes.Count; i++) { intersector.AddEnvelope(i, envelopes[i]); } intersector.EndConstruction(); int count = 0; while (intersector.Next()) { int env_a = intersector.GetHandleA(); int env_b = intersector.GetHandleB(); count++; com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); env.SetCoords(envelopes[env_a]); env.Inflate(0.001, 0.001); NUnit.Framework.Assert.IsTrue(env.IsIntersecting(envelopes[env_b])); } System.Diagnostics.Debug.Assert((count == 16)); com.epl.geometry.Envelope2DIntersectorImpl intersector2 = new com.epl.geometry.Envelope2DIntersectorImpl(); intersector2.SetTolerance(0.0); intersector2.StartConstruction(); for (int i_1 = 0; i_1 < envelopes.Count; i_1++) { intersector2.AddEnvelope(i_1, envelopes[i_1]); } intersector2.EndConstruction(); count = 0; while (intersector2.Next()) { int env_a = intersector2.GetHandleA(); int env_b = intersector2.GetHandleB(); count++; com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); env.SetCoords(envelopes[env_a]); NUnit.Framework.Assert.IsTrue(env.IsIntersecting(envelopes[env_b])); } System.Diagnostics.Debug.Assert((count == 13)); env0 = new com.epl.geometry.Envelope2D(0, 0, 0, 10); env1 = new com.epl.geometry.Envelope2D(0, 10, 10, 10); env2 = new com.epl.geometry.Envelope2D(10, 0, 10, 10); env3 = new com.epl.geometry.Envelope2D(0, 0, 10, 0); envelopes.Clear(); envelopes.Add(env0); envelopes.Add(env1); envelopes.Add(env2); envelopes.Add(env3); com.epl.geometry.Envelope2DIntersectorImpl intersector3 = new com.epl.geometry.Envelope2DIntersectorImpl(); intersector3.SetTolerance(0.001); intersector3.StartConstruction(); for (int i_2 = 0; i_2 < envelopes.Count; i_2++) { intersector3.AddEnvelope(i_2, envelopes[i_2]); } intersector3.EndConstruction(); count = 0; while (intersector3.Next()) { int env_a = intersector3.GetHandleA(); int env_b = intersector3.GetHandleB(); count++; com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); env.SetCoords(envelopes[env_a]); NUnit.Framework.Assert.IsTrue(env.IsIntersecting(envelopes[env_b])); } NUnit.Framework.Assert.IsTrue(count == 4); env0 = new com.epl.geometry.Envelope2D(0, 0, 0, 10); envelopes.Clear(); envelopes.Add(env0); envelopes.Add(env0); envelopes.Add(env0); envelopes.Add(env0); com.epl.geometry.Envelope2DIntersectorImpl intersector4 = new com.epl.geometry.Envelope2DIntersectorImpl(); intersector4.SetTolerance(0.001); intersector4.StartConstruction(); for (int i_3 = 0; i_3 < envelopes.Count; i_3++) { intersector4.AddEnvelope(i_3, envelopes[i_3]); } intersector4.EndConstruction(); count = 0; while (intersector4.Next()) { int env_a = intersector4.GetHandleA(); int env_b = intersector4.GetHandleB(); count++; com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); env.SetCoords(envelopes[env_a]); NUnit.Framework.Assert.IsTrue(env.IsIntersecting(envelopes[env_b])); } System.Diagnostics.Debug.Assert((count == 6)); env0 = new com.epl.geometry.Envelope2D(0, 10, 10, 10); envelopes.Clear(); envelopes.Add(env0); envelopes.Add(env0); envelopes.Add(env0); envelopes.Add(env0); com.epl.geometry.Envelope2DIntersectorImpl intersector5 = new com.epl.geometry.Envelope2DIntersectorImpl(); intersector5.SetTolerance(0.001); intersector5.StartConstruction(); for (int i_4 = 0; i_4 < envelopes.Count; i_4++) { intersector5.AddEnvelope(i_4, envelopes[i_4]); } intersector5.EndConstruction(); count = 0; while (intersector5.Next()) { int env_a = intersector5.GetHandleA(); int env_b = intersector5.GetHandleB(); count++; com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); env.SetCoords(envelopes[env_a]); NUnit.Framework.Assert.IsTrue(env.IsIntersecting(envelopes[env_b])); } NUnit.Framework.Assert.IsTrue(count == 6); }
internal static com.epl.geometry.Geometry Difference(com.epl.geometry.Geometry geometry_a, com.epl.geometry.Geometry geometry_b, com.epl.geometry.SpatialReference spatial_reference, com.epl.geometry.ProgressTracker progress_tracker) { if (geometry_a.IsEmpty() || geometry_b.IsEmpty()) { return(geometry_a); } int dimension_a = geometry_a.GetDimension(); int dimension_b = geometry_b.GetDimension(); if (dimension_a > dimension_b) { return(geometry_a); } int type_a = geometry_a.GetType().Value(); int type_b = geometry_b.GetType().Value(); com.epl.geometry.Envelope2D env_a = new com.epl.geometry.Envelope2D(); com.epl.geometry.Envelope2D env_b = new com.epl.geometry.Envelope2D(); com.epl.geometry.Envelope2D env_merged = new com.epl.geometry.Envelope2D(); geometry_a.QueryEnvelope2D(env_a); geometry_b.QueryEnvelope2D(env_b); env_merged.SetCoords(env_a); env_merged.Merge(env_b); double tolerance = com.epl.geometry.InternalUtils.CalculateToleranceFromGeometry(spatial_reference, env_merged, false); double tolerance_cluster = tolerance * System.Math.Sqrt(2.0) * 1.00001; com.epl.geometry.Envelope2D env_a_inflated = new com.epl.geometry.Envelope2D(); env_a_inflated.SetCoords(env_a); env_a_inflated.Inflate(tolerance_cluster, tolerance_cluster); // inflate // by // cluster // tolerance if (!env_a_inflated.IsIntersecting(env_b)) { return(geometry_a); } if (dimension_a == 1 && dimension_b == 2) { return(PolylineMinusArea_(geometry_a, geometry_b, type_b, spatial_reference, progress_tracker)); } if (type_a == com.epl.geometry.Geometry.GeometryType.Point) { com.epl.geometry.Geometry geometry_b_; if (com.epl.geometry.MultiPath.IsSegment(type_b)) { geometry_b_ = new com.epl.geometry.Polyline(geometry_b.GetDescription()); ((com.epl.geometry.Polyline)(geometry_b_)).AddSegment((com.epl.geometry.Segment)(geometry_b), true); } else { geometry_b_ = geometry_b; } switch (type_b) { case com.epl.geometry.Geometry.GeometryType.Polygon: { return(PointMinusPolygon_((com.epl.geometry.Point)(geometry_a), (com.epl.geometry.Polygon)(geometry_b_), tolerance, progress_tracker)); } case com.epl.geometry.Geometry.GeometryType.Polyline: { return(PointMinusPolyline_((com.epl.geometry.Point)(geometry_a), (com.epl.geometry.Polyline)(geometry_b_), tolerance, progress_tracker)); } case com.epl.geometry.Geometry.GeometryType.MultiPoint: { return(PointMinusMultiPoint_((com.epl.geometry.Point)(geometry_a), (com.epl.geometry.MultiPoint)(geometry_b_), tolerance, progress_tracker)); } case com.epl.geometry.Geometry.GeometryType.Envelope: { return(PointMinusEnvelope_((com.epl.geometry.Point)(geometry_a), (com.epl.geometry.Envelope)(geometry_b_), tolerance, progress_tracker)); } case com.epl.geometry.Geometry.GeometryType.Point: { return(PointMinusPoint_((com.epl.geometry.Point)(geometry_a), (com.epl.geometry.Point)(geometry_b_), tolerance, progress_tracker)); } default: { throw new System.ArgumentException(); } } } else { if (type_a == com.epl.geometry.Geometry.GeometryType.MultiPoint) { switch (type_b) { case com.epl.geometry.Geometry.GeometryType.Polygon: { return(MultiPointMinusPolygon_((com.epl.geometry.MultiPoint)(geometry_a), (com.epl.geometry.Polygon)(geometry_b), tolerance, progress_tracker)); } case com.epl.geometry.Geometry.GeometryType.Envelope: { return(MultiPointMinusEnvelope_((com.epl.geometry.MultiPoint)(geometry_a), (com.epl.geometry.Envelope)(geometry_b), tolerance, progress_tracker)); } case com.epl.geometry.Geometry.GeometryType.Point: { return(MultiPointMinusPoint_((com.epl.geometry.MultiPoint)(geometry_a), (com.epl.geometry.Point)(geometry_b), tolerance, progress_tracker)); } default: { break; } } } } return(com.epl.geometry.TopologicalOperations.Difference(geometry_a, geometry_b, spatial_reference, progress_tracker)); }
public static void Test_perf_quad_tree() { com.epl.geometry.Envelope extent1 = new com.epl.geometry.Envelope(); extent1.SetCoords(-1000, -1000, 1000, 1000); com.epl.geometry.RandomCoordinateGenerator generator1 = new com.epl.geometry.RandomCoordinateGenerator(1000, extent1, 0.001); //HiResTimer timer; for (int N = 16; N <= 1024; N *= 2) { //timer.StartMeasurement(); com.epl.geometry.Envelope2D extent = new com.epl.geometry.Envelope2D(); extent.SetCoords(-1000, -1000, 1000, 1000); System.Collections.Generic.Dictionary <int, com.epl.geometry.Envelope2D> data = new System.Collections.Generic.Dictionary <int, com.epl.geometry.Envelope2D>(0); com.epl.geometry.QuadTree qt = new com.epl.geometry.QuadTree(extent, 10); for (int i = 0; i < N; i++) { com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(); com.epl.geometry.Point2D center = generator1.GetRandomCoord().GetXY(); double w = 10; env.SetCoords(center, w, w); env.Intersect(extent); if (env.IsEmpty()) { continue; } int h = qt.Insert(i, env); data[h] = env; } int ecount = 0; com.epl.geometry.AttributeStreamOfInt32 handles = new com.epl.geometry.AttributeStreamOfInt32(0); com.epl.geometry.QuadTree.QuadTreeIterator iter = qt.GetIterator(); System.Collections.Generic.IEnumerator <System.Collections.Generic.KeyValuePair <int, com.epl.geometry.Envelope2D> > pairs = data.GetEnumerator(); while (pairs.MoveNext()) { System.Collections.Generic.KeyValuePair <int, com.epl.geometry.Envelope2D> entry = pairs.Current; iter.ResetIterator((com.epl.geometry.Envelope2D)entry.Value, 0.001); bool remove_self = false; for (int h = iter.Next(); h != -1; h = iter.Next()) { if (h != entry.Key) { handles.Add(h); } else { remove_self = true; } ecount++; } for (int i_1 = 0; i_1 < handles.Size(); i_1++) { qt.RemoveElement(handles.Get(i_1)); } //remove elements that were selected. if (remove_self) { qt.RemoveElement(entry.Key); } handles.Resize(0); } } }