Пример #1
0
        public virtual void TestBufferPoint()
        {
            com.epl.geometry.SpatialReference sr        = com.epl.geometry.SpatialReference.Create(4326);
            com.epl.geometry.Point            inputGeom = new com.epl.geometry.Point(12, 120);
            com.epl.geometry.OperatorBuffer   buffer    = (com.epl.geometry.OperatorBuffer)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Buffer);
            com.epl.geometry.OperatorSimplify simplify  = (com.epl.geometry.OperatorSimplify)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Simplify);
            com.epl.geometry.Geometry         result    = buffer.Execute(inputGeom, sr, 40.0, null);
            NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon);
            com.epl.geometry.Polygon poly = (com.epl.geometry.Polygon)result;
            int pathCount = poly.GetPathCount();

            NUnit.Framework.Assert.IsTrue(pathCount == 1);
            int pointCount = poly.GetPointCount();

            NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 100.0) < 10);
            com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D();
            result.QueryEnvelope2D(env2D);
            NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 80) < 0.01 && System.Math.Abs(env2D.GetHeight() - 80) < 0.01);
            NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 12) < 0.001 && System.Math.Abs(env2D.GetCenterY() - 120) < 0.001);
            com.epl.geometry.NonSimpleResult nsr = new com.epl.geometry.NonSimpleResult();
            bool is_simple = simplify.IsSimpleAsFeature(result, sr, true, nsr, null);

            NUnit.Framework.Assert.IsTrue(is_simple);
            {
                result = buffer.Execute(inputGeom, sr, 0, null);
                NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon);
                NUnit.Framework.Assert.IsTrue(result.IsEmpty());
            }
            {
                result = buffer.Execute(inputGeom, sr, -1, null);
                NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon);
                NUnit.Framework.Assert.IsTrue(result.IsEmpty());
            }
        }
Пример #2
0
        internal static com.epl.geometry.Geometry Calculate(com.epl.geometry.Geometry geom, com.epl.geometry.ProgressTracker progress_tracker)
        {
            int gt = geom.GetType().Value();

            if (gt == com.epl.geometry.Geometry.GeometryType.Polygon)
            {
                com.epl.geometry.Polyline dst = new com.epl.geometry.Polyline(geom.GetDescription());
                if (!geom.IsEmpty())
                {
                    ((com.epl.geometry.MultiPathImpl)geom._getImpl())._copyToUnsafe((com.epl.geometry.MultiPathImpl)dst._getImpl());
                }
                return(dst);
            }
            else
            {
                if (gt == com.epl.geometry.Geometry.GeometryType.Polyline)
                {
                    return(CalculatePolylineBoundary_(geom._getImpl(), progress_tracker, false, null));
                }
                else
                {
                    if (gt == com.epl.geometry.Geometry.GeometryType.Envelope)
                    {
                        com.epl.geometry.Polyline dst = new com.epl.geometry.Polyline(geom.GetDescription());
                        if (!geom.IsEmpty())
                        {
                            dst.AddEnvelope((com.epl.geometry.Envelope)geom, false);
                        }
                        return(dst);
                    }
                    else
                    {
                        if (com.epl.geometry.Geometry.IsSegment(gt))
                        {
                            com.epl.geometry.MultiPoint mp = new com.epl.geometry.MultiPoint(geom.GetDescription());
                            if (!geom.IsEmpty() && !((com.epl.geometry.Segment)geom).IsClosed())
                            {
                                com.epl.geometry.Point pt = new com.epl.geometry.Point();
                                ((com.epl.geometry.Segment)geom).QueryStart(pt);
                                mp.Add(pt);
                                ((com.epl.geometry.Segment)geom).QueryEnd(pt);
                                mp.Add(pt);
                            }
                            return(mp);
                        }
                        else
                        {
                            if (com.epl.geometry.Geometry.IsPoint(gt))
                            {
                                // returns empty point for points and multipoints.
                                return(null);
                            }
                        }
                    }
                }
            }
            throw new System.ArgumentException();
        }
 private com.epl.geometry.Geometry Generalize(com.epl.geometry.Geometry geom)
 {
     com.epl.geometry.Geometry.Type gt = geom.GetType();
     if (com.epl.geometry.Geometry.IsPoint(gt.Value()))
     {
         return(geom);
     }
     if (gt == com.epl.geometry.Geometry.Type.Envelope)
     {
         com.epl.geometry.Polygon poly = new com.epl.geometry.Polygon(geom.GetDescription());
         poly.AddEnvelope((com.epl.geometry.Envelope)geom, false);
         return(Generalize(poly));
     }
     if (geom.IsEmpty())
     {
         return(geom);
     }
     com.epl.geometry.MultiPath mp    = (com.epl.geometry.MultiPath)geom;
     com.epl.geometry.MultiPath dstmp = (com.epl.geometry.MultiPath)geom.CreateInstance();
     com.epl.geometry.Line      line  = new com.epl.geometry.Line();
     for (int ipath = 0, npath = mp.GetPathCount(); ipath < npath; ipath++)
     {
         GeneralizePath((com.epl.geometry.MultiPathImpl)mp._getImpl(), ipath, (com.epl.geometry.MultiPathImpl)dstmp._getImpl(), line);
     }
     return(dstmp);
 }
        public virtual void TestWKB2()
        {
            // JSON -> GEOM -> WKB
            // String strPolygon1 =
            // "{\"xmin\":-1.16605115291E7,\"ymin\":4925189.941699997,\"xmax\":-1.16567772126E7,\"ymax\":4928658.771399997,\"spatialReference\":{\"wkid\":102100}}";
            string strPolygon1 = "{\"rings\" : [ [ [-1.16605115291E7,4925189.941699997], [-1.16567772126E7,4925189.941699997], [-1.16567772126E7,4928658.771399997], [-1.16605115291E7,4928658.771399997], [-1.16605115291E7,4925189.941699997] ] ], \"spatialReference\" : {\"wkid\" : 102100}}";

            com.epl.geometry.MapGeometry mapGeom = com.epl.geometry.GeometryEngine.JsonToGeometry(strPolygon1);
            com.epl.geometry.Geometry    geom    = mapGeom.GetGeometry();
            // simplifying geom
            com.epl.geometry.OperatorSimplify operatorSimplify = (com.epl.geometry.OperatorSimplify)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Simplify);
            com.epl.geometry.SpatialReference sr = com.epl.geometry.SpatialReference.Create(102100);
            geom = operatorSimplify.Execute(geom, sr, true, null);
            com.epl.geometry.OperatorExportToWkb operatorExport = (com.epl.geometry.OperatorExportToWkb)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.ExportToWkb);
            System.IO.MemoryStream byteBuffer = operatorExport.Execute(0, geom, null);
            byte[] wkb = ((byte[])byteBuffer.Array());
            // // checking WKB correctness
            // WKBReader jtsReader = new WKBReader();
            // com.vividsolutions.jts.geom.Geometry jtsGeom = jtsReader.read(wkb);
            // System.out.println("jtsGeom = " + jtsGeom);
            // WKB -> GEOM -> JSON
            com.epl.geometry.OperatorImportFromWkb operatorImport = (com.epl.geometry.OperatorImportFromWkb)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.ImportFromWkb);
            geom = operatorImport.Execute(0, com.epl.geometry.Geometry.Type.Polygon, System.IO.MemoryStream.Wrap(wkb), null);
            NUnit.Framework.Assert.IsTrue(!geom.IsEmpty());
        }
