/// <exception cref="com.fasterxml.jackson.core.JsonParseException"/>
        /// <exception cref="System.IO.IOException"/>
        internal virtual bool TestEnvelope()
        {
            bool bAnswer = true;

            com.epl.geometry.Envelope envelope = new com.epl.geometry.Envelope();
            envelope.SetCoords(-109.55, 25.76, -86.39, 49.94);
            {
                com.fasterxml.jackson.core.JsonParser envelopeWGS84Parser = factory.CreateParser(com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWGS84, envelope));
                com.epl.geometry.MapGeometry          envelopeWGS84MP     = com.epl.geometry.GeometryEngine.JsonToGeometry(envelopeWGS84Parser);
                NUnit.Framework.Assert.IsTrue(envelope.IsEmpty() == envelopeWGS84MP.GetGeometry().IsEmpty());
                NUnit.Framework.Assert.IsTrue(envelope.GetXMax() == ((com.epl.geometry.Envelope)envelopeWGS84MP.GetGeometry()).GetXMax());
                NUnit.Framework.Assert.IsTrue(envelope.GetYMax() == ((com.epl.geometry.Envelope)envelopeWGS84MP.GetGeometry()).GetYMax());
                NUnit.Framework.Assert.IsTrue(envelope.GetXMin() == ((com.epl.geometry.Envelope)envelopeWGS84MP.GetGeometry()).GetXMin());
                NUnit.Framework.Assert.IsTrue(envelope.GetYMin() == ((com.epl.geometry.Envelope)envelopeWGS84MP.GetGeometry()).GetYMin());
                NUnit.Framework.Assert.IsTrue(spatialReferenceWGS84.GetID() == envelopeWGS84MP.GetSpatialReference().GetID());
                if (!CheckResultSpatialRef(envelopeWGS84MP, 4326, 0))
                {
                    bAnswer = false;
                }
            }
            {
                // export
                com.epl.geometry.Envelope e = new com.epl.geometry.Envelope();
                e.AddAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
                e.AddAttribute(com.epl.geometry.VertexDescription.Semantics.M);
                string s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, e);
                NUnit.Framework.Assert.IsTrue(s.Equals("{\"xmin\":null,\"ymin\":null,\"xmax\":null,\"ymax\":null,\"zmin\":null,\"zmax\":null,\"mmin\":null,\"mmax\":null,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"));
                e.SetCoords(0, 1, 2, 3);
                com.epl.geometry.Envelope1D z = new com.epl.geometry.Envelope1D();
                com.epl.geometry.Envelope1D m = new com.epl.geometry.Envelope1D();
                z.SetCoords(5, 7);
                m.SetCoords(11, 13);
                e.SetInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0, z);
                e.SetInterval(com.epl.geometry.VertexDescription.Semantics.M, 0, m);
                s = com.epl.geometry.GeometryEngine.GeometryToJson(spatialReferenceWebMerc1, e);
                NUnit.Framework.Assert.IsTrue(s.Equals("{\"xmin\":0,\"ymin\":1,\"xmax\":2,\"ymax\":3,\"zmin\":5,\"zmax\":7,\"mmin\":11,\"mmax\":13,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}"));
            }
            {
                // import
                string s = "{\"xmin\":0.0,\"ymin\":1.0,\"xmax\":2.0,\"ymax\":3.0,\"zmin\":5.0,\"zmax\":7.0,\"mmin\":11.0,\"mmax\":13.0,\"spatialReference\":{\"wkid\":102100,\"latestWkid\":3857}}";
                com.fasterxml.jackson.core.JsonParser parser  = factory.CreateParser(s);
                com.epl.geometry.MapGeometry          map_env = com.epl.geometry.GeometryEngine.JsonToGeometry(parser);
                com.epl.geometry.Envelope             env     = (com.epl.geometry.Envelope)map_env.GetGeometry();
                com.epl.geometry.Envelope1D           z       = env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0);
                com.epl.geometry.Envelope1D           m       = env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.M, 0);
                NUnit.Framework.Assert.IsTrue(z.vmin == 5.0);
                NUnit.Framework.Assert.IsTrue(z.vmax == 7.0);
                NUnit.Framework.Assert.IsTrue(m.vmin == 11.0);
                NUnit.Framework.Assert.IsTrue(m.vmax == 13.0);
            }
            {
                string s = "{ \"zmin\" : 33, \"xmin\" : -109.55, \"zmax\" : 53, \"ymin\" : 25.76, \"xmax\" : -86.39, \"ymax\" : 49.94, \"mmax\" : 13}";
                com.fasterxml.jackson.core.JsonParser parser  = factory.CreateParser(s);
                com.epl.geometry.MapGeometry          map_env = com.epl.geometry.GeometryEngine.JsonToGeometry(parser);
                com.epl.geometry.Envelope             env     = (com.epl.geometry.Envelope)map_env.GetGeometry();
                com.epl.geometry.Envelope2D           e       = new com.epl.geometry.Envelope2D();
                env.QueryEnvelope2D(e);
                NUnit.Framework.Assert.IsTrue(e.xmin == -109.55 && e.ymin == 25.76 && e.xmax == -86.39 && e.ymax == 49.94);
                com.epl.geometry.Envelope1D e1D;
                NUnit.Framework.Assert.IsTrue(env.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z));
                e1D = env.QueryInterval(com.epl.geometry.VertexDescription.Semantics.Z, 0);
                NUnit.Framework.Assert.IsTrue(e1D.vmin == 33 && e1D.vmax == 53);
                NUnit.Framework.Assert.IsTrue(!env.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M));
            }
            return(bAnswer);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Inserts the element and bounding_box into the QuadTree at the given
 /// quad_handle.
 /// </summary>
 /// <remarks>
 /// Inserts the element and bounding_box into the QuadTree at the given
 /// quad_handle. Note that a copy will me made of the input bounding_box.
 /// Note that this will invalidate any active iterator on the QuadTree.
 /// Returns an Element_handle corresponding to the element and bounding_box.
 /// \param element The element of the Geometry to be inserted.
 /// \param bounding_box The bounding_box of the Geometry to be inserted.
 /// \param hint_index A handle used as a hint where to place the element. This can
 /// be a handle obtained from a previous insertion and is useful on data
 /// having strong locality such as segments of a Polygon.
 /// </remarks>
 public virtual int Insert(int element, com.epl.geometry.Envelope2D boundingBox, int hintIndex)
 {
     return(m_impl.Insert(element, boundingBox, hintIndex));
 }
Ejemplo n.º 3
0
 public override com.epl.geometry.Geometry Execute(com.epl.geometry.Geometry geom, com.epl.geometry.Envelope2D envelope, com.epl.geometry.SpatialReference spatialRef, com.epl.geometry.ProgressTracker progressTracker)
 {
     com.epl.geometry.SimpleGeometryCursor inputCursor  = new com.epl.geometry.SimpleGeometryCursor(geom);
     com.epl.geometry.GeometryCursor       outputCursor = Execute(inputCursor, envelope, spatialRef, progressTracker);
     return(outputCursor.Next());
 }
Ejemplo n.º 4
0
 public Envelope(com.epl.geometry.Envelope2D env2D)
 {
     m_description = com.epl.geometry.VertexDescriptionDesignerImpl.GetDefaultDescriptor2D();
     m_envelope.SetCoords(env2D);
     m_envelope.Normalize();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a QuadTree with the root having the extent of the input
 /// Envelope2D, and height of the input height, where the root starts at height 0.
 /// </summary>
 /// <remarks>
 /// Creates a QuadTree with the root having the extent of the input
 /// Envelope2D, and height of the input height, where the root starts at height 0.
 /// \param extent The extent of the QuadTree.
 /// \param height The max height of the QuadTree.
 /// </remarks>
 public QuadTree(com.epl.geometry.Envelope2D extent, int height)
 {
     m_impl = new com.epl.geometry.QuadTreeImpl(extent, height);
 }
Ejemplo n.º 6
0
        internal void StrokeDrawPolyPath(com.epl.geometry.SimpleRasterizer rasterizer, com.epl.geometry.MultiPathImpl polyPath, double tol)
        {
            com.epl.geometry.Point2D[] fan = new com.epl.geometry.Point2D[4];
            for (int i = 0; i < fan.Length; i++)
            {
                fan[i] = new com.epl.geometry.Point2D();
            }
            com.epl.geometry.SegmentIteratorImpl segIter = polyPath.QuerySegmentIterator();
            double strokeHalfWidth = m_transform.Transform(tol) + 1.5;
            double shortSegment    = 0.25;

            com.epl.geometry.Point2D vec        = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D vecA       = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D vecB       = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D ptStart    = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D ptEnd      = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D prev_start = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D prev_end   = new com.epl.geometry.Point2D();
            double[] helper_xy_10_elm           = new double[10];
            com.epl.geometry.Envelope2D segEnv  = new com.epl.geometry.Envelope2D();
            com.epl.geometry.Point2D    ptOld   = new com.epl.geometry.Point2D();
            while (segIter.NextPath())
            {
                bool hasFan = false;
                bool first  = true;
                ptOld.SetCoords(0, 0);
                while (segIter.HasNextSegment())
                {
                    com.epl.geometry.Segment seg = segIter.NextSegment();
                    ptStart.x = seg.GetStartX();
                    ptStart.y = seg.GetStartY();
                    ptEnd.x   = seg.GetEndX();
                    ptEnd.y   = seg.GetEndY();
                    segEnv.SetEmpty();
                    segEnv.Merge(ptStart.x, ptStart.y);
                    segEnv.MergeNE(ptEnd.x, ptEnd.y);
                    if (!m_geomEnv.IsIntersectingNE(segEnv))
                    {
                        if (hasFan)
                        {
                            rasterizer.StartAddingEdges();
                            rasterizer.AddSegmentStroke(prev_start.x, prev_start.y, prev_end.x, prev_end.y, strokeHalfWidth, false, helper_xy_10_elm);
                            rasterizer.RenderEdges(com.epl.geometry.SimpleRasterizer.EVEN_ODD);
                            hasFan = false;
                        }
                        first = true;
                        continue;
                    }
                    m_transform.Transform(ptEnd, ptEnd);
                    if (first)
                    {
                        m_transform.Transform(ptStart, ptStart);
                        ptOld.SetCoords(ptStart);
                        first = false;
                    }
                    else
                    {
                        ptStart.SetCoords(ptOld);
                    }
                    prev_start.SetCoords(ptStart);
                    prev_end.SetCoords(ptEnd);
                    rasterizer.StartAddingEdges();
                    hasFan = !rasterizer.AddSegmentStroke(prev_start.x, prev_start.y, prev_end.x, prev_end.y, strokeHalfWidth, true, helper_xy_10_elm);
                    rasterizer.RenderEdges(com.epl.geometry.SimpleRasterizer.EVEN_ODD);
                    if (!hasFan)
                    {
                        ptOld.SetCoords(prev_end);
                    }
                }
                if (hasFan)
                {
                    rasterizer.StartAddingEdges();
                    hasFan = !rasterizer.AddSegmentStroke(prev_start.x, prev_start.y, prev_end.x, prev_end.y, strokeHalfWidth, false, helper_xy_10_elm);
                    rasterizer.RenderEdges(com.epl.geometry.SimpleRasterizer.EVEN_ODD);
                }
            }
        }
Ejemplo n.º 7
0
        public override com.epl.geometry.RasterizedGeometry2D.HitType QueryEnvelopeInGeometry(com.epl.geometry.Envelope2D env)
        {
            if (!env.Intersect(m_geomEnv))
            {
                return(com.epl.geometry.RasterizedGeometry2D.HitType.Outside);
            }
            int ixmin = WorldToPixX(env.xmin);
            int ixmax = WorldToPixX(env.xmax);
            int iymin = WorldToPixY(env.ymin);
            int iymax = WorldToPixY(env.ymax);

            if (ixmin < 0)
            {
                ixmin = 0;
            }
            if (iymin < 0)
            {
                iymin = 0;
            }
            if (ixmax >= m_width)
            {
                ixmax = m_width - 1;
            }
            if (iymax >= m_width)
            {
                iymax = m_width - 1;
            }
            if (ixmin > ixmax || iymin > iymax)
            {
                return(com.epl.geometry.RasterizedGeometry2D.HitType.Outside);
            }
            int area         = System.Math.Max(ixmax - ixmin, 1) * System.Math.Max(iymax - iymin, 1);
            int iStart       = 0;
            int scanLineSize = m_scanLineSize;
            int width        = m_width;
            int res          = 0;

            while (true)
            {
                if (area < 32 || width < 16)
                {
                    for (int iy = iymin; iy <= iymax; iy++)
                    {
                        for (int ix = ixmin; ix <= ixmax; ix++)
                        {
                            int divix = ix >> 4;
                            int modix = (ix & 15) * 2;
                            res = (m_bitmap[iStart + scanLineSize * iy + divix] >> modix) & 3;
                            // read
                            // two
                            // bit
                            // color.
                            if (res > 1)
                            {
                                return(com.epl.geometry.RasterizedGeometry2D.HitType.Border);
                            }
                        }
                    }
                    if (res == 0)
                    {
                        return(com.epl.geometry.RasterizedGeometry2D.HitType.Outside);
                    }
                    else
                    {
                        if (res == 1)
                        {
                            return(com.epl.geometry.RasterizedGeometry2D.HitType.Inside);
                        }
                    }
                }
                iStart      += scanLineSize * width;
                width       /= 2;
                scanLineSize = (width * 2 + 31) / 32;
                ixmin       /= 2;
                iymin       /= 2;
                ixmax       /= 2;
                iymax       /= 2;
                area         = System.Math.Max(ixmax - ixmin, 1) * System.Math.Max(iymax - iymin, 1);
            }
        }
 // GEOMTHROW(internal_error);
 // //what else
 // return 0;
 private static int QuickTest2DPolygonEnvelope(com.epl.geometry.Polygon geomA, com.epl.geometry.Envelope geomB, double tolerance)
 {
     com.epl.geometry.Envelope2D geomBEnv = new com.epl.geometry.Envelope2D();
     geomB.QueryEnvelope2D(geomBEnv);
     return(QuickTest2DPolygonEnvelope(geomA, geomBEnv, tolerance));
 }
        private static int QuickTest2DPolygonEnvelope(com.epl.geometry.Polygon geomA, com.epl.geometry.Envelope2D geomBEnv, double tolerance)
        {
            int res = QuickTest2DMVEnvelopeRasterOnly(geomA, geomBEnv, tolerance);

            if (res > 0)
            {
                return(res);
            }
            // TODO: implement me
            return(0);
        }
        private static int QuickTest2DMultiPointEnvelope(com.epl.geometry.MultiPoint geomA, com.epl.geometry.Envelope2D geomBEnv, double tolerance, int testType)
        {
            // Add early bailout for disjoint test.
            com.epl.geometry.Envelope2D envBMinus = geomBEnv;
            envBMinus.Inflate(-tolerance, -tolerance);
            com.epl.geometry.Envelope2D envBPlus = geomBEnv;
            envBPlus.Inflate(tolerance, tolerance);
            int dres = 0;

            for (int i = 0, n = geomA.GetPointCount(); i < n; i++)
            {
                com.epl.geometry.Point2D ptA;
                ptA = geomA.GetXY(i);
                int res = ReverseResult(QuickTest2DEnvelopePoint(envBPlus, envBMinus, ptA, tolerance));
                if (res != (int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint)
                {
                    dres |= res;
                    if (testType == (int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint)
                    {
                        return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Intersects);
                    }
                }
            }
            if (dres == 0)
            {
                return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
            }
            if (dres == (int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Within)
            {
                return(dres);
            }
            return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Overlaps);
        }
 private static int QuickTest2DMVEnvelopeRasterOnly(com.epl.geometry.MultiVertexGeometry geomA, com.epl.geometry.Envelope2D geomBEnv, double tolerance)
 {
     // Use rasterized Geometry only:
     com.epl.geometry.RasterizedGeometry2D    rgeomA;
     com.epl.geometry.MultiVertexGeometryImpl mpImpl = (com.epl.geometry.MultiVertexGeometryImpl)geomA._getImpl();
     com.epl.geometry.GeometryAccelerators    gaccel = mpImpl._getAccelerators();
     if (gaccel != null)
     {
         rgeomA = gaccel.GetRasterizedGeometry();
     }
     else
     {
         return(-1);
     }
     if (rgeomA != null)
     {
         com.epl.geometry.RasterizedGeometry2D.HitType hitres = rgeomA.QueryEnvelopeInGeometry(geomBEnv);
         if (hitres == com.epl.geometry.RasterizedGeometry2D.HitType.Outside)
         {
             return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
         }
         if (hitres == com.epl.geometry.RasterizedGeometry2D.HitType.Inside)
         {
             return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Contains);
         }
     }
     else
     {
         return(-1);
     }
     return(0);
 }
 private static int QuickTest2DMultiPointEnvelope(com.epl.geometry.MultiPoint geomA, com.epl.geometry.Envelope geomB, double tolerance, int testType)
 {
     com.epl.geometry.Envelope2D geomBEnv = new com.epl.geometry.Envelope2D();
     geomB.QueryEnvelope2D(geomBEnv);
     return(QuickTest2DMultiPointEnvelope(geomA, geomBEnv, tolerance, testType));
 }
        private static int QuickTest2DEnvelopeEnvelope(com.epl.geometry.Envelope2D geomAEnv, com.epl.geometry.Envelope2D geomBEnv, double tolerance)
        {
            // firstly check for contains and within to give a chance degenerate
            // envelopes to work.
            // otherwise, if there are two degenerate envelopes that are equal,
            // Touch relation may occur.
            int res = 0;

            if (geomAEnv.Contains(geomBEnv))
            {
                res |= (int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Contains;
            }
            if (geomBEnv.Contains(geomAEnv))
            {
                res |= (int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Within;
            }
            if (res != 0)
            {
                return(res);
            }
            com.epl.geometry.Envelope2D envAMinus = geomAEnv;
            envAMinus.Inflate(-tolerance, -tolerance);
            // Envelope A interior
            com.epl.geometry.Envelope2D envBMinus = geomBEnv;
            envBMinus.Inflate(-tolerance, -tolerance);
            // Envelope B interior
            if (envAMinus.IsIntersecting(envBMinus))
            {
                com.epl.geometry.Envelope2D envAPlus = geomAEnv;
                envAPlus.Inflate(tolerance, tolerance);
                // Envelope A interior plus
                // boundary
                res = envAPlus.Contains(geomBEnv) ? (int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Contains : 0;
                com.epl.geometry.Envelope2D envBPlus = geomBEnv;
                envBPlus.Inflate(tolerance, tolerance);
                // Envelope A interior plus
                // boundary
                res |= envBPlus.Contains(geomAEnv) ? (int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Within : 0;
                if (res != 0)
                {
                    return(res);
                }
                return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Overlaps);
            }
            else
            {
                // Clementini's Overlap
                com.epl.geometry.Envelope2D envAPlus = geomAEnv;
                envAPlus.Inflate(tolerance, tolerance);
                // Envelope A interior plus
                // boundary
                com.epl.geometry.Envelope2D envBPlus = geomBEnv;
                envBPlus.Inflate(tolerance, tolerance);
                // Envelope A interior plus
                // boundary
                if (envAPlus.IsIntersecting(envBPlus))
                {
                    return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Touches);
                }
                else
                {
                    // Clementini Touch
                    return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
                }
            }
        }
 // clementini's disjoint
 private static int QuickTest2DEnvelopePoint(com.epl.geometry.Envelope2D envAPlus, com.epl.geometry.Envelope2D envAMinus, com.epl.geometry.Point2D ptB, double tolerance)
 {
     if (envAMinus.Contains(ptB))
     {
         return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Contains);
     }
     // clementini's contains
     if (envAPlus.Contains(ptB))
     {
         return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Touches);
     }
     // clementini's touches
     return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
 }
Ejemplo n.º 15
0
        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 int QuickTest2D_Accelerated_DisjointOrContains(com.epl.geometry.Geometry geomA, com.epl.geometry.Geometry geomB, double tolerance)
        {
            int gtA = geomA.GetType().Value();
            int gtB = geomB.GetType().Value();

            com.epl.geometry.GeometryAccelerators accel;
            bool endWhileStatement = false;

            do
            {
                if (com.epl.geometry.Geometry.IsMultiVertex(gtA))
                {
                    com.epl.geometry.MultiVertexGeometryImpl impl = (com.epl.geometry.MultiVertexGeometryImpl)geomA._getImpl();
                    accel = impl._getAccelerators();
                    if (accel != null)
                    {
                        com.epl.geometry.RasterizedGeometry2D rgeom = accel.GetRasterizedGeometry();
                        if (rgeom != null)
                        {
                            if (gtB == com.epl.geometry.Geometry.GeometryType.Point)
                            {
                                com.epl.geometry.Point2D ptB = ((com.epl.geometry.Point)geomB).GetXY();
                                com.epl.geometry.RasterizedGeometry2D.HitType hit = rgeom.QueryPointInGeometry(ptB.x, ptB.y);
                                if (hit == com.epl.geometry.RasterizedGeometry2D.HitType.Inside)
                                {
                                    return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Contains);
                                }
                                else
                                {
                                    if (hit == com.epl.geometry.RasterizedGeometry2D.HitType.Outside)
                                    {
                                        return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
                                    }
                                }
                                break;
                            }
                            com.epl.geometry.Envelope2D envB = new com.epl.geometry.Envelope2D();
                            geomB.QueryEnvelope2D(envB);
                            com.epl.geometry.RasterizedGeometry2D.HitType hit_1 = rgeom.QueryEnvelopeInGeometry(envB);
                            if (hit_1 == com.epl.geometry.RasterizedGeometry2D.HitType.Inside)
                            {
                                return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Contains);
                            }
                            else
                            {
                                if (hit_1 == com.epl.geometry.RasterizedGeometry2D.HitType.Outside)
                                {
                                    return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
                                }
                            }
                            break;
                        }
                    }
                }
            }while (endWhileStatement);
            accel = null;
            do
            {
                if (com.epl.geometry.Geometry.IsMultiVertex(gtB))
                {
                    com.epl.geometry.MultiVertexGeometryImpl impl = (com.epl.geometry.MultiVertexGeometryImpl)geomB._getImpl();
                    accel = impl._getAccelerators();
                    if (accel != null)
                    {
                        com.epl.geometry.RasterizedGeometry2D rgeom = accel.GetRasterizedGeometry();
                        if (rgeom != null)
                        {
                            if (gtA == com.epl.geometry.Geometry.GeometryType.Point)
                            {
                                com.epl.geometry.Point2D ptA = ((com.epl.geometry.Point)geomA).GetXY();
                                com.epl.geometry.RasterizedGeometry2D.HitType hit = rgeom.QueryPointInGeometry(ptA.x, ptA.y);
                                if (hit == com.epl.geometry.RasterizedGeometry2D.HitType.Inside)
                                {
                                    return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Within);
                                }
                                else
                                {
                                    if (hit == com.epl.geometry.RasterizedGeometry2D.HitType.Outside)
                                    {
                                        return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
                                    }
                                }
                                break;
                            }
                            com.epl.geometry.Envelope2D envA = new com.epl.geometry.Envelope2D();
                            geomA.QueryEnvelope2D(envA);
                            com.epl.geometry.RasterizedGeometry2D.HitType hit_1 = rgeom.QueryEnvelopeInGeometry(envA);
                            if (hit_1 == com.epl.geometry.RasterizedGeometry2D.HitType.Inside)
                            {
                                return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Within);
                            }
                            else
                            {
                                if (hit_1 == com.epl.geometry.RasterizedGeometry2D.HitType.Outside)
                                {
                                    return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
                                }
                            }
                            break;
                        }
                    }
                }
            }while (endWhileStatement);
            return(0);
        }
