/// <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)); }
public static Geometry Buffer(Geometry g, Double distance) { SqlGeometry sg = SqlGeometryConverter.ToSqlGeometry(g); SqlGeometry sgBuffer = sg.STBuffer(distance); return(SqlGeometryConverter.ToSharpMapGeometry(sgBuffer)); }
public static Geometry ConvexHull(Geometry g) { SqlGeometry sg = SqlGeometryConverter.ToSqlGeometry(g); SqlGeometry sgConvexHull = sg.STConvexHull(); return(SqlGeometryConverter.ToSharpMapGeometry(sgConvexHull)); }
/// <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)); }
public static Geometry Boundary(Geometry g) { SqlGeometry sg = SqlGeometryConverter.ToSqlGeometry(g); SqlGeometry sgBoundary = sg.STBoundary(); return(SqlGeometryConverter.ToSharpMapGeometry(sgBoundary)); }
/// <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))); }
/// <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)); }
private Geometry ToSqlServerAndBack(Geometry gIn) { SqlGeometry sqlGeometry = SqlGeometryConverter.ToSqlGeometry(gIn); Geometry gOut = SqlGeometryConverter.ToSharpMapGeometry(sqlGeometry); return(gOut); }
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)); }
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)); }
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); }
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)); }
/// <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"); }
/// <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"); } }
/// <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"); } }
/// <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))); } }
/// <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)); } }
/// <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)); } }
/// <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)); } }
/// <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)); } }
/// <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)); } }
/// <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)); } }
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())); } }