Пример #5
0
 /// <exception cref="java.io.ObjectStreamException"/>
 internal object ReadResolve()
 {
     com.epl.geometry.Geometry geometry = null;
     try
     {
         geometry = com.epl.geometry.GeometryEngine.GeometryFromEsriShape(geometryData.esriShape, geometryData.geometryType);
         if (com.epl.geometry.Geometry.IsMultiVertex(geometry.GetType().Value()))
         {
             com.epl.geometry.GeometrySerializer.MultiVertexData mvd    = (com.epl.geometry.GeometrySerializer.MultiVertexData)geometryData;
             com.epl.geometry.MultiVertexGeometryImpl            mvImpl = (com.epl.geometry.MultiVertexGeometryImpl)geometry._getImpl();
             if (!geometry.IsEmpty() && com.epl.geometry.Geometry.IsMultiPath(geometry.GetType().Value()))
             {
                 com.epl.geometry.GeometrySerializer.MultiPathData mpd = (com.epl.geometry.GeometrySerializer.MultiPathData)geometryData;
                 com.epl.geometry.MultiPathImpl         mpImpl         = (com.epl.geometry.MultiPathImpl)geometry._getImpl();
                 com.epl.geometry.AttributeStreamOfInt8 pathFlags      = mpImpl.GetPathFlagsStreamRef();
                 for (int i = 0, n = mpImpl.GetPathCount(); i < n; i++)
                 {
                     if (mpd.ogcFlags[i])
                     {
                         pathFlags.SetBits(i, unchecked ((byte)com.epl.geometry.PathFlags.enumOGCStartPolygon));
                     }
                 }
             }
             mvImpl.SetIsSimple(mvd.simpleFlag, mvd.tolerance, false);
         }
     }
     catch (System.Exception)
     {
         throw new System.IO.InvalidDataException("Cannot read geometry from stream");
     }
     return(geometry);
 }
Пример #6
0
//		/// <exception cref="java.io.ObjectStreamException"/>
//		internal virtual object WriteReplace()
//		{
//			com.epl.geometry.Geometry.Type gt = GetType();
//			if (gt == com.epl.geometry.Geometry.Type.Point)
//			{
//				com.epl.geometry.PtSrlzr pt = new com.epl.geometry.PtSrlzr();
//				pt.SetGeometryByValue((com.epl.geometry.Point)this);
//				return pt;
//			}
//			else
//			{
//				if (gt == com.epl.geometry.Geometry.Type.Envelope)
//				{
//					com.epl.geometry.EnvSrlzr e = new com.epl.geometry.EnvSrlzr();
//					e.SetGeometryByValue((com.epl.geometry.Envelope)this);
//					return e;
//				}
//				else
//				{
//					if (gt == com.epl.geometry.Geometry.Type.Line)
//					{
//						com.epl.geometry.LnSrlzr ln = new com.epl.geometry.LnSrlzr();
//						ln.SetGeometryByValue((com.epl.geometry.Line)this);
//						return ln;
//					}
//				}
//			}
//			com.epl.geometry.GenericGeometrySerializer geomSerializer = new com.epl.geometry.GenericGeometrySerializer();
//			geomSerializer.SetGeometryByValue(this);
//			return geomSerializer;
//		}
//
//		/// <summary>The output of this method can be only used for debugging.</summary>
//		/// <remarks>The output of this method can be only used for debugging. It is subject to change without notice.</remarks>
//		public override string ToString()
//		{
//			string snippet = com.epl.geometry.OperatorExportToJson.Local().Execute(null, this);
//			if (snippet.Length > 200)
//			{
//				return snippet.Substring(0, 197 - 0) + "... (" + snippet.Length + " characters)";
//			}
//			else
//			{
//				return snippet;
//			}
//		}

        /// <summary>
        /// Returns count of geometry vertices:
        /// 1 for Point, 4 for Envelope, get_point_count for MultiVertexGeometry types,
        /// 2 for segment types
        /// Returns 0 if geometry is empty.
        /// </summary>
        public static int Vertex_count(com.epl.geometry.Geometry geom)
        {
            com.epl.geometry.Geometry.Type gt = geom.GetType();
            if (com.epl.geometry.Geometry.IsMultiVertex(gt.Value()))
            {
                return(((com.epl.geometry.MultiVertexGeometry)geom).GetPointCount());
            }
            if (geom.IsEmpty())
            {
                return(0);
            }
            if (gt == com.epl.geometry.Geometry.Type.Envelope)
            {
                return(4);
            }
            if (gt == com.epl.geometry.Geometry.Type.Point)
            {
                return(1);
            }
            if (com.epl.geometry.Geometry.IsSegment(gt.Value()))
            {
                return(2);
            }
            throw new com.epl.geometry.GeometryException("missing type");
        }
        public virtual void TestMultiPointAndMultiPoint3()
        {
            com.epl.geometry.MultiPoint basePl = new com.epl.geometry.MultiPoint();
            basePl.Add(new com.epl.geometry.Point(-116, 21));
            basePl.Add(new com.epl.geometry.Point(-117, 20));
            com.epl.geometry.MultiPoint compPl = new com.epl.geometry.MultiPoint();
            compPl.Add(new com.epl.geometry.Point(-116, 20));
            compPl.Add(new com.epl.geometry.Point(-117, 21));
            compPl.Add(new com.epl.geometry.Point(-118, 20));
            compPl.Add(new com.epl.geometry.Point(-119, 21));
            int noException = 1;

            // no exception
            com.epl.geometry.Geometry intersectGeom = null;
            try
            {
                intersectGeom = com.epl.geometry.GeometryEngine.Intersect(basePl, compPl, com.epl.geometry.SpatialReference.Create(4326));
            }
            catch (System.Exception)
            {
                noException = 0;
            }
            NUnit.Framework.Assert.AreEqual(noException, 1);
            NUnit.Framework.Assert.IsTrue(intersectGeom.IsEmpty());
        }
Пример #8
0
 public static com.epl.geometry.ogc.OGCGeometry CreateFromEsriCursor(com.epl.geometry.GeometryCursor gc, com.epl.geometry.SpatialReference sr, bool skipEmpty)
 {
     System.Collections.Generic.List <com.epl.geometry.ogc.OGCGeometry> geoms = new System.Collections.Generic.List <com.epl.geometry.ogc.OGCGeometry>(10);
     com.epl.geometry.Geometry emptyGeom = null;
     for (com.epl.geometry.Geometry g = gc.Next(); g != null; g = gc.Next())
     {
         emptyGeom = g;
         if (!skipEmpty || !g.IsEmpty())
         {
             geoms.Add(CreateFromEsriGeometry(g, sr));
         }
     }
     if (geoms.Count == 1)
     {
         return(geoms[0]);
     }
     else
     {
         if (geoms.Count == 0)
         {
             return(CreateFromEsriGeometry(emptyGeom, sr));
         }
         else
         {
             return(new com.epl.geometry.ogc.OGCConcreteGeometryCollection(geoms, sr));
         }
     }
 }