Ejemplo n.º 17
0
 internal void FillEnvelope(com.epl.geometry.SimpleRasterizer rasterizer, com.epl.geometry.Envelope2D envIn)
 {
     rasterizer.FillEnvelope(envIn);
 }
Ejemplo n.º 18
0
 /// <summary>Returns true if the quad tree has data intersecting the given query.</summary>
 /// <remarks>
 /// Returns true if the quad tree has data intersecting the given query.
 /// \param query The Envelope2D used for the query.
 /// \param tolerance The tolerance used for the intersection tests.
 /// </remarks>
 public virtual bool HasData(com.epl.geometry.Envelope2D query, double tolerance)
 {
     return(m_impl.HasData(query, tolerance));
 }
Ejemplo n.º 19
0
        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();
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Gets an iterator on the QuadTree using the input Envelope2D as the
 /// query.
 /// </summary>
 /// <remarks>
 /// Gets an iterator on the QuadTree using the input Envelope2D as the
 /// query. To reuse the existing iterator on the same QuadTree but with a
 /// new query, use the reset_iterator function on the QuadTree_iterator.
 /// \param query The Envelope2D used for the query.
 /// \param tolerance The tolerance used for the intersection tests.
 /// </remarks>
 public virtual com.epl.geometry.QuadTree.QuadTreeIterator GetIterator(com.epl.geometry.Envelope2D query, double tolerance)
 {
     com.epl.geometry.QuadTreeImpl.QuadTreeIteratorImpl iterator = m_impl.GetIterator(query, tolerance);
     return(new com.epl.geometry.QuadTree.QuadTreeIterator(iterator, false));
 }
