예제 #1
0
        /// <summary>
        /// Returns true if the primary geometry is wholly contained within the comparison geometry.
        /// </summary>
        /// <param name="g1">Source geometry</param>
        /// <param name="g2">Other geometry</param>
        /// <returns></returns>
        public static bool Within(Geometry g1, Geometry g2)
        {
            SqlGeometry sg1 = SqlGeometryConverter.ToSqlGeometry(g1);
            SqlGeometry sg2 = SqlGeometryConverter.ToSqlGeometry(g2);

            return((bool)sg1.STWithin(sg2));
        }
예제 #2
0
        public static Geometry Buffer(Geometry g, Double distance)
        {
            SqlGeometry sg       = SqlGeometryConverter.ToSqlGeometry(g);
            SqlGeometry sgBuffer = sg.STBuffer(distance);

            return(SqlGeometryConverter.ToSharpMapGeometry(sgBuffer));
        }
예제 #3
0
        public static Geometry ConvexHull(Geometry g)
        {
            SqlGeometry sg           = SqlGeometryConverter.ToSqlGeometry(g);
            SqlGeometry sgConvexHull = sg.STConvexHull();

            return(SqlGeometryConverter.ToSharpMapGeometry(sgConvexHull));
        }
예제 #4
0
        /// <summary>
        /// Returns true if there is any intersection between the two geometries.
        /// </summary>
        /// <param name="g1">Source geometry</param>
        /// <param name="g2">Other geometry</param>
        /// <returns></returns>
        public static bool Intersects(Geometry g1, Geometry g2)
        {
            SqlGeometry sg1 = SqlGeometryConverter.ToSqlGeometry(g1);
            SqlGeometry sg2 = SqlGeometryConverter.ToSqlGeometry(g2);

            return((bool)sg1.STIntersects(sg2));
        }
예제 #5
0
        public static Geometry Boundary(Geometry g)
        {
            SqlGeometry sg         = SqlGeometryConverter.ToSqlGeometry(g);
            SqlGeometry sgBoundary = sg.STBoundary();

            return(SqlGeometryConverter.ToSharpMapGeometry(sgBoundary));
        }
예제 #6
0
        /// <summary>
        /// Returns true if otherGeometry is wholly contained within the source geometry. This is the same as
        /// reversing the primary and comparison shapes of the Within operation.
        /// </summary>
        /// <param name="g1">Source geometry</param>
        /// <param name="g2">Other geometry</param>
        /// <returns>True if otherGeometry is wholly contained within the source geometry.</returns>
        public static bool Contains(Geometry g1, Geometry g2)
        {
            SqlGeometry sg1 = SqlGeometryConverter.ToSqlGeometry(g1);
            SqlGeometry sg2 = SqlGeometryConverter.ToSqlGeometry(g2);

            return((bool)(sg1.STContains(sg2)));
        }
예제 #7
0
        /// <summary>
        /// Returns true if the given geometries relate according to the provided intersection pattern Matrix
        /// </summary>
        /// <param name="g1">Source geometry</param>
        /// <param name="g2">Other geometry</param>
        /// <param name="intersectionPatternMatrix">Intersection pattern Matrix</param>
        /// <returns></returns>
        public static Boolean Relate(Geometry g1, Geometry g2, string intersectionPatternMatrix)
        {
            SqlGeometry sg1 = SqlGeometryConverter.ToSqlGeometry(g1);
            SqlGeometry sg2 = SqlGeometryConverter.ToSqlGeometry(g2);

            return((bool)sg1.STRelate(sg2, intersectionPatternMatrix));
        }
예제 #8
0
        private Geometry ToSqlServerAndBack(Geometry gIn)
        {
            SqlGeometry sqlGeometry = SqlGeometryConverter.ToSqlGeometry(gIn);
            Geometry    gOut        = SqlGeometryConverter.ToSharpMapGeometry(sqlGeometry);

            return(gOut);
        }
예제 #9
0
        public static Geometry SymDifference(Geometry g1, Geometry g2)
        {
            SqlGeometry sg1             = SqlGeometryConverter.ToSqlGeometry(g1);
            SqlGeometry sg2             = SqlGeometryConverter.ToSqlGeometry(g2);
            SqlGeometry sgSymDifference = sg1.STSymDifference(sg2);

            return(SqlGeometryConverter.ToSharpMapGeometry(sgSymDifference));
        }