Пример #9
0
 /// <exception cref="java.io.ObjectStreamException"/>
 public virtual void SetGeometryByValue(com.epl.geometry.Geometry geometry)
 {
     try
     {
         esriShape    = com.epl.geometry.GeometryEngine.GeometryToEsriShape(geometry);
         geometryType = geometry.GetType().Value();
         if (com.epl.geometry.Geometry.IsMultiVertex(geometryType))
         {
             com.epl.geometry.MultiVertexGeometryImpl mvImpl = (com.epl.geometry.MultiVertexGeometryImpl)geometry._getImpl();
             tolerance  = mvImpl.m_simpleTolerance;
             simpleFlag = mvImpl.GetIsSimple(0);
             if (!geometry.IsEmpty() && com.epl.geometry.Geometry.IsMultiPath(geometryType))
             {
                 com.epl.geometry.MultiPathImpl mpImpl = (com.epl.geometry.MultiPathImpl)geometry._getImpl();
                 ogcFlags = new bool[mpImpl.GetPathCount()];
                 com.epl.geometry.AttributeStreamOfInt8 pathFlags = mpImpl.GetPathFlagsStreamRef();
                 for (int i = 0, n = mpImpl.GetPathCount(); i < n; i++)
                 {
                     ogcFlags[i] = (pathFlags.Read(i) & unchecked ((byte)com.epl.geometry.PathFlags.enumOGCStartPolygon)) != 0;
                 }
             }
         }
     }
     catch (System.Exception)
     {
         throw new System.IO.InvalidDataException("Cannot serialize this geometry");
     }
 }
        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));
        }
 /// <summary>
 /// Checks whether the RasterizedGeometry2D accelerator can be used with the
 /// given geometry.
 /// </summary>
 internal static bool CanUseAccelerator(com.epl.geometry.Geometry geom)
 {
     if (geom.IsEmpty() || !(geom.GetType() == com.epl.geometry.Geometry.Type.Polyline || geom.GetType() == com.epl.geometry.Geometry.Type.Polygon))
     {
         return(false);
     }
     return(true);
 }
Пример #12
0
 internal virtual double Calculate(com.epl.geometry.Geometry geometryA, com.epl.geometry.Geometry geometryB)
 {
     /* const */
     /* const */
     if (geometryA.IsEmpty() || geometryB.IsEmpty())
     {
         return(com.epl.geometry.NumberUtils.TheNaN);
     }
     geometryA.QueryEnvelope2D(this.m_env2DgeometryA);
     geometryB.QueryEnvelope2D(this.m_env2DgeometryB);
     return(this.ExecuteBruteForce_(geometryA, geometryB));
 }
Пример #13
0
 internal static bool CanUseQuadTreeForPaths(com.epl.geometry.Geometry geom)
 {
     if (geom.IsEmpty() || !(geom.GetType() == com.epl.geometry.Geometry.Type.Polyline || geom.GetType() == com.epl.geometry.Geometry.Type.Polygon))
     {
         return(false);
     }
     if (((com.epl.geometry.MultiVertexGeometry)geom).GetPointCount() < 20)
     {
         return(false);
     }
     return(true);
 }
Пример #14
0
 internal static bool HasNonEmptyBoundary(com.epl.geometry.Geometry geom, com.epl.geometry.ProgressTracker progress_tracker)
 {
     if (geom.IsEmpty())
     {
         return(false);
     }
     com.epl.geometry.Geometry.Type gt = geom.GetType();
     if (gt == com.epl.geometry.Geometry.Type.Polygon)
     {
         if (geom.CalculateArea2D() == 0)
         {
             return(false);
         }
         return(true);
     }
     else
     {
         if (gt == com.epl.geometry.Geometry.Type.Polyline)
         {
             bool[] b = new bool[1];
             b[0] = false;
             CalculatePolylineBoundary_(geom._getImpl(), progress_tracker, true, b);
             return(b[0]);
         }
         else
         {
             if (gt == com.epl.geometry.Geometry.Type.Envelope)
             {
                 return(true);
             }
             else
             {
                 if (com.epl.geometry.Geometry.IsSegment(gt.Value()))
                 {
                     if (!((com.epl.geometry.Segment)geom).IsClosed())
                     {
                         return(true);
                     }
                     return(false);
                 }
                 else
                 {
                     if (com.epl.geometry.Geometry.IsPoint(gt.Value()))
                     {
                         return(false);
                     }
                 }
             }
         }
     }
     return(false);
 }
        private com.epl.geometry.Geometry DensifyByLength(com.epl.geometry.Geometry geom)
        {
            if (geom.IsEmpty() || geom.GetDimension() < 1)
            {
                return(geom);
            }
            int geometryType = geom.GetType().Value();

            // TODO implement IsMultiPath and remove Polygon and Polyline call to
            // match Native
            // if (Geometry.IsMultiPath(geometryType))
            if (geometryType == com.epl.geometry.Geometry.GeometryType.Polygon)
            {
                return(DensifyMultiPath((com.epl.geometry.MultiPath)geom));
            }
            else
            {
                if (com.epl.geometry.Geometry.GeometryType.Polyline == geometryType)
                {
                    return(DensifyMultiPath((com.epl.geometry.MultiPath)geom));
                }
                else
                {
                    if (com.epl.geometry.Geometry.IsSegment(geometryType))
                    {
                        return(DensifySegment((com.epl.geometry.Segment)geom));
                    }
                    else
                    {
                        if (geometryType == com.epl.geometry.Geometry.GeometryType.Envelope)
                        {
                            return(DensifyEnvelope((com.epl.geometry.Envelope)geom));
                        }
                        else
                        {
                            // TODO fix geometry exception to match native implementation
                            throw com.epl.geometry.GeometryException.GeometryInternalError();
                        }
                    }
                }
            }
        }
Пример #16
0
		internal virtual com.epl.geometry.Geometry NormalizeIntersectionOutput(com.epl.geometry.Geometry geom, int GT_1, int GT_2)
		{
			if (GT_1 == com.epl.geometry.Geometry.GeometryType.Point || GT_2 == com.epl.geometry.Geometry.GeometryType.Point)
			{
				System.Diagnostics.Debug.Assert((geom.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Point));
			}
			if (GT_1 == com.epl.geometry.Geometry.GeometryType.MultiPoint)
			{
				if (geom.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Point)
				{
					com.epl.geometry.MultiPoint mp = new com.epl.geometry.MultiPoint(geom.GetDescription());
					if (!geom.IsEmpty())
					{
						mp.Add((com.epl.geometry.Point)geom);
					}
					return mp;
				}
			}
			return geom;
		}
Пример #17
0
        public override com.epl.geometry.Proximity2DResult[] GetNearestVertices(com.epl.geometry.Geometry geom, com.epl.geometry.Point inputPoint, double searchRadius, int maxVertexCountToReturn)
        {
            if (maxVertexCountToReturn < 0)
            {
                throw new System.ArgumentException();
            }
            if (geom.IsEmpty())
            {
                return(new com.epl.geometry.Proximity2DResult[] {  });
            }
            com.epl.geometry.Point2D  inputPoint2D     = inputPoint.GetXY();
            com.epl.geometry.Geometry proxmityTestGeom = geom;
            int gt = geom.GetType().Value();

            if (gt == com.epl.geometry.Geometry.GeometryType.Envelope)
            {
                com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon();
                polygon.AddEnvelope((com.epl.geometry.Envelope)geom, false);
                proxmityTestGeom = polygon;
                gt = com.epl.geometry.Geometry.GeometryType.Polygon;
            }
            switch (gt)
            {
            case com.epl.geometry.Geometry.GeometryType.Point:
            {
                return(PointGetNearestVertices((com.epl.geometry.Point)proxmityTestGeom, inputPoint2D, searchRadius, maxVertexCountToReturn));
            }

            case com.epl.geometry.Geometry.GeometryType.MultiPoint:
            case com.epl.geometry.Geometry.GeometryType.Polyline:
            case com.epl.geometry.Geometry.GeometryType.Polygon:
            {
                return(MultiVertexGetNearestVertices((com.epl.geometry.MultiVertexGeometry)proxmityTestGeom, inputPoint2D, searchRadius, maxVertexCountToReturn));
            }

            default:
            {
                throw new com.epl.geometry.GeometryException("not implemented");
            }
            }
        }
Пример #18
0
        public override com.epl.geometry.Proximity2DResult GetNearestCoordinate(com.epl.geometry.Geometry geom, com.epl.geometry.Point inputPoint, bool bTestPolygonInterior, bool bCalculateLeftRightSide)
        {
            if (geom.IsEmpty())
            {
                return(new com.epl.geometry.Proximity2DResult());
            }
            com.epl.geometry.Point2D  inputPoint2D     = inputPoint.GetXY();
            com.epl.geometry.Geometry proxmityTestGeom = geom;
            int gt = geom.GetType().Value();

            if (gt == com.epl.geometry.Geometry.GeometryType.Envelope)
            {
                com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon();
                polygon.AddEnvelope((com.epl.geometry.Envelope)geom, false);
                proxmityTestGeom = polygon;
                gt = com.epl.geometry.Geometry.GeometryType.Polygon;
            }
            switch (gt)
            {
            case com.epl.geometry.Geometry.GeometryType.Point:
            {
                return(PointGetNearestVertex((com.epl.geometry.Point)proxmityTestGeom, inputPoint2D));
            }

            case com.epl.geometry.Geometry.GeometryType.MultiPoint:
            {
                return(MultiVertexGetNearestVertex((com.epl.geometry.MultiVertexGeometry)proxmityTestGeom, inputPoint2D));
            }

            case com.epl.geometry.Geometry.GeometryType.Polyline:
            case com.epl.geometry.Geometry.GeometryType.Polygon:
            {
                return(MultiPathGetNearestCoordinate((com.epl.geometry.MultiPath)proxmityTestGeom, inputPoint2D, bTestPolygonInterior, bCalculateLeftRightSide));
            }

            default:
            {
                throw new com.epl.geometry.GeometryException("not implemented");
            }
            }
        }
Пример #19
0
        public virtual void TestPointAndPolygon2()
        {
            com.epl.geometry.Point   basePl = new com.epl.geometry.Point(-115, 20);
            com.epl.geometry.Polygon compPl = new com.epl.geometry.Polygon();
            compPl.StartPath(new com.epl.geometry.Point(-116, 20));
            compPl.LineTo(new com.epl.geometry.Point(-131, 10));
            compPl.LineTo(new com.epl.geometry.Point(-121, 50));
            int noException = 1;

            // no exception
            com.epl.geometry.Geometry intersectGeom = null;
            try
            {
                intersectGeom = com.epl.geometry.GeometryEngine.Intersect(basePl, compPl, com.epl.geometry.SpatialReference.Create(4326));
            }
            catch (System.Exception)
            {
                noException = 0;
            }
            NUnit.Framework.Assert.AreEqual(noException, 1);
            NUnit.Framework.Assert.IsTrue(intersectGeom.IsEmpty());
        }
