/// <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 OracleConnection(ConnectionString)) { string strGeom = "MDSYS.SDO_GEOMETRY('" + geom.AsText() + "', #SRID#)"; strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(Map.NumberFormatEnUs) : "NULL"); strGeom = "SDO_RELATE(g." + GeometryColumn + ", " + strGeom + ", 'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'"; string strSql = "SELECT * FROM " + Table + " g WHERE "; if (!String.IsNullOrEmpty(_definitionQuery)) { strSql += DefinitionQuery + " AND "; } strSql += strGeom; using (var adapter = new OracleDataAdapter(strSql, conn)) { conn.Open(); adapter.Fill(ds); conn.Close(); if (ds.Tables.Count > 0) { var fdt = new FeatureDataTable(ds.Tables[0]); foreach (DataColumn col in ds.Tables[0].Columns) { if (string.Compare(col.ColumnName, GeometryColumn, CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) != 0) { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } foreach (DataRow dr in ds.Tables[0].Rows) { var fdr = fdt.NewRow(); foreach (DataColumn col in ds.Tables[0].Columns) { if (string.Compare(col.ColumnName, GeometryColumn, CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) != 0) { fdr[col.ColumnName] = dr[col]; } } var sdoGeometry = dr[GeometryColumn] as SdoGeometry; if (sdoGeometry != null) { fdr.Geometry = sdoGeometry.AsGeometry(); } fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
/// <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) { //List<Geometry> features = new List<Geometry>(); using (var conn = new SqlConnection(ConnectionString)) { //TODO: Convert to SQL Server string strGeom = _spatialObject + "::STGeomFromText('" + geom.AsText() + "', #SRID#)"; strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString() : "0"); strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1"; string strSQL = "SELECT g.* , g." + GeometryColumn + ".STAsBinary() As sharpmap_tempgeometry FROM " + Table + " g " + BuildTableHints() + " WHERE "; if (!String.IsNullOrEmpty(_definitionQuery)) { strSQL += DefinitionQuery + " AND "; } strSQL += strGeom; string extraOptions = GetExtraOptions(); if (!string.IsNullOrEmpty(extraOptions)) { strSQL += " " + extraOptions; } using (SqlDataAdapter 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 (System.Data.DataColumn col in ds.Tables[0].Columns) { if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry") { 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 && col.ColumnName != "sharpmap_tempgeometry") { fdr[col.ColumnName] = dr[col]; } } fdr.Geometry = Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"], Factory); fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
/// <summary> /// Returns the features that intersects with 'geom' /// </summary> /// <param name="geom"></param> /// <param name="fcs">FeatureDataSet to fill data into</param> /// <param name="cancellationToken">A cancellation token</param> protected override void OnExecuteIntersectionQuery(Geometry geom, IFeatureCollectionSet fcs, CancellationToken?cancellationToken = null) { using (SqlConnection conn = new SqlConnection(ConnectionString)) { string strGeom = SpatialObjectType + "::STGeomFromText('" + geom.AsText() + "', #SRID#)"; strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(NumberFormatInfo.InvariantInfo) : "0"); strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1"; string strSQL = "SELECT g.* FROM " + Table + " g " + BuildTableHints() + " WHERE "; if (!String.IsNullOrEmpty(DefinitionQuery)) { strSQL += DefinitionQuery + " AND "; } strSQL += strGeom; string extraOptions = GetExtraOptions(); if (!string.IsNullOrEmpty(extraOptions)) { strSQL += " " + extraOptions; } var ds = (System.Data.DataSet) new FeatureDataSet(); using (SqlDataAdapter 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 (System.Data.DataColumn col in ds.Tables[0].Columns) { if (col.ColumnName != GeometryColumn) { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } var geometryReader = CreateReader(); 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]; } } fdr.Geometry = geometryReader.Read(dr[GeometryColumn]); fdt.AddRow(fdr); } fcs.Add(fdt); } } } }
/// <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); } } } }
/// <summary> /// Returns the features that intersects with 'geom' /// </summary> /// <param name="geom"></param> /// <param name="fcs">FeatureCollectionSet to fill data into</param> protected override void OnExecuteIntersectionQuery(IGeometry geom, IFeatureCollectionSet fcs, CancellationToken?cancellationToken = null) { using (var conn = new OracleConnection(ConnectionString)) { var strGeom = "MDSYS.SDO_GEOMETRY('" + geom.AsText() + "', #SRID#)"; strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString(Map.NumberFormatEnUs) : "NULL"); strGeom = "SDO_RELATE(g." + GeometryColumn + ", " + strGeom + ", 'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'"; var strSQL = "SELECT g.* , g." + GeometryColumn + ").Get_WKB() As sharpmap_tempgeometry FROM " + Table + " g WHERE "; if (!String.IsNullOrEmpty(_definitionQuery)) { strSQL += DefinitionQuery + " AND "; } strSQL += strGeom; var ds = new FeatureDataSet(); using (var adapter = new OracleDataAdapter(strSQL, conn)) { conn.Open(); adapter.Fill(ds); conn.Close(); if (ds.Tables.Count <= 0) { return; } var fdt = new FeatureDataTable(ds.Tables[0]); foreach (DataColumn col in ds.Tables[0].Columns) { if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry") { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } foreach (DataRow dr in ds.Tables[0].Rows) { var fdr = fdt.NewRow(); foreach (DataColumn col in ds.Tables[0].Columns) { if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry") { fdr[col.ColumnName] = dr[col]; } } fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"], Factory); fdt.AddRow(fdr); } fcs.Add(fdt); } } }
/// <summary> /// Returns geometries within the specified bounding box /// </summary> /// <param name="bbox"></param> /// <returns></returns> public Collection <Geometry> GetGeometriesInView(BoundingBox bbox) { Collection <Geometry> features = new Collection <Geometry>(); using (NpgsqlConnection conn = new NpgsqlConnection(_ConnectionString)) { string strBbox = "box2d('BOX3D(" + bbox.Min.X.ToString(Map.NumberFormatEnUs) + " " + bbox.Min.Y.ToString(Map.NumberFormatEnUs) + "," + bbox.Max.X.ToString(Map.NumberFormatEnUs) + " " + bbox.Max.Y.ToString(Map.NumberFormatEnUs) + ")'::box3d)"; if (SRID > 0) { strBbox = "setSRID(" + strBbox + "," + SRID.ToString(Map.NumberFormatEnUs) + ")"; } string strSQL = "SELECT AsBinary(\"" + GeometryColumn + "\") AS Geom "; strSQL += "FROM " + QualifiedTable + " WHERE "; if (!String.IsNullOrEmpty(_defintionQuery)) { strSQL += DefinitionQuery + " AND "; } if (_SupportSTIntersects) { strSQL += "ST_Intersects(\"" + GeometryColumn + "\"," + strBbox + ")"; } else { strSQL += "\"" + GeometryColumn + "\" && " + strBbox; } #if DEBUG Debug.WriteLine(string.Format("{0}\n{1}", "GetGeometriesInView: executing sql:", strSQL)); #endif using (NpgsqlCommand command = new NpgsqlCommand(strSQL, conn)) { conn.Open(); using (NpgsqlDataReader dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != DBNull.Value) { Geometry geom = GeometryFromWKB.Parse((byte[])dr[0]); if (geom != null) { features.Add(geom); } } } } conn.Close(); } } return(features); }
/// <summary> /// Returns the features that intersects with 'geom' /// </summary> /// <param name="geom"></param> /// <param name="ds">FeatureDataSet to fill data into</param> public void ExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds) { //List<Geometry> features = new List<Geometry>(); using (SqlConnection conn = new SqlConnection(_connectionString)) { //TODO: Convert to SQL Server string strGeom = _spatialObject + "::STGeomFromText('" + geom.AsText() + "', #SRID#)"; strGeom = strGeom.Replace("#SRID#", SRID > 0 ? SRID.ToString() : "0"); strGeom = GeometryColumn + ".STIntersects(" + strGeom + ") = 1"; string strSQL = string.Format("SELECT g.* , g.{0}{1}.STAsBinary() As sharpmap_tempgeometry FROM {2} g WHERE ", GeometryColumn, MakeValidString, Table); if (!String.IsNullOrEmpty(_defintionQuery)) { strSQL += DefinitionQuery + " AND "; } strSQL += strGeom; using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn)) { conn.Open(); System.Data.DataSet ds2 = new System.Data.DataSet(); adapter.Fill(ds2); conn.Close(); if (ds2.Tables.Count > 0) { FeatureDataTable fdt = new FeatureDataTable(ds2.Tables[0]); foreach (System.Data.DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry") { 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 && col.ColumnName != "sharpmap_tempgeometry") { fdr[col.ColumnName] = dr[col]; } } fdr.Geometry = Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]); fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
/// <summary> /// Returns the features that intersects with 'geom' /// </summary> /// <param name="geom"></param> /// <param name="ds">FeatureDataSet to fill data into</param> public void ExecuteIntersectionQuery(Geometry geom, FeatureDataSet ds) { //List<Geometries.Geometry> features = new List<SharpMap.Geometries.Geometry>(); using (PgConnection conn = new PgConnection(_ConnectionString)) { string strGeom = "GeomFromText('" + geom.AsText() + "')"; if (SRID > 0) { strGeom = "setSRID(" + strGeom + "," + SRID.ToString() + ")"; } string strSQL = "SELECT * , AsBinary(" + GeometryColumn + ") As sharpmap_tempgeometry FROM " + Table + " WHERE "; if (!String.IsNullOrEmpty(_defintionQuery)) { strSQL += DefinitionQuery + " AND "; } strSQL += GeometryColumn + " && " + strGeom + " AND distance(" + GeometryColumn + ", " + strGeom + ")<0"; using (PgDataAdapter adapter = new PgDataAdapter(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 != "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 != "sharpmap_tempgeometry") { fdr[col.ColumnName] = dr[col]; } } fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]); fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
/// <summary> /// Returns the box filter string needed in SQL query /// </summary> /// <param name="bbox"></param> /// <returns></returns> protected string GetBoxFilterStr(Envelope bbox) { string strBbox = "SDO_FILTER(g." + GeometryColumn + ", mdsys.sdo_geometry(2003,#SRID#,NULL," + "mdsys.sdo_elem_info_array(1,1003,3)," + "mdsys.sdo_ordinate_array(" + bbox.MinX.ToString(Map.NumberFormatEnUs) + ", " + bbox.MinY.ToString(Map.NumberFormatEnUs) + ", " + bbox.MaxX.ToString(Map.NumberFormatEnUs) + ", " + bbox.MaxY.ToString(Map.NumberFormatEnUs) + ")), " + "'querytype=window') = 'TRUE'"; strBbox = strBbox.Replace("#SRID#", SRID > 0 ? SRID.ToString(Map.NumberFormatEnUs) : "NULL"); return(strBbox); }
internal static string Get(SRID id, params object[] args) { string text = _resourceManager.GetString(id.ToString()); if (string.IsNullOrEmpty(text)) { text = _resourceManager.GetString("Unavailable"); } else if (args != null && args.Length != 0) { text = string.Format(CultureInfo.InvariantCulture, text, args); } return(text); }
/// <summary> /// Returns geometry Object IDs whose bounding box intersects 'bbox' /// </summary> /// <param name="bbox"></param> /// <returns></returns> public Collection <uint> GetObjectIDsInView(BoundingBox bbox) { Collection <uint> objectlist = new Collection <uint>(); using (NpgsqlConnection conn = new NpgsqlConnection(_ConnectionString)) { string strBbox = "box2d('BOX3D(" + bbox.Min.X.ToString(Map.NumberFormatEnUs) + " " + bbox.Min.Y.ToString(Map.NumberFormatEnUs) + "," + bbox.Max.X.ToString(Map.NumberFormatEnUs) + " " + bbox.Max.Y.ToString(Map.NumberFormatEnUs) + ")'::box3d)"; if (SRID > 0) { strBbox = "setSRID(" + strBbox + "," + SRID.ToString(Map.NumberFormatEnUs) + ")"; } string strSQL = "SELECT \"" + ObjectIdColumn + "\" "; strSQL += "FROM " + QualifiedTable + " WHERE "; if (!String.IsNullOrEmpty(_defintionQuery)) { strSQL += DefinitionQuery + " AND "; } strSQL += "\"" + GeometryColumn + "\" && " + strBbox; #if DEBUG Debug.WriteLine(string.Format("{0}\n{1}", "GetObjectIDsInView: executing sql:", strSQL)); #endif using (NpgsqlCommand command = new NpgsqlCommand(strSQL, conn)) { conn.Open(); using (NpgsqlDataReader dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != DBNull.Value) { uint ID = (uint)(int)dr[0]; objectlist.Add(ID); } } } conn.Close(); } } return(objectlist); }
/// <summary> /// Returns the box filter string needed in SQL query /// </summary> /// <param name="bbox"></param> /// <returns></returns> private string GetBoxFilterStr(BoundingBox bbox) { string strBbox = "SDO_FILTER(g." + GeometryColumn + ", mdsys.sdo_geometry(2003,#SRID#,NULL," + "mdsys.sdo_elem_info_array(1,1003,3)," + "mdsys.sdo_ordinate_array(" + bbox.Min.X.ToString(Map.NumberFormatEnUs) + ", " + bbox.Min.Y.ToString(Map.NumberFormatEnUs) + ", " + bbox.Max.X.ToString(Map.NumberFormatEnUs) + ", " + bbox.Max.Y.ToString(Map.NumberFormatEnUs) + ")), " + "'querytype=window') = 'TRUE'"; if (SRID > 0) { strBbox = strBbox.Replace("#SRID#", SRID.ToString(Map.NumberFormatEnUs)); } else { strBbox = strBbox.Replace("#SRID#", "NULL"); } return(strBbox); }
public FeatureDataTable QueryFeatures(Geometry geom, double distance) { //List<Geometries.Geometry> features = new List<SharpMap.Geometries.Geometry>(); using (SqlConnection conn = new SqlConnection(ConnectionString)) { string strGeom; if (TargetSRID > 0 && SRID > 0 && SRID != TargetSRID) { strGeom = "ST.Transform(ST.GeomFromText('" + geom.AsText() + "'," + TargetSRID.ToString() + ")," + SRID.ToString() + ")"; } else { strGeom = "ST.GeomFromText('" + geom.AsText() + "', " + SRID.ToString() + ")"; } string strSQL = "SELECT " + FeatureColumns + ", ST.AsBinary(" + BuildGeometryExpression() + ") As sharpmap_tempgeometry "; strSQL += "FROM ST.IsWithinDistanceQuery" + BuildSpatialQuerySuffix() + "(" + strGeom + ", " + distance.ToString(Map.NumberFormatEnUs) + ")"; if (!String.IsNullOrEmpty(DefinitionQuery)) { strSQL += " WHERE " + DefinitionQuery; } if (!String.IsNullOrEmpty(OrderQuery)) { strSQL += " ORDER BY " + OrderQuery; } using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn)) { DataSet ds = new DataSet(); 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"]); } fdt.AddRow(fdr); } return(fdt); } else { return(null); } } } }
/// <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 void ExecuteIntersectionQuery(BoundingBox bbox, FeatureDataSet ds) { //List<Geometry> features = new List<Geometry>(); using (NpgsqlConnection conn = new NpgsqlConnection(_ConnectionString)) { string strBbox = "box2d('BOX3D(" + bbox.Min.X.ToString(Map.NumberFormatEnUs) + " " + bbox.Min.Y.ToString(Map.NumberFormatEnUs) + "," + bbox.Max.X.ToString(Map.NumberFormatEnUs) + " " + bbox.Max.Y.ToString(Map.NumberFormatEnUs) + ")'::box3d)"; if (SRID > 0) { strBbox = "setSRID(" + strBbox + "," + SRID.ToString(Map.NumberFormatEnUs) + ")"; } string strSQL = "SELECT *, AsBinary(\"" + GeometryColumn + "\") AS sharpmap_tempgeometry "; strSQL += "FROM " + QualifiedTable + " WHERE "; if (!String.IsNullOrEmpty(_defintionQuery)) { strSQL += DefinitionQuery + " AND "; } strSQL += "\"" + GeometryColumn + "\" && " + strBbox; #if DEBUG Debug.WriteLine(string.Format("{0}\n{1}\n", "ExecuteIntersectionQuery: executing sql:", strSQL)); #endif using (NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(strSQL, conn)) { conn.Open(); DataSet ds2 = new DataSet(); adapter.Fill(ds2); conn.Close(); if (ds2.Tables.Count > 0) { FeatureDataTable fdt = new FeatureDataTable(ds2.Tables[0]); foreach (DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry") { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } foreach (DataRow dr in ds2.Tables[0].Rows) { FeatureDataRow fdr = fdt.NewRow(); foreach (DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry") { fdr[col.ColumnName] = dr[col]; } } fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]); fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
/// <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.* , g." + GeometryColumn + ".STAsBinary() As sharpmap_tempgeometry FROM " + QualifiedTable + " g " + BuildTableHints() + " WHERE "; if (!String.IsNullOrEmpty(_definitionQuery)) { strSql += DefinitionQuery + " AND "; } strSql += strGeom; string extraOptions = GetExtraOptions(); if (!string.IsNullOrEmpty(extraOptions)) { strSql += " " + extraOptions; } 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 && col.ColumnName != "sharpmap_tempgeometry") { 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 && col.ColumnName != "sharpmap_tempgeometry") { fdr[col.ColumnName] = dr[col]; } } var tmpGeom = Converters.WellKnownBinary.GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"], Factory); if (tmpGeom != null && _spatialObjectType == SqlServerSpatialObjectType.Geography) { FlipXY(tmpGeom); tmpGeom.GeometryChanged(); } fdr.Geometry = tmpGeom; fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
/// <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 " + 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 += strGeom; string extraOptions = GetExtraOptions(); if (!string.IsNullOrEmpty(extraOptions)) { strSql += " " + extraOptions; } 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 FeatureDataTable QueryFeatures(Geometry geom, double distance) { Collection <Geometry> features = new Collection <Geometry>(); using (PgConnection conn = new PgConnection(_ConnectionString)) { string strGeom = "GeomFromText('" + geom.AsText() + "')"; if (SRID > 0) { strGeom = "setSRID(" + strGeom + "," + SRID.ToString() + ")"; } string strSQL = "SELECT * , AsBinary(" + GeometryColumn + ") As sharpmap_tempgeometry FROM " + Table + " WHERE "; if (!String.IsNullOrEmpty(_defintionQuery)) { strSQL += DefinitionQuery + " AND "; } strSQL += GeometryColumn + " && " + "buffer(" + strGeom + "," + distance.ToString(Map.NumberFormatEnUs) + ")"; strSQL += " AND distance(" + GeometryColumn + ", " + strGeom + ")<" + distance.ToString(Map.NumberFormatEnUs); using (PgDataAdapter adapter = new PgDataAdapter(strSQL, conn)) { DataSet ds = new DataSet(); 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 != "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 != "sharpmap_tempgeometry") { fdr[col.ColumnName] = dr[col]; } } fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]); fdt.AddRow(fdr); } return(fdt); } else { return(null); } } } }
public FeatureDataTable QueryFeatures(Geometry geom, double distance) { //List<Geometries.Geometry> features = new List<SharpMap.Geometries.Geometry>(); using (OracleConnection conn = new OracleConnection(_ConnectionString)) { string strGeom = "MDSYS.SDO_GEOMETRY('" + geom.AsText() + "', #SRID#)"; if (SRID > 0) { strGeom = strGeom.Replace("#SRID#", SRID.ToString(Map.NumberFormatEnUs)); } else { strGeom = strGeom.Replace("#SRID#", "NULL"); } strGeom = "SDO_WITHIN_DISTANCE(g." + GeometryColumn + ", " + strGeom + ", 'distance = " + distance.ToString(Map.NumberFormatEnUs) + "') = 'TRUE'"; string strSQL = "SELECT g.* , g." + GeometryColumn + ").Get_WKB() As sharpmap_tempgeometry FROM " + Table + " g WHERE "; if (!String.IsNullOrEmpty(_defintionQuery)) { strSQL += DefinitionQuery + " AND "; } strSQL += strGeom; using (OracleDataAdapter adapter = new OracleDataAdapter(strSQL, conn)) { DataSet ds = new DataSet(); 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 != "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 != "sharpmap_tempgeometry") { fdr[col.ColumnName] = dr[col]; } } fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]); fdt.AddRow(fdr); } return(fdt); } else { return(null); } } } }