예제 #10
0
        public static Geometry Intersection(Geometry g1, Geometry g2)
        {
            SqlGeometry sg1            = SqlGeometryConverter.ToSqlGeometry(g1);
            SqlGeometry sg2            = SqlGeometryConverter.ToSqlGeometry(g2);
            SqlGeometry sgIntersection = sg1.STIntersection(sg2);

            return(SqlGeometryConverter.ToSharpMapGeometry(sgIntersection));
        }
예제 #11
0
        private Geometry ToSqlServerAndBack(Geometry gIn)
        {
            Assert.That(gIn, Is.Not.Null);
            Assert.That(gIn.SRID, Is.EqualTo(-1));
            gIn.SRID = 0;
            SqlGeometry sqlGeometry = SqlGeometryConverter.ToSqlGeometry(gIn);
            Geometry    gOut        = SqlGeometryConverter.ToSharpMapGeometry(sqlGeometry, new NetTopologySuite.Geometries.GeometryFactory());

            return(gOut);
        }
예제 #12
0
        public static Geometry Union(Geometry g, params Geometry[] geometries)
        {
            SqlGeometry sg = SqlGeometryConverter.ToSqlGeometry(g);

            foreach (SqlGeometry sgUnion in SqlGeometryConverter.ToSqlGeometries(geometries))
            {
                sg = sg.STUnion(sgUnion);
            }
            return(SqlGeometryConverter.ToSharpMapGeometry(sg));
        }
예제 #13
0
        /// <summary>
        /// Computes the boundary of <paramref name="g"/> using SqlServer spatial object algorithms
        /// </summary>
        /// <param name="g">A geometry/geography</param>
        /// <param name="spatialMode">Flag indicating if <paramref name="g"/> is geometry or geography</param>
        /// <returns>The boundary</returns>
        public static Geometry Boundary(Geometry g, SqlServerSpatialObjectType spatialMode)
        {
            if (spatialMode == SqlServerSpatialObjectType.Geometry)
            {
                SqlGeometry sg         = SqlGeometryConverter.ToSqlGeometry(g);
                SqlGeometry sgBoundary = sg.STBoundary();
                return(SqlGeometryConverter.ToSharpMapGeometry(sgBoundary));
            }

            throw new ArgumentOutOfRangeException("Geography does not support STBoundary");
        }
예제 #14
0
 /// <summary>
 /// Returns true if the intersection of the two geometries results in a geometry whose dimension is less than
 /// the maximum dimension of the two geometries and the intersection geometry is not equal to either.
 /// geometry.
 /// </summary>
 /// <param name="g1">Source geometry</param>
 /// <param name="g2">Other geometry</param>
 /// <param name="spatialMode">calculation library - some methods have different behaviour depending on geometry or geography</param>
 /// <returns></returns>
 public static bool Crosses(Geometry g1, Geometry g2, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == Data.Providers.SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg1 = SqlGeometryConverter.ToSqlGeometry(g1);
         SqlGeometry sg2 = SqlGeometryConverter.ToSqlGeometry(g2);
         return((bool)sg1.STCrosses(sg2));
     }
     else
     {
         throw new ArgumentOutOfRangeException("Geography does not support STCrosses. You must first convert Geography to Geometry using WKB");
     }
 }
예제 #15
0
 /// <summary>
 /// Returns true if the given geometries relate according to the provided intersection pattern Matrix
 /// </summary>
 /// <param name="g1">Source geometry</param>
 /// <param name="g2">Other geometry</param>
 /// <param name="intersectionPatternMatrix">Intersection pattern Matrix</param>
 /// <param name="spatialMode">calculation library - some methods have different behaviour depending on geometry or geography</param>
 /// <returns></returns>
 public static Boolean Relate(Geometry g1, Geometry g2, string intersectionPatternMatrix, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg1 = SqlGeometryConverter.ToSqlGeometry(g1);
         SqlGeometry sg2 = SqlGeometryConverter.ToSqlGeometry(g2);
         return((bool)sg1.STRelate(sg2, intersectionPatternMatrix));
     }
     else
     {
         throw new ArgumentOutOfRangeException("Geography does not support STRelate. You must first convert Geography to Geometry using WKB");
     }
 }
