/// <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 ConvexHull(Geometry g) { SqlGeometry sg = SqlGeometryConverter.ToSqlGeometry(g); SqlGeometry sgConvexHull = sg.STConvexHull(); return(SqlGeometryConverter.ToSharpMapGeometry(sgConvexHull)); }
/// <summary> /// Returns the geometry corresponding to the Object ID /// </summary> /// <param name="oid">Object ID</param> /// <returns>geometry</returns> public override Geometry GetGeometryByID(uint oid) { Geometry geom = null; using (var conn = new SqlConnection(ConnectionString)) { string strSql = "SELECT g." + GeometryColumn + " FROM " + QualifiedTable + " g WHERE " + ObjectIdColumn + "='" + oid + "'"; conn.Open(); using (var command = new SqlCommand(strSql, conn)) { using (SqlDataReader dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != null && dr[0] != DBNull.Value) { geom = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)dr[0]); } } } } conn.Close(); } return(geom); }
public static Geometry Boundary(Geometry g) { SqlGeometry sg = SqlGeometryConverter.ToSqlGeometry(g); SqlGeometry sgBoundary = sg.STBoundary(); return(SqlGeometryConverter.ToSharpMapGeometry(sgBoundary)); }
/// <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)); }
/// <summary> /// Returns all features with the view box /// </summary> /// <param name="bbox">view box</param> /// <param name="ds">FeatureDataSet to fill data into</param> public override void ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds) { using (var conn = new SqlConnection(ConnectionString)) { //Get bounding box string string strBbox = GetBoxFilterStr(bbox); string strSql = String.Format( "SELECT g.* FROM {0} g {1} WHERE ", Table, BuildTableHints()); if (!String.IsNullOrEmpty(DefinitionQuery)) { strSql += DefinitionQuery + " AND "; } strSql += strBbox; using (var adapter = new SqlDataAdapter(strSql, conn)) { conn.Open(); var ds2 = new System.Data.DataSet(); adapter.Fill(ds2); conn.Close(); if (ds2.Tables.Count > 0) { var fdt = new FeatureDataTable(ds2.Tables[0]); foreach (System.Data.DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn) { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } foreach (System.Data.DataRow dr in ds2.Tables[0].Rows) { FeatureDataRow fdr = fdt.NewRow(); foreach (System.Data.DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn) { fdr[col.ColumnName] = dr[col]; } } var geom = dr[GeometryColumn]; Geometry sqlGeometry = null; if (geom != null && geom != DBNull.Value) { sqlGeometry = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)geom); } fdr.Geometry = sqlGeometry; fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
/// <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)); }
public static Geometry Buffer(Geometry g, Double distance) { SqlGeometry sg = SqlGeometryConverter.ToSqlGeometry(g); SqlGeometry sgBuffer = sg.STBuffer(distance); return(SqlGeometryConverter.ToSharpMapGeometry(sgBuffer)); }
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)); }
/// <summary> /// Returns the features that intersects with 'geom' /// </summary> /// <param name="geom"></param> /// <param name="ds">FeatureDataSet to fill data into</param> protected override void OnExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds) { using (var conn = new SqlConnection(ConnectionString)) { string strGeom = SpatialObject + "::STGeomFromText('" + geom.AsText() + "', #SRID#)"; strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(CultureInfo.InvariantCulture) : "0"); strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1"; string strSql = "SELECT g.* FROM " + Table + " g " + BuildTableHints() + " WHERE "; if (!String.IsNullOrEmpty(DefinitionQuery)) { strSql += DefinitionQuery + " AND "; } strSql += strGeom; using (var adapter = new SqlDataAdapter(strSql, conn)) { conn.Open(); adapter.Fill(ds); conn.Close(); if (ds.Tables.Count > 0) { var fdt = new FeatureDataTable(ds.Tables[0]); foreach (System.Data.DataColumn col in ds.Tables[0].Columns) { if (col.ColumnName != GeometryColumn) { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } foreach (System.Data.DataRow dr in ds.Tables[0].Rows) { FeatureDataRow fdr = fdt.NewRow(); foreach (System.Data.DataColumn col in ds.Tables[0].Columns) { if (col.ColumnName != GeometryColumn) { fdr[col.ColumnName] = dr[col]; } } var ogeom = dr[GeometryColumn]; Geometry sqlGeometry = null; if (ogeom != null && ogeom != DBNull.Value) { sqlGeometry = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)ogeom); } fdr.Geometry = sqlGeometry; fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
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)); }
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); }
/// <summary> /// Returns geometries within the specified bounding box /// </summary> /// <param name="bbox"></param> /// <returns></returns> public override Collection <Geometry> GetGeometriesInView(BoundingBox bbox) { var features = new Collection <Geometry>(); using (var conn = new SqlConnection(ConnectionString)) { //Get bounding box string string strBbox = GetBoxFilterStr(bbox); string strSql = "SELECT g." + GeometryColumn + GetMakeValidString(); strSql += " FROM " + QualifiedTable + " g " + BuildTableHints() + " WHERE "; if (!String.IsNullOrEmpty(DefinitionQuery)) { strSql += DefinitionQuery + " AND "; } if (!ValidateGeometries || (SpatialObjectType == SqlServerSpatialObjectType.Geometry && (ForceSeekHint || !string.IsNullOrEmpty(ForceIndex)))) { // Geometry sensitive to invalid geometries, and BuildTableHints (ForceSeekHint, ForceIndex) do not suppport .MakeValid() in GetBoxFilterStr strSql += $"{GeometryColumn}.STIsValid() = 1 AND "; } strSql += strBbox; string extraOptions = GetExtraOptions(); if (!string.IsNullOrEmpty(extraOptions)) { strSql += " " + extraOptions; } using (var command = new SqlCommand(strSql, conn)) { conn.Open(); using (SqlDataReader dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != null && dr[0] != DBNull.Value) { Geometry geom = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)dr[0]); if (geom != null) { features.Add(geom); } } } } conn.Close(); } } return(features); }
/// <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 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 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 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> /// Returns a datarow based on a RowID /// </summary> /// <param name="rowId"></param> /// <returns>datarow</returns> public override FeatureDataRow GetFeature(uint rowId) { using (var conn = new SqlConnection(ConnectionString)) { string strSql = "select g.* from " + QualifiedTable + " g WHERE " + ObjectIdColumn + "=" + rowId + ""; using (var adapter = new SqlDataAdapter(strSql, conn)) { var ds = new System.Data.DataSet(); conn.Open(); adapter.Fill(ds); conn.Close(); if (ds.Tables.Count > 0) { var fdt = new FeatureDataTable(ds.Tables[0]); foreach (System.Data.DataColumn col in ds.Tables[0].Columns) { if (col.ColumnName != GeometryColumn) { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } if (ds.Tables[0].Rows.Count > 0) { System.Data.DataRow dr = ds.Tables[0].Rows[0]; FeatureDataRow fdr = fdt.NewRow(); foreach (System.Data.DataColumn col in ds.Tables[0].Columns) { if (col.ColumnName != GeometryColumn) { fdr[col.ColumnName] = dr[col]; } } var geom = dr[GeometryColumn]; Geometry sqlGeometry = null; if (geom != null && geom != DBNull.Value) { sqlGeometry = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)geom); } fdr.Geometry = sqlGeometry; return(fdr); } return(null); } return(null); } } }
/// <summary> /// Returns geometries within the specified bounding box /// </summary> /// <param name="bbox"></param> /// <returns></returns> public override Collection <Geometry> GetGeometriesInView(BoundingBox bbox) { var features = new Collection <Geometry>(); using (var conn = new SqlConnection(ConnectionString)) { //Get bounding box string string strBbox = GetBoxFilterStr(bbox); string strSql = "SELECT g." + GeometryColumn; strSql += " FROM " + QualifiedTable + " g " + BuildTableHints() + " WHERE "; if (!String.IsNullOrEmpty(DefinitionQuery)) { strSql += DefinitionQuery + " AND "; } strSql += strBbox; string extraOptions = GetExtraOptions(); if (!string.IsNullOrEmpty(extraOptions)) { strSql += " " + extraOptions; } using (var command = new SqlCommand(strSql, conn)) { conn.Open(); using (SqlDataReader dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != null && dr[0] != DBNull.Value) { Geometry geom = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)dr[0]); if (geom != null) { features.Add(geom); } } } } conn.Close(); } } return(features); }
/// <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())); } }
/// <summary> /// Returns all features with the view box /// </summary> /// <param name="bbox">view box</param> /// <param name="ds">FeatureDataSet to fill data into</param> public override void ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds) { using (var conn = new SqlConnection(ConnectionString)) { //Get bounding box string string strBbox = GetBoxFilterStr(bbox); string strSql = String.Format( "SELECT g.* FROM {0} g {1} WHERE ", QualifiedTable, BuildTableHints()); if (!String.IsNullOrEmpty(DefinitionQuery)) { strSql += DefinitionQuery + " AND "; } if (!ValidateGeometries || (SpatialObjectType == SqlServerSpatialObjectType.Geometry && (ForceSeekHint || !string.IsNullOrEmpty(ForceIndex)))) { // Geometry sensitive to invalid geometries, and BuildTableHints (ForceSeekHint, ForceIndex) do not suppport .MakeValid() in GetBoxFilterStr strSql += $"{GeometryColumn}.STIsValid() = 1 AND "; } strSql += strBbox; string extraOptions = GetExtraOptions(); if (!string.IsNullOrEmpty(extraOptions)) { strSql += " " + extraOptions; } using (var adapter = new SqlDataAdapter(strSql, conn)) { conn.Open(); var ds2 = new System.Data.DataSet(); adapter.Fill(ds2); conn.Close(); if (ds2.Tables.Count > 0) { var fdt = new FeatureDataTable(ds2.Tables[0]); foreach (System.Data.DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn) { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } foreach (System.Data.DataRow dr in ds2.Tables[0].Rows) { FeatureDataRow fdr = fdt.NewRow(); foreach (System.Data.DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn) { fdr[col.ColumnName] = dr[col]; } } var geom = dr[GeometryColumn]; Geometry sqlGeometry = null; if (geom != null && geom != DBNull.Value) { sqlGeometry = SqlGeometryConverter.ToSharpMapGeometry((Microsoft.SqlServer.Types.SqlGeometry)geom); } fdr.Geometry = sqlGeometry; fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }