using System.Collections.Generic;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using Newtonsoft.Json;

namespace SouthSmart.GISService.Infrastructure.Module
{
    //拓扑分析类
    public static class TopoAnalyseHelper
    {
        public static IGeometry IntersectResult ( this IGeometry geometry, IGeometry tagGeometry )
        {
            ITopologicalOperator pTopological = ( geometry ) as ITopologicalOperator;
            IGeometry pGeoIntersect = pTopological.Intersect ( tagGeometry, esriGeometryDimension.esriGeometry2Dimension );
            return pGeoIntersect;
        }
        public static IGeometry DifferenceResult ( this IGeometry geometry, IGeometry tagGeometry )
        {
            ITopologicalOperator pTopological = ( geometry ) as ITopologicalOperator;
            IGeometry pGeoIntersect = pTopological.Difference ( tagGeometry );
            return pGeoIntersect;
        }
        public static bool TouchResult ( this IGeometry geometry, IGeometry tagGeometry )
        {
            IRelationalOperator2 pTopological = ( geometry ) as IRelationalOperator2;
            bool isTouch = pTopological.Touches ( tagGeometry );
            return isTouch;
        }
        public static IGeometry UnionResult ( this IGeometry geometry, IGeometry tagGeometry )
        {
            ITopologicalOperator2 pTopological = geometry as ITopologicalOperator2;
            IGeometry pGeoUnion = pTopological.Union ( tagGeometry );
            return pGeoUnion;
        }
        public static IGeometry BufferResult ( this IGeometry geometry, double distance )
        {
            ITopologicalOperator2 pTopological = geometry as ITopologicalOperator2;
            IGeometry pGeoBuffer = pTopological.Buffer ( distance );
            return pGeoBuffer;
        }
        //缝隙结果
        public static IGeometry GapResult ( this IGeometry geometry, IGeometry tagGeometry )
        {
            
            IPolygon polygon = geometry as IPolygon;
            IArea pArea = ( IArea ) polygon;
            double area = pArea.Area;

             polygon = tagGeometry as IPolygon;
             pArea = ( IArea ) polygon;
             area = pArea.Area;

            ITopologicalOperator2 pTopological = geometry as ITopologicalOperator2;
            IGeometry pGeoUnion = pTopological.Union ( tagGeometry );
             polygon = pGeoUnion as IPolygon;
             pArea = ( IArea ) polygon;
             area = pArea.Area;
            ITopologicalOperator2 pTopologica2 = pGeoUnion as ITopologicalOperator2;
            IGeometry pGeoDifference2 = pTopologica2.Difference ( geometry );
            polygon = pGeoDifference2 as IPolygon;
            pArea = ( IArea ) polygon;
            area = pArea.Area;
            ITopologicalOperator2 pTopologica3 = pGeoDifference2 as ITopologicalOperator2;
            IGeometry pGeoDifference3 = pTopologica3.Difference ( tagGeometry );
            polygon = pGeoDifference3 as IPolygon;
            pArea = ( IArea ) polygon;
            area = pArea.Area;
            return pGeoDifference3;
        }
        /*
        #todo:esriSpatialRelUndefined
        Used when the spatial relationship is not known at the time of object creation.
        #todo:esriSpatialRelIntersects
        Returns a feature if any spatial relationship is found.Applies to all shape type combinations. 
        #todo:esriSpatialRelEnvelopeIntersects
        Returns a feature if the envelope of the two shapes intersects.
        #todo:esriSpatialRelIndexIntersects
        Returns a feature if the envelope of the query geometry intersects the index entry for the target geometry.Because it uses the underlying index grid, rather than the evelope of the feature, it is faster and is commonly used for return features for display purposes.
        #todo:esriSpatialRelTouches
        Returns a feature if the two shapes share a common boundary.However, the intersection of the interiors of the two shapes must be empty. In the Point/Line case, the point may touch an endpoint only of the line. Applies to all combinations except Point/Point.
        #todo:esriSpatialRelOverlaps
        Returns a feature if the intersection of the two shapes results in an object of the same dimension, but different from both of the shapes.Applies to Area/Area, Line/Line, and Multi-point/Multi-point shape type combinations. 
        #todo:esriSpatialRelCrosses
        Returns a feature if the intersection of the interiors of the two shapes is not empty and has a lower dimension than the maximum dimension of the two shapes.Two lines that share an endpoint in common do not cross. Valid for Line/Line, Line/Area, Multi-point/Area, and Multi-point/Line shape type combinations. 
        #todo:esriSpatialRelWithin
        Returns a feature if its shape wholly contains the search geometry.Valid for all shape type combinations. 
        #todo:esriSpatialRelContains
        Returns a feature if its shape is wholly contained within the search geometry. Valid for all shape type combinations. 
        #todo:esriSpatialRelRelation
        This is the expected value for ISpatialFilter::SpatialRel when using ISpatialFilter::SpatialRelDescription to define a custom spatial relationship.See the help on ISpatialFilter for details.
        */
    }
}