예제 #16
0
 /// <summary>
 /// Returns true if otherGeometry is wholly contained within the source geometry. This is the same as
 /// reversing the primary and comparison shapes of the Within operation.
 /// </summary>
 /// <param name="g1">Source geometry</param>
 /// <param name="g2">Other geometry</param>
 /// <param name="spatialMode">calculation library - some methods have different behaviour depending on geometry or geography</param>
 /// <returns>True if otherGeometry is wholly contained within the source geometry.</returns>
 public static bool Contains(Geometry g1, Geometry g2, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == Data.Providers.SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg1 = SqlGeometryConverter.ToSqlGeometry(g1);
         SqlGeometry sg2 = SqlGeometryConverter.ToSqlGeometry(g2);
         return((bool)(sg1.STContains(sg2)));
     }
     else
     {
         SqlGeography sg1 = SqlGeographyConverter.ToSqlGeography(g1);
         SqlGeography sg2 = SqlGeographyConverter.ToSqlGeography(g2);
         return((bool)(sg1.STContains(sg2)));
     }
 }
예제 #17
0
 /// <summary>
 /// Returns true if the primary geometry is wholly contained within the comparison geometry.
 /// </summary>
 /// <param name="g1">Source geometry</param>
 /// <param name="g2">Other geometry</param>
 /// <param name="spatialMode">calculation library - some methods have different behaviour depending on geometry or geography</param>
 /// <returns></returns>
 public static bool Within(Geometry g1, Geometry g2, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg1 = SqlGeometryConverter.ToSqlGeometry(g1);
         SqlGeometry sg2 = SqlGeometryConverter.ToSqlGeometry(g2);
         return((bool)sg1.STWithin(sg2));
     }
     else
     {
         SqlGeography sg1 = SqlGeographyConverter.ToSqlGeography(g1);
         SqlGeography sg2 = SqlGeographyConverter.ToSqlGeography(g2);
         return((bool)sg1.STWithin(sg2));
     }
 }
예제 #18
0
 /// <summary>
 /// Computes the convex-hull of <paramref name="g"/> using SqlServer spatial object algorithms
 /// </summary>
 /// <param name="g">A geometry/geography</param>
 /// <param name="spatialMode">Flag indicating if <paramref name="g"/> is geometry or geography</param>
 /// <returns>The convex-hull</returns>
 public static Geometry ConvexHull(Geometry g, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg           = SqlGeometryConverter.ToSqlGeometry(g);
         SqlGeometry sgConvexHull = sg.STConvexHull();
         return(SqlGeometryConverter.ToSharpMapGeometry(sgConvexHull));
     }
     else
     {
         SqlGeography sg           = SqlGeographyConverter.ToSqlGeography(g);
         SqlGeography sgConvexHull = sg.STConvexHull();
         return(SqlGeographyConverter.ToSharpMapGeometry(sgConvexHull));
     }
 }
예제 #19
0
 /// <summary>
 /// Computes a buffer around <paramref name="g"/> with a given <paramref name="distance"/> using SqlServer spatial object algorithms
 /// </summary>
 /// <param name="g">A geometry/geography</param>
 /// <param name="distance">A distance</param>
 /// <param name="spatialMode">Flag indicating if <paramref name="g"/> is a geometry or geography objects</param>
 /// <returns>The buffered geometry</returns>
 public static Geometry Buffer(Geometry g, Double distance, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg       = SqlGeometryConverter.ToSqlGeometry(g);
         SqlGeometry sgBuffer = sg.STBuffer(distance);
         return(SqlGeometryConverter.ToSharpMapGeometry(sgBuffer));
     }
     else
     {
         SqlGeography sg       = SqlGeographyConverter.ToSqlGeography(g);
         SqlGeography sgBuffer = sg.STBuffer(distance);
         return(SqlGeographyConverter.ToSharpMapGeometry(sgBuffer));
     }
 }
예제 #20
0
 /// <summary>
 /// Computes the symmetric-difference of <paramref name="g1"/> and <paramref name="g2"/> using SqlServer spatial object algorithms
 /// </summary>
 /// <param name="g1">A geometry/geography</param>
 /// <param name="g2">A geometry/geography</param>
 /// <param name="spatialMode">Flag indicating if <paramref name="g1"/> and <paramref name="g2"/> are geometry or geography objects</param>
 /// <returns>The symmetric difference</returns>
 public static Geometry SymDifference(Geometry g1, Geometry g2, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg1             = SqlGeometryConverter.ToSqlGeometry(g1);
         SqlGeometry sg2             = SqlGeometryConverter.ToSqlGeometry(g2);
         SqlGeometry sgSymDifference = sg1.STSymDifference(sg2);
         return(SqlGeometryConverter.ToSharpMapGeometry(sgSymDifference));
     }
     else
     {
         SqlGeography sg1             = SqlGeographyConverter.ToSqlGeography(g1);
         SqlGeography sg2             = SqlGeographyConverter.ToSqlGeography(g2);
         SqlGeography sgSymDifference = sg1.STSymDifference(sg2);
         return(SqlGeographyConverter.ToSharpMapGeometry(sgSymDifference));
     }
 }
