コード例 #1
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);
        }