Пример #20
0
 public virtual void OffsetPolygon_(double distance, com.epl.geometry.OperatorOffset.JoinType joins)
 {
     com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon();
     polygon.StartPath(0, 0);
     polygon.LineTo(0, 16);
     polygon.LineTo(16, 16);
     polygon.LineTo(16, 11);
     polygon.LineTo(10, 10);
     polygon.LineTo(10, 12);
     polygon.LineTo(3, 12);
     polygon.LineTo(3, 4);
     polygon.LineTo(10, 4);
     polygon.LineTo(10, 6);
     polygon.LineTo(16, 5);
     polygon.LineTo(16, 0);
     com.epl.geometry.OperatorOffset offset     = (com.epl.geometry.OperatorOffset)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Offset);
     com.epl.geometry.Geometry       outputGeom = offset.Execute(polygon, null, distance, joins, 2, 0, null);
     NUnit.Framework.Assert.IsNotNull(outputGeom);
     if (distance > 2)
     {
         NUnit.Framework.Assert.IsTrue(outputGeom.IsEmpty());
     }
 }
 internal static bool IsConvex_(com.epl.geometry.Geometry geom, com.epl.geometry.ProgressTracker progress_tracker)
 {
     if (geom.IsEmpty())
     {
         return(true);
     }
     // vacuously true
     com.epl.geometry.Geometry.Type type = geom.GetType();
     if (type == com.epl.geometry.Geometry.Type.Point)
     {
         return(true);
     }
     // vacuously true
     if (type == com.epl.geometry.Geometry.Type.Envelope)
     {
         com.epl.geometry.Envelope envelope = (com.epl.geometry.Envelope)geom;
         if (envelope.GetXMin() == envelope.GetXMax() || envelope.GetYMin() == envelope.GetYMax())
         {
             return(false);
         }
         return(true);
     }
     if (com.epl.geometry.MultiPath.IsSegment(type.Value()))
     {
         com.epl.geometry.Segment segment = (com.epl.geometry.Segment)geom;
         if (segment.GetStartXY().Equals(segment.GetEndXY()))
         {
             return(false);
         }
         return(true);
     }
     // true, but we will upgrade to a Polyline for the ConvexHull operation
     if (type == com.epl.geometry.Geometry.Type.MultiPoint)
     {
         com.epl.geometry.MultiPoint multi_point = (com.epl.geometry.MultiPoint)geom;
         if (multi_point.GetPointCount() == 1)
         {
             return(true);
         }
         // vacuously true, but we will downgrade to a Point for the ConvexHull operation
         return(false);
     }
     if (type == com.epl.geometry.Geometry.Type.Polyline)
     {
         com.epl.geometry.Polyline polyline = (com.epl.geometry.Polyline)geom;
         if (polyline.GetPathCount() == 1 && polyline.GetPointCount() == 2)
         {
             if (!polyline.GetXY(0).Equals(polyline.GetXY(1)))
             {
                 return(true);
             }
         }
         // vacuously true
         return(false);
     }
     // create convex hull
     com.epl.geometry.Polygon polygon = (com.epl.geometry.Polygon)geom;
     if (polygon.GetPathCount() != 1 || polygon.GetPointCount() < 3)
     {
         return(false);
     }
     return(com.epl.geometry.ConvexHull.IsPathConvex(polygon, 0, progress_tracker));
 }
        public static int QuickTest2D(com.epl.geometry.Geometry geomA, com.epl.geometry.Geometry geomB, double tolerance, int testType)
        {
            if (geomB.IsEmpty() || geomA.IsEmpty())
            {
                return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
            }
            int geomAtype = geomA.GetType().Value();
            int geomBtype = geomB.GetType().Value();

            // We do not support segments directly for now. Convert to Polyline
            com.epl.geometry.Polyline autoPolyA;
            if (com.epl.geometry.Geometry.IsSegment(geomAtype))
            {
                autoPolyA = new com.epl.geometry.Polyline(geomA.GetDescription());
                geomA     = (com.epl.geometry.Geometry)autoPolyA;
                autoPolyA.AddSegment((com.epl.geometry.Segment)geomA, true);
            }
            com.epl.geometry.Polyline autoPolyB;
            if (com.epl.geometry.Geometry.IsSegment(geomBtype))
            {
                autoPolyB = new com.epl.geometry.Polyline(geomB.GetDescription());
                geomB     = (com.epl.geometry.Geometry)autoPolyB;
                autoPolyB.AddSegment((com.epl.geometry.Segment)geomB, true);
            }
            switch (geomAtype)
            {
            case com.epl.geometry.Geometry.GeometryType.Point:
            {
                switch (geomBtype)
                {
                case com.epl.geometry.Geometry.GeometryType.Point:
                {
                    // Now process GeometryxGeometry case by case
                    return(QuickTest2DPointPoint((com.epl.geometry.Point)geomA, (com.epl.geometry.Point)geomB, tolerance));
                }

                case com.epl.geometry.Geometry.GeometryType.Envelope:
                {
                    return(ReverseResult(QuickTest2DEnvelopePoint((com.epl.geometry.Envelope)geomB, (com.epl.geometry.Point)geomA, tolerance)));
                }

                case com.epl.geometry.Geometry.GeometryType.MultiPoint:
                {
                    return(ReverseResult(QuickTest2DMultiPointPoint((com.epl.geometry.MultiPoint)geomB, (com.epl.geometry.Point)geomA, tolerance)));
                }

                case com.epl.geometry.Geometry.GeometryType.Polyline:
                {
                    return(ReverseResult(QuickTest2DPolylinePoint((com.epl.geometry.Polyline)geomB, (com.epl.geometry.Point)geomA, tolerance, testType)));
                }

                case com.epl.geometry.Geometry.GeometryType.Polygon:
                {
                    return(ReverseResult(QuickTest2DPolygonPoint((com.epl.geometry.Polygon)geomB, (com.epl.geometry.Point)geomA, tolerance)));
                }
                }
                throw com.epl.geometry.GeometryException.GeometryInternalError();
            }

            case com.epl.geometry.Geometry.GeometryType.Envelope:
            {
                switch (geomBtype)
                {
                case com.epl.geometry.Geometry.GeometryType.Point:
                {
                    // GEOMTHROW(internal_error);//what
                    // else?
                    return(QuickTest2DEnvelopePoint((com.epl.geometry.Envelope)geomA, (com.epl.geometry.Point)geomB, tolerance));
                }

                case com.epl.geometry.Geometry.GeometryType.Envelope:
                {
                    return(QuickTest2DEnvelopeEnvelope((com.epl.geometry.Envelope)geomA, (com.epl.geometry.Envelope)geomB, tolerance));
                }

                case com.epl.geometry.Geometry.GeometryType.MultiPoint:
                {
                    return(ReverseResult(QuickTest2DMultiPointEnvelope((com.epl.geometry.MultiPoint)geomB, (com.epl.geometry.Envelope)geomA, tolerance, testType)));
                }

                case com.epl.geometry.Geometry.GeometryType.Polyline:
                {
                    return(ReverseResult(QuickTest2DPolylineEnvelope((com.epl.geometry.Polyline)geomB, (com.epl.geometry.Envelope)geomA, tolerance)));
                }

                case com.epl.geometry.Geometry.GeometryType.Polygon:
                {
                    return(ReverseResult(QuickTest2DPolygonEnvelope((com.epl.geometry.Polygon)geomB, (com.epl.geometry.Envelope)geomA, tolerance)));
                }
                }
                throw com.epl.geometry.GeometryException.GeometryInternalError();
            }

            case com.epl.geometry.Geometry.GeometryType.MultiPoint:
            {
                switch (geomBtype)
                {
                case com.epl.geometry.Geometry.GeometryType.Point:
                {
                    // GEOMTHROW(internal_error);//what
                    // else?
                    return(QuickTest2DMultiPointPoint((com.epl.geometry.MultiPoint)geomA, (com.epl.geometry.Point)geomB, tolerance));
                }

                case com.epl.geometry.Geometry.GeometryType.Envelope:
                {
                    return(QuickTest2DMultiPointEnvelope((com.epl.geometry.MultiPoint)geomA, (com.epl.geometry.Envelope)geomB, tolerance, testType));
                }

                case com.epl.geometry.Geometry.GeometryType.MultiPoint:
                {
                    return(QuickTest2DMultiPointMultiPoint((com.epl.geometry.MultiPoint)geomA, (com.epl.geometry.MultiPoint)geomB, tolerance, testType));
                }

                case com.epl.geometry.Geometry.GeometryType.Polyline:
                {
                    return(ReverseResult(QuickTest2DPolylineMultiPoint((com.epl.geometry.Polyline)geomB, (com.epl.geometry.MultiPoint)geomA, tolerance)));
                }

                case com.epl.geometry.Geometry.GeometryType.Polygon:
                {
                    return(ReverseResult(QuickTest2DPolygonMultiPoint((com.epl.geometry.Polygon)geomB, (com.epl.geometry.MultiPoint)geomA, tolerance)));
                }
                }
                throw com.epl.geometry.GeometryException.GeometryInternalError();
            }

            case com.epl.geometry.Geometry.GeometryType.Polyline:
            {
                switch (geomBtype)
                {
                case com.epl.geometry.Geometry.GeometryType.Point:
                {
                    // GEOMTHROW(internal_error);//what
                    // else?
                    return(QuickTest2DPolylinePoint((com.epl.geometry.Polyline)geomA, (com.epl.geometry.Point)geomB, tolerance, testType));
                }

                case com.epl.geometry.Geometry.GeometryType.Envelope:
                {
                    return(QuickTest2DPolylineEnvelope((com.epl.geometry.Polyline)geomA, (com.epl.geometry.Envelope)geomB, tolerance));
                }

                case com.epl.geometry.Geometry.GeometryType.MultiPoint:
                {
                    return(QuickTest2DPolylineMultiPoint((com.epl.geometry.Polyline)geomA, (com.epl.geometry.MultiPoint)geomB, tolerance));
                }

                case com.epl.geometry.Geometry.GeometryType.Polyline:
                {
                    return(QuickTest2DPolylinePolyline((com.epl.geometry.Polyline)geomA, (com.epl.geometry.Polyline)geomB, tolerance));
                }

                case com.epl.geometry.Geometry.GeometryType.Polygon:
                {
                    return(ReverseResult(QuickTest2DPolygonPolyline((com.epl.geometry.Polygon)geomB, (com.epl.geometry.Polyline)geomA, tolerance)));
                }
                }
                throw com.epl.geometry.GeometryException.GeometryInternalError();
            }

            case com.epl.geometry.Geometry.GeometryType.Polygon:
            {
                switch (geomBtype)
                {
                case com.epl.geometry.Geometry.GeometryType.Point:
                {
                    // GEOMTHROW(internal_error);//what
                    // else?
                    return(QuickTest2DPolygonPoint((com.epl.geometry.Polygon)geomA, (com.epl.geometry.Point)geomB, tolerance));
                }

                case com.epl.geometry.Geometry.GeometryType.Envelope:
                {
                    return(QuickTest2DPolygonEnvelope((com.epl.geometry.Polygon)geomA, (com.epl.geometry.Envelope)geomB, tolerance));
                }

                case com.epl.geometry.Geometry.GeometryType.MultiPoint:
                {
                    return(QuickTest2DPolygonMultiPoint((com.epl.geometry.Polygon)geomA, (com.epl.geometry.MultiPoint)geomB, tolerance));
                }

                case com.epl.geometry.Geometry.GeometryType.Polyline:
                {
                    return(QuickTest2DPolygonPolyline((com.epl.geometry.Polygon)geomA, (com.epl.geometry.Polyline)geomB, tolerance));
                }

                case com.epl.geometry.Geometry.GeometryType.Polygon:
                {
                    return(QuickTest2DPolygonPolygon((com.epl.geometry.Polygon)geomA, (com.epl.geometry.Polygon)geomB, tolerance));
                }
                }
                throw com.epl.geometry.GeometryException.GeometryInternalError();
            }

            default:
            {
                // GEOMTHROW(internal_error);//what
                // else?
                throw com.epl.geometry.GeometryException.GeometryInternalError();
            }
            }
        }
Пример #23
0
 public static com.epl.geometry.ogc.OGCGeometry CreateFromEsriGeometry(com.epl.geometry.Geometry geom, com.epl.geometry.SpatialReference sr, bool multiType)
 {
     if (geom == null)
     {
         return(null);
     }
     com.epl.geometry.Geometry.Type t = geom.GetType();
     if (t == com.epl.geometry.Geometry.Type.Polygon)
     {
         if (!multiType && ((com.epl.geometry.Polygon)geom).GetExteriorRingCount() == 1)
         {
             return(new com.epl.geometry.ogc.OGCPolygon((com.epl.geometry.Polygon)geom, sr));
         }
         else
         {
             return(new com.epl.geometry.ogc.OGCMultiPolygon((com.epl.geometry.Polygon)geom, sr));
         }
     }
     if (t == com.epl.geometry.Geometry.Type.Polyline)
     {
         if (!multiType && ((com.epl.geometry.Polyline)geom).GetPathCount() == 1)
         {
             return(new com.epl.geometry.ogc.OGCLineString((com.epl.geometry.Polyline)geom, 0, sr));
         }
         else
         {
             return(new com.epl.geometry.ogc.OGCMultiLineString((com.epl.geometry.Polyline)geom, sr));
         }
     }
     if (t == com.epl.geometry.Geometry.Type.MultiPoint)
     {
         if (!multiType && ((com.epl.geometry.MultiPoint)geom).GetPointCount() <= 1)
         {
             if (geom.IsEmpty())
             {
                 return(new com.epl.geometry.ogc.OGCPoint(new com.epl.geometry.Point(), sr));
             }
             else
             {
                 return(new com.epl.geometry.ogc.OGCPoint(((com.epl.geometry.MultiPoint)geom).GetPoint(0), sr));
             }
         }
         else
         {
             return(new com.epl.geometry.ogc.OGCMultiPoint((com.epl.geometry.MultiPoint)geom, sr));
         }
     }
     if (t == com.epl.geometry.Geometry.Type.Point)
     {
         if (!multiType)
         {
             return(new com.epl.geometry.ogc.OGCPoint((com.epl.geometry.Point)geom, sr));
         }
         else
         {
             return(new com.epl.geometry.ogc.OGCMultiPoint((com.epl.geometry.Point)geom, sr));
         }
     }
     if (t == com.epl.geometry.Geometry.Type.Envelope)
     {
         com.epl.geometry.Polygon p = new com.epl.geometry.Polygon();
         p.AddEnvelope((com.epl.geometry.Envelope)geom, false);
         return(CreateFromEsriGeometry(p, sr, multiType));
     }
     throw new System.NotSupportedException();
 }
Пример #24
0
 public virtual void TestBufferPolyline()
 {
     com.epl.geometry.SpatialReference sr        = com.epl.geometry.SpatialReference.Create(4326);
     com.epl.geometry.Polyline         inputGeom = new com.epl.geometry.Polyline();
     com.epl.geometry.OperatorBuffer   buffer    = (com.epl.geometry.OperatorBuffer)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Buffer);
     com.epl.geometry.OperatorSimplify simplify  = (com.epl.geometry.OperatorSimplify)com.epl.geometry.OperatorFactoryLocal.GetInstance().GetOperator(com.epl.geometry.Operator.Type.Simplify);
     inputGeom.StartPath(0, 0);
     inputGeom.LineTo(50, 50);
     inputGeom.LineTo(50, 0);
     inputGeom.LineTo(0, 50);
     {
         com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 0, null);
         NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon);
         NUnit.Framework.Assert.IsTrue(result.IsEmpty());
     }
     {
         com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, -1, null);
         NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon);
         NUnit.Framework.Assert.IsTrue(result.IsEmpty());
     }
     {
         com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 40.0, null);
         NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon);
         com.epl.geometry.Polygon    poly  = (com.epl.geometry.Polygon)(result);
         com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D();
         result.QueryEnvelope2D(env2D);
         NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 80 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() - 80 - 50) < 0.1);
         NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1);
         int pathCount = poly.GetPathCount();
         NUnit.Framework.Assert.IsTrue(pathCount == 1);
         int pointCount = poly.GetPointCount();
         NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 171.0) < 10);
         NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null));
     }
     {
         com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 4.0, null);
         NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon);
         com.epl.geometry.Polygon    poly  = (com.epl.geometry.Polygon)(result);
         com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D();
         result.QueryEnvelope2D(env2D);
         NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 8 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() - 8 - 50) < 0.1);
         NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1);
         int pathCount = poly.GetPathCount();
         NUnit.Framework.Assert.IsTrue(pathCount == 2);
         int pointCount = poly.GetPointCount();
         NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 186.0) < 10);
         NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null));
     }
     {
         inputGeom = new com.epl.geometry.Polyline();
         inputGeom.StartPath(0, 0);
         inputGeom.LineTo(50, 50);
         inputGeom.StartPath(50, 0);
         inputGeom.LineTo(0, 50);
         com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 4.0, null);
         NUnit.Framework.Assert.IsTrue(result.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Polygon);
         com.epl.geometry.Polygon    poly  = (com.epl.geometry.Polygon)(result);
         com.epl.geometry.Envelope2D env2D = new com.epl.geometry.Envelope2D();
         result.QueryEnvelope2D(env2D);
         NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetWidth() - 8 - 50) < 0.1 && System.Math.Abs(env2D.GetHeight() - 8 - 50) < 0.1);
         NUnit.Framework.Assert.IsTrue(System.Math.Abs(env2D.GetCenterX() - 25) < 0.1 && System.Math.Abs(env2D.GetCenterY() - 25) < 0.1);
         int pathCount = poly.GetPathCount();
         NUnit.Framework.Assert.IsTrue(pathCount == 1);
         int pointCount = poly.GetPointCount();
         NUnit.Framework.Assert.IsTrue(System.Math.Abs(pointCount - 208.0) < 10);
         NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null));
     }
     {
         inputGeom = new com.epl.geometry.Polyline();
         inputGeom.StartPath(1.762614, 0.607368);
         inputGeom.LineTo(1.762414, 0.606655);
         inputGeom.LineTo(1.763006, 0.607034);
         inputGeom.LineTo(1.762548, 0.607135);
         com.epl.geometry.Geometry result = buffer.Execute(inputGeom, sr, 0.005, null);
         NUnit.Framework.Assert.IsTrue(simplify.IsSimpleAsFeature(result, sr, null));
     }
 }
        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));
        }