예제 #21
0
 /// <summary>
 /// Computes the intersection of <paramref name="g1"/> and <paramref name="g2"/> using SqlServer spatial object algorithms
 /// </summary>
 /// <param name="g1">A geometry/geography</param>
 /// <param name="g2">A geometry/geography</param>
 /// <param name="spatialMode">Flag indicating if <paramref name="g1"/> and <paramref name="g2"/> are geometry or geography objects</param>
 /// <returns>The intersection</returns>
 public static Geometry Intersection(Geometry g1, Geometry g2, SqlServerSpatialObjectType spatialMode)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg1            = SqlGeometryConverter.ToSqlGeometry(g1);
         SqlGeometry sg2            = SqlGeometryConverter.ToSqlGeometry(g2);
         SqlGeometry sgIntersection = sg1.STIntersection(sg2);
         return(SqlGeometryConverter.ToSharpMapGeometry(sgIntersection));
     }
     else
     {
         SqlGeography sg1            = SqlGeographyConverter.ToSqlGeography(g1);
         SqlGeography sg2            = SqlGeographyConverter.ToSqlGeography(g2);
         SqlGeography sgIntersection = sg1.STIntersection(sg2);
         return(SqlGeographyConverter.ToSharpMapGeometry(sgIntersection));
     }
 }
예제 #22
0
 /// <summary>
 /// Computes the union of <paramref name="g"/> and <paramref name="geometries"/> using SqlServer spatial object algorithms
 /// </summary>
 /// <param name="g">A geometry/geography</param>
 /// <param name="geometries">A (series of) geometry/geography objects</param>
 /// <param name="spatialMode">Flag indicating if <paramref name="g"/> and <paramref name="geometries"/> are geometry or geography objects</param>
 /// <returns>The union</returns>
 public static Geometry Union(Geometry g, SqlServerSpatialObjectType spatialMode, params Geometry[] geometries)
 {
     if (spatialMode == SqlServerSpatialObjectType.Geometry)
     {
         SqlGeometry sg = SqlGeometryConverter.ToSqlGeometry(g);
         foreach (SqlGeometry sgUnion in SqlGeometryConverter.ToSqlGeometries(geometries))
         {
             sg = sg.STUnion(sgUnion);
         }
         return(SqlGeometryConverter.ToSharpMapGeometry(sg));
     }
     else
     {
         SqlGeography sg = SqlGeographyConverter.ToSqlGeography(g);
         foreach (SqlGeography sgUnion in SqlGeographyConverter.ToSqlGeographies(geometries))
         {
             sg = sg.STUnion(sgUnion);
         }
         return(SqlGeographyConverter.ToSharpMapGeometry(sg));
     }
 }
예제 #23
0
        private IGeometry ToSqlServerAndBack(IGeometry gIn, SqlServerSpatialObjectType spatialType)
        {
            Assert.That(gIn, Is.Not.Null);
            //Assert.That(gIn.SRID, Is.EqualTo(-1));
            //gIn.SRID = 0;
            Assert.That(gIn.SRID, Is.GreaterThan(0));

            switch (spatialType)
            {
            case SqlServerSpatialObjectType.Geography:
                SqlGeography sqlGeography = SqlGeographyConverter.ToSqlGeography(gIn);
                //if (gIn is NetTopologySuite.Geometries.Polygon || gIn is NetTopologySuite.Geometries.MultiPolygon)
                //{
                //    sqlGeography.ReorientObject().MakeValid();
                //}
                return(SqlGeographyConverter.ToSharpMapGeometry(sqlGeography, new NetTopologySuite.Geometries.GeometryFactory()));

            default:
                SqlGeometry sqlGeometry = SqlGeometryConverter.ToSqlGeometry(gIn);
                return(SqlGeometryConverter.ToSharpMapGeometry(sqlGeometry, new NetTopologySuite.Geometries.GeometryFactory()));
            }
        }