///// <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(IGeometry geom, FeatureDataSet ds) //{ // var features = new List<IGeometry>(); // using (var conn = CreateOpenDbConnection()) // { // string strGeom; // if (TargetSRID > 0 && SRID > 0 && SRID != TargetSRID) // strGeom = "ST.Transform(ST.GeomFromText('" + geom.AsText() + "'," + TargetSRID.ToString(Map.NumberFormatEnUs) + ")," + // SRID.ToString(Map.NumberFormatEnUs) + ")"; // else // strGeom = "ST.GeomFromText('" + geom.AsText() + "', " + SRID.ToString(Map.NumberFormatEnUs) + ")"; // string strSQL = "SELECT " + FeatureColumns + ", ST.AsBinary(" + BuildGeometryExpression() + // ") As sharpmap_tempgeometry "; // strSQL += "FROM ST.RelateQuery" + BuildSpatialQuerySuffix() + "(" + strGeom + ", 'intersects')"; // if (!String.IsNullOrEmpty(DefinitionQuery)) // strSQL += " WHERE " + DefinitionQuery; // if (!String.IsNullOrEmpty(OrderQuery)) // strSQL += " ORDER BY " + OrderQuery; // using (var adapter = new SqlDataAdapter(strSQL, conn)) // { // conn.Open(); // adapter.Fill(ds); // conn.Close(); // if (ds.Tables.Count > 0) // { // FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]); // foreach (DataColumn col in ds.Tables[0].Columns) // if (col.ColumnName != GeometryColumn && // !col.ColumnName.StartsWith(GeometryColumn + "_Envelope_") && // col.ColumnName != "sharpmap_tempgeometry") // fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); // foreach (DataRow dr in ds.Tables[0].Rows) // { // FeatureDataRow fdr = fdt.NewRow(); // foreach (DataColumn col in ds.Tables[0].Columns) // if (col.ColumnName != GeometryColumn && // !col.ColumnName.StartsWith(GeometryColumn + "_Envelope_") && // col.ColumnName != "sharpmap_tempgeometry") // fdr[col.ColumnName] = dr[col]; // if (dr["sharpmap_tempgeometry"] != DBNull.Value) // fdr.Geometry = GeometryFromWKB.Parse((byte[]) dr["sharpmap_tempgeometry"], Factory); // fdt.AddRow(fdr); // } // ds.Tables.Add(fdt); // } // } // } //} ///// <summary> ///// Spacial Reference ID handling ///// </summary> //protected override int SRID //{ // get { return base.SRID; } // set // { // if (SRID == -2) // return; // { // int dotPos = Table.IndexOf("."); // string strSQL = ""; // if (dotPos == -1) // strSQL = "select SRID from ST.GEOMETRY_COLUMNS WHERE F_TABLE_NAME='" + Table + "'"; // else // { // var schema = Table.Substring(0, dotPos); // var table = Table.Substring(dotPos + 1); // strSQL = "select SRID from ST.GEOMETRY_COLUMNS WHERE F_TABLE_SCHEMA='" + schema + // "' AND F_TABLE_NAME='" + table + "'"; // } // using (var conn = (SqlConnection)CreateOpenDbConnection()) // { // using (var command = new SqlCommand(strSQL, conn)) // { // try // { // conn.Open(); // base.SRID = (int) command.ExecuteScalar(); // conn.Close(); // } // catch // { // base.SRID = -1; // } // } // } // } // } //} ///// <summary> ///// Returns a datarow based on a RowID ///// </summary> ///// <param name="rowId"></param> ///// <returns>datarow</returns> //protected override FeatureDataRow GetFeatureInternal(uint rowId) //{ // using (var conn = (SqlConnection)CreateOpenDbConnection()) // { // string strSQL = "select " + FeatureColumns + ", ST.AsBinary(" + BuildGeometryExpression() + // ") As sharpmap_tempgeometry from " + Table + " WHERE " + ObjectIdColumn + "='" + // rowId.ToString() + "'"; // using (var adapter = new SqlDataAdapter(strSQL, conn)) // { // FeatureDataSet ds = new FeatureDataSet(); // conn.Open(); // adapter.Fill(ds); // conn.Close(); // if (ds.Tables.Count > 0) // { // FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]); // foreach (DataColumn col in ds.Tables[0].Columns) // if (col.ColumnName != GeometryColumn && // !col.ColumnName.StartsWith(GeometryColumn + "_Envelope_") && // col.ColumnName != "sharpmap_tempgeometry") // fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); // if (ds.Tables[0].Rows.Count > 0) // { // DataRow dr = ds.Tables[0].Rows[0]; // FeatureDataRow fdr = fdt.NewRow(); // foreach (DataColumn col in ds.Tables[0].Columns) // if (col.ColumnName != GeometryColumn && // !col.ColumnName.StartsWith(GeometryColumn + "_Envelope_") && // col.ColumnName != "sharpmap_tempgeometry") // fdr[col.ColumnName] = dr[col]; // if (dr["sharpmap_tempgeometry"] != DBNull.Value) // fdr.Geometry = GeometryFromWKB.Parse((byte[]) dr["sharpmap_tempgeometry"]); // return fdr; // } // else // return null; // } // else // return null; // } // } //} /// <summary> /// Boundingbox of dataset /// </summary> /// <returns>boundingbox</returns> protected override Envelope GetExtentsInternal() { using (var conn = (SqlConnection)CreateOpenDbConnection()) { #pragma warning disable 612,618 var where = (String.IsNullOrEmpty(DefinitionQuery) ? FeatureColumns.GetWhereClause() : DefinitionQuery).Replace(" WHERE ", "").Replace("'", "''"); #pragma warning restore 612,618 var strSQL = string.Format("SELECT ST.AsBinary(ST.EnvelopeQueryWhere('{0}', '{1}', '{2}'))", DbUtility.DecorateTable(Schema, Table), GeometryColumn, where); using (var command = new SqlCommand(strSQL, conn)) { var result = command.ExecuteScalar(); return(result == DBNull.Value ? null : GeometryFromWKB.Parse((byte[])result, Factory).EnvelopeInternal); } } }