Пример #26
0
        /// <summary>Performs the Distance operation on two geometries</summary>
        /// <returns>Returns a double.</returns>
        public override double Execute(com.epl.geometry.Geometry geom1, com.epl.geometry.Geometry geom2, com.epl.geometry.ProgressTracker progressTracker)
        {
            if (null == geom1 || null == geom2)
            {
                throw new System.ArgumentException();
            }
            com.epl.geometry.Geometry geometryA = geom1;
            com.epl.geometry.Geometry geometryB = geom2;
            if (geometryA.IsEmpty() || geometryB.IsEmpty())
            {
                return(com.epl.geometry.NumberUtils.TheNaN);
            }
            com.epl.geometry.Polygon    polygonA;
            com.epl.geometry.Polygon    polygonB;
            com.epl.geometry.MultiPoint multiPointA;
            com.epl.geometry.MultiPoint multiPointB;
            // if geometryA is an envelope use a polygon instead (if geom1 was
            // folded, then geometryA will already be a polygon)
            // if geometryA is a point use a multipoint instead
            com.epl.geometry.Geometry.Type gtA = geometryA.GetType();
            com.epl.geometry.Geometry.Type gtB = geometryB.GetType();
            if (gtA == com.epl.geometry.Geometry.Type.Point)
            {
                if (gtB == com.epl.geometry.Geometry.Type.Point)
                {
                    return(com.epl.geometry.Point2D.Distance(((com.epl.geometry.Point)geometryA).GetXY(), ((com.epl.geometry.Point)geometryB).GetXY()));
                }
                else
                {
                    if (gtB == com.epl.geometry.Geometry.Type.Envelope)
                    {
                        com.epl.geometry.Envelope2D envB = new com.epl.geometry.Envelope2D();
                        geometryB.QueryEnvelope2D(envB);
                        return(envB.Distance(((com.epl.geometry.Point)geometryA).GetXY()));
                    }
                }
                multiPointA = new com.epl.geometry.MultiPoint();
                multiPointA.Add((com.epl.geometry.Point)geometryA);
                geometryA = multiPointA;
            }
            else
            {
                if (gtA == com.epl.geometry.Geometry.Type.Envelope)
                {
                    if (gtB == com.epl.geometry.Geometry.Type.Envelope)
                    {
                        com.epl.geometry.Envelope2D envA = new com.epl.geometry.Envelope2D();
                        geometryA.QueryEnvelope2D(envA);
                        com.epl.geometry.Envelope2D envB = new com.epl.geometry.Envelope2D();
                        geometryB.QueryEnvelope2D(envB);
                        return(envB.Distance(envA));
                    }
                    polygonA = new com.epl.geometry.Polygon();
                    polygonA.AddEnvelope((com.epl.geometry.Envelope)geometryA, false);
                    geometryA = polygonA;
                }
            }
            // if geom_2 is an envelope use a polygon instead
            // if geom_2 is a point use a multipoint instead
            if (gtB == com.epl.geometry.Geometry.Type.Point)
            {
                multiPointB = new com.epl.geometry.MultiPoint();
                multiPointB.Add((com.epl.geometry.Point)geometryB);
                geometryB = multiPointB;
            }
            else
            {
                if (gtB == com.epl.geometry.Geometry.Type.Envelope)
                {
                    polygonB = new com.epl.geometry.Polygon();
                    polygonB.AddEnvelope((com.epl.geometry.Envelope)geometryB, false);
                    geometryB = polygonB;
                }
            }
            com.epl.geometry.OperatorDistanceLocal.DistanceCalculator distanceCalculator = new com.epl.geometry.OperatorDistanceLocal.DistanceCalculator(this, progressTracker);
            double distance = distanceCalculator.Calculate(geometryA, geometryB);

            return(distance);
        }