Ejemplo n.º 21
0
 public virtual void Merge(com.epl.geometry.Envelope2D other)
 {
     _touch();
     m_envelope.Merge(other);
 }
Ejemplo n.º 22
0
 public override void QueryEnvelope2D(com.epl.geometry.Envelope2D env)
 {
     m_impl.QueryEnvelope2D(env);
 }
Ejemplo n.º 23
0
 public virtual bool IsIntersecting(com.epl.geometry.Envelope2D other)
 {
     return(m_envelope.IsIntersecting(other));
 }
Ejemplo n.º 24
0
        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));
        }
Ejemplo n.º 25
0
 /// <summary>Creates a QuadTree with the root having the extent of the input Envelope2D, and height of the input height, where the root starts at height 0.</summary>
 /// <remarks>
 /// Creates a QuadTree with the root having the extent of the input Envelope2D, and height of the input height, where the root starts at height 0.
 /// \param extent The extent of the QuadTreeImpl.
 /// \param height The max height of the QuadTreeImpl.
 /// \param bStoreDuplicates Put true to place elements deeper into the quad tree at intesecting quads, duplicates will be stored. Put false to only place elements into quads that can contain it..
 /// </remarks>
 public QuadTree(com.epl.geometry.Envelope2D extent, int height, bool bStoreDuplicates)
 {
     m_impl = new com.epl.geometry.QuadTreeImpl(extent, height, bStoreDuplicates);
 }
Ejemplo n.º 26
0
        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());
            }
        }
Ejemplo n.º 27
0
 /// <summary>Returns the number of elements in the quad tree that intersect the qiven query.</summary>
 /// <remarks>
 /// Returns the number of elements in the quad tree that intersect the qiven query. Some elements may be duplicated if the quad tree stores duplicates.
 /// \param query The Envelope2D used for the query.
 /// \param tolerance The tolerance used for the intersection tests.
 /// \param max_count If the intersection count becomes greater than or equal to the max_count, then max_count is returned.
 /// </remarks>
 public virtual int GetIntersectionCount(com.epl.geometry.Envelope2D query, double tolerance, int maxCount)
 {
     return(m_impl.GetIntersectionCount(query, tolerance, maxCount));
 }
Ejemplo n.º 28
0
 public override com.epl.geometry.GeometryCursor Execute(com.epl.geometry.GeometryCursor geoms, com.epl.geometry.Envelope2D envelope, com.epl.geometry.SpatialReference spatialRef, com.epl.geometry.ProgressTracker progressTracker)
 {
     return(new com.epl.geometry.OperatorClipCursor(geoms, envelope, spatialRef, progressTracker));
 }