Пример #27
0
		internal virtual com.epl.geometry.Geometry TryNativeImplementation_(com.epl.geometry.Geometry input_geom)
		{
			// A note on attributes:
			// 1. The geometry with lower dimension wins in regard to the
			// attributes.
			// 2. If the dimensions are the same, the input_geometry attributes win.
			// 3. The exception to the 2. is when the input is an Envelope, and the
			// intersector is a polygon, then the intersector wins.
			// A note on the tolerance:
			// This operator performs a simple intersection operation. Should it use
			// the tolerance?
			// Example: Point is intersected by the envelope.
			// If it is slightly outside of the envelope, should we still return it
			// if it is closer than the tolerance?
			// Should we do crack and cluster and snap the point coordinates to the
			// envelope boundary?
			//
			// Consider floating point arithmetics approach. When you compare
			// doubles, you should use an epsilon (equals means ::fabs(a - b) <
			// eps), however when you add/subtract, etc them, you do not use
			// epsilon.
			// Shouldn't we do same here? Relational operators use tolerance, but
			// the action operators don't.
			com.epl.geometry.Envelope2D mergedExtent = com.epl.geometry.InternalUtils.GetMergedExtent(input_geom, m_geomIntersector);
			double tolerance = com.epl.geometry.InternalUtils.CalculateToleranceFromGeometry(m_spatial_reference, mergedExtent, false);
			int gtInput = input_geom.GetType().Value();
			bool bInputEmpty = input_geom.IsEmpty();
			bool bGeomIntersectorEmpty = m_geomIntersector.IsEmpty();
			bool bResultIsEmpty = bInputEmpty || bGeomIntersectorEmpty;
			if (!bResultIsEmpty)
			{
				// test envelopes
				com.epl.geometry.Envelope2D env2D1 = new com.epl.geometry.Envelope2D();
				input_geom.QueryEnvelope2D(env2D1);
				com.epl.geometry.Envelope2D env2D2 = new com.epl.geometry.Envelope2D();
				m_geomIntersector.QueryEnvelope2D(env2D2);
				env2D2.Inflate(2.0 * tolerance, 2.0 * tolerance);
				bResultIsEmpty = !env2D1.IsIntersecting(env2D2);
			}
			if (!bResultIsEmpty)
			{
				// try accelerated test
				int res = com.epl.geometry.OperatorInternalRelationUtils.QuickTest2D_Accelerated_DisjointOrContains(m_geomIntersector, input_geom, tolerance);
				if (res == com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint)
				{
					// disjoint
					bResultIsEmpty = true;
				}
				else
				{
					if ((res & com.epl.geometry.OperatorInternalRelationUtils.Relation.Within) != 0)
					{
						// intersector
						// is
						// within
						// the
						// input_geom
						// TODO:
						// assign
						// input_geom
						// attributes
						// first
						return m_geomIntersector;
					}
					else
					{
						if ((res & com.epl.geometry.OperatorInternalRelationUtils.Relation.Contains) != 0)
						{
							// intersector
							// contains
							// input_geom
							return input_geom;
						}
					}
				}
			}
			if (bResultIsEmpty)
			{
				// When one geometry or both are empty, we need to
				// return an empty geometry.
				// Here we do that end also ensure the type is
				// correct.
				// That is the lower dimension need to be
				// returned. Also, for Point vs Multi_point, an
				// empty Point need to be returned.
				int dim1 = com.epl.geometry.Geometry.GetDimensionFromType(gtInput);
				int dim2 = com.epl.geometry.Geometry.GetDimensionFromType(m_geomIntersectorType);
				if (dim1 < dim2)
				{
					return ReturnEmpty_(input_geom, bInputEmpty);
				}
				else
				{
					if (dim1 > dim2)
					{
						return ReturnEmptyIntersector_();
					}
					else
					{
						if (dim1 == 0)
						{
							if (gtInput == com.epl.geometry.Geometry.GeometryType.MultiPoint && m_geomIntersectorType == com.epl.geometry.Geometry.GeometryType.Point)
							{
								// point
								// vs
								// Multi_point
								// need
								// special
								// treatment
								// to
								// ensure
								// Point
								// is
								// returned
								// always.
								return ReturnEmptyIntersector_();
							}
							else
							{
								// Both input and intersector have same gtype, or input is
								// Point.
								return ReturnEmpty_(input_geom, bInputEmpty);
							}
						}
						else
						{
							return ReturnEmpty_(input_geom, bInputEmpty);
						}
					}
				}
			}
			// Note: No empty geometries after this point!
			// Warning: Do not try clip for polylines and polygons.
			// Try clip of Envelope with Envelope.
			if ((m_dimensionMask == -1 || m_dimensionMask == (1 << 2)) && gtInput == com.epl.geometry.Geometry.GeometryType.Envelope && m_geomIntersectorType == com.epl.geometry.Geometry.GeometryType.Envelope)
			{
				com.epl.geometry.Envelope env1 = (com.epl.geometry.Envelope)input_geom;
				com.epl.geometry.Envelope env2 = (com.epl.geometry.Envelope)m_geomIntersector;
				com.epl.geometry.Envelope2D env2D_1 = new com.epl.geometry.Envelope2D();
				env1.QueryEnvelope2D(env2D_1);
				com.epl.geometry.Envelope2D env2D_2 = new com.epl.geometry.Envelope2D();
				env2.QueryEnvelope2D(env2D_2);
				env2D_1.Intersect(env2D_2);
				com.epl.geometry.Envelope result_env = new com.epl.geometry.Envelope();
				env1.CopyTo(result_env);
				result_env.SetEnvelope2D(env2D_1);
				return result_env;
			}
			// Use clip for Point and Multi_point with Envelope
			if ((gtInput == com.epl.geometry.Geometry.GeometryType.Envelope && com.epl.geometry.Geometry.GetDimensionFromType(m_geomIntersectorType) == 0) || (m_geomIntersectorType == com.epl.geometry.Geometry.GeometryType.Envelope && com.epl.geometry.Geometry.GetDimensionFromType(gtInput
				) == 0))
			{
				com.epl.geometry.Envelope env = gtInput == com.epl.geometry.Geometry.GeometryType.Envelope ? (com.epl.geometry.Envelope)input_geom : (com.epl.geometry.Envelope)m_geomIntersector;
				com.epl.geometry.Geometry other = gtInput == com.epl.geometry.Geometry.GeometryType.Envelope ? m_geomIntersector : input_geom;
				com.epl.geometry.Envelope2D env_2D = new com.epl.geometry.Envelope2D();
				env.QueryEnvelope2D(env_2D);
				return com.epl.geometry.Clipper.Clip(other, env_2D, tolerance, 0);
			}
			if ((com.epl.geometry.Geometry.GetDimensionFromType(gtInput) == 0 && com.epl.geometry.Geometry.GetDimensionFromType(m_geomIntersectorType) > 0) || (com.epl.geometry.Geometry.GetDimensionFromType(gtInput) > 0 && com.epl.geometry.Geometry.GetDimensionFromType(m_geomIntersectorType
				) == 0))
			{
				// multipoint
				// intersection
				double tolerance1 = com.epl.geometry.InternalUtils.CalculateToleranceFromGeometry(m_spatial_reference, input_geom, false);
				if (gtInput == com.epl.geometry.Geometry.GeometryType.MultiPoint)
				{
					return com.epl.geometry.TopologicalOperations.Intersection((com.epl.geometry.MultiPoint)input_geom, m_geomIntersector, tolerance1);
				}
				if (gtInput == com.epl.geometry.Geometry.GeometryType.Point)
				{
					return com.epl.geometry.TopologicalOperations.Intersection((com.epl.geometry.Point)input_geom, m_geomIntersector, tolerance1);
				}
				if (m_geomIntersectorType == com.epl.geometry.Geometry.GeometryType.MultiPoint)
				{
					return com.epl.geometry.TopologicalOperations.Intersection((com.epl.geometry.MultiPoint)m_geomIntersector, input_geom, tolerance1);
				}
				if (m_geomIntersectorType == com.epl.geometry.Geometry.GeometryType.Point)
				{
					return com.epl.geometry.TopologicalOperations.Intersection((com.epl.geometry.Point)m_geomIntersector, input_geom, tolerance1);
				}
				throw com.epl.geometry.GeometryException.GeometryInternalError();
			}
			// Try Polyline vs Polygon
			if ((m_dimensionMask == -1 || m_dimensionMask == (1 << 1)) && (gtInput == com.epl.geometry.Geometry.GeometryType.Polyline) && (m_geomIntersectorType == com.epl.geometry.Geometry.GeometryType.Polygon))
			{
				return TryFastIntersectPolylinePolygon_((com.epl.geometry.Polyline)(input_geom), (com.epl.geometry.Polygon)(m_geomIntersector));
			}
			// Try Polygon vs Polyline
			if ((m_dimensionMask == -1 || m_dimensionMask == (1 << 1)) && (gtInput == com.epl.geometry.Geometry.GeometryType.Polygon) && (m_geomIntersectorType == com.epl.geometry.Geometry.GeometryType.Polyline))
			{
				return TryFastIntersectPolylinePolygon_((com.epl.geometry.Polyline)(m_geomIntersector), (com.epl.geometry.Polygon)(input_geom));
			}
			return null;
		}
 internal static com.epl.geometry.Geometry CalculateConvexHull_(com.epl.geometry.Geometry geom, com.epl.geometry.ProgressTracker progress_tracker)
 {
     if (geom.IsEmpty())
     {
         return(geom.CreateInstance());
     }
     com.epl.geometry.Geometry.Type type = geom.GetType();
     if (com.epl.geometry.Geometry.IsSegment(type.Value()))
     {
         // Segments are always returned either as a Point or Polyline
         com.epl.geometry.Segment segment = (com.epl.geometry.Segment)geom;
         if (segment.GetStartXY().Equals(segment.GetEndXY()))
         {
             com.epl.geometry.Point point = new com.epl.geometry.Point();
             segment.QueryStart(point);
             return(point);
         }
         else
         {
             com.epl.geometry.Point    pt       = new com.epl.geometry.Point();
             com.epl.geometry.Polyline polyline = new com.epl.geometry.Polyline(geom.GetDescription());
             segment.QueryStart(pt);
             polyline.StartPath(pt);
             segment.QueryEnd(pt);
             polyline.LineTo(pt);
             return(polyline);
         }
     }
     else
     {
         if (type == com.epl.geometry.Geometry.Type.Envelope)
         {
             com.epl.geometry.Envelope   envelope = (com.epl.geometry.Envelope)geom;
             com.epl.geometry.Envelope2D env      = new com.epl.geometry.Envelope2D();
             envelope.QueryEnvelope2D(env);
             if (env.xmin == env.xmax && env.ymin == env.ymax)
             {
                 com.epl.geometry.Point point = new com.epl.geometry.Point();
                 envelope.QueryCornerByVal(0, point);
                 return(point);
             }
             else
             {
                 if (env.xmin == env.xmax || env.ymin == env.ymax)
                 {
                     com.epl.geometry.Point    pt       = new com.epl.geometry.Point();
                     com.epl.geometry.Polyline polyline = new com.epl.geometry.Polyline(geom.GetDescription());
                     envelope.QueryCornerByVal(0, pt);
                     polyline.StartPath(pt);
                     envelope.QueryCornerByVal(1, pt);
                     polyline.LineTo(pt);
                     return(polyline);
                 }
                 else
                 {
                     com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon(geom.GetDescription());
                     polygon.AddEnvelope(envelope, false);
                     return(polygon);
                 }
             }
         }
     }
     if (IsConvex_(geom, progress_tracker))
     {
         if (type == com.epl.geometry.Geometry.Type.MultiPoint)
         {
             // Downgrade to a Point for simplistic output
             com.epl.geometry.MultiPoint multi_point = (com.epl.geometry.MultiPoint)geom;
             com.epl.geometry.Point      point       = new com.epl.geometry.Point();
             multi_point.GetPointByVal(0, point);
             return(point);
         }
         return(geom);
     }
     System.Diagnostics.Debug.Assert((com.epl.geometry.Geometry.IsMultiVertex(type.Value())));
     com.epl.geometry.Geometry convex_hull = com.epl.geometry.ConvexHull.Construct((com.epl.geometry.MultiVertexGeometry)geom);
     return(convex_hull);
 }