Esempio n. 1
0
 private static Geometry ParseOgrGeometry(OgrGeometry ogrGeometry, GeoAPI.Geometries.IGeometryFactory factory)
 {
     if (ogrGeometry != null)
     {
         //Just in case it isn't 2D
         ogrGeometry.FlattenTo2D();
         var wkbBuffer = new byte[ogrGeometry.WkbSize()];
         ogrGeometry.ExportToWkb(wkbBuffer);
         var geom = GeometryFromWKB.Parse(wkbBuffer, factory);
         if (geom == null)
         {
             Debug.WriteLine("Failed to parse '{0}'", ogrGeometry.GetGeometryType());
         }
         return(geom);
     }
     return(null);
 }
Esempio n. 2
0
 public FeatureDataRow GetFeature(uint rowId)
 {
     using (SQLiteConnection conn = SpatiaLiteConnection(_connectionString))
     {
         string strSQL = "SELECT *, AsBinary(" + GeometryColumn + ") AS sharpmap_tempgeometry FROM " + Table +
                         " WHERE " + ObjectIdColumn + "='" + rowId + "'";
         using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(strSQL, conn))
         {
             DataSet ds = new DataSet();
             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" &&
                         !col.ColumnName.StartsWith("Envelope_"))
                     {
                         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 != "sharpmap_tempgeometry" &&
                             !col.ColumnName.StartsWith("Envelope_"))
                         {
                             fdr[col.ColumnName] = dr[col];
                         }
                     }
                     if (dr["sharpmap_tempgeometry"] != DBNull.Value)
                     {
                         fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
                     }
                     return(fdr);
                 }
                 return(null);
             }
             return(null);
         }
     }
 }
        public IFeature GetFeature(int index)
        {
            using (SqlConnection conn = new SqlConnection(this.connectionString))
            {
                int    rowId  = index + 1; // index looks zero-based
                string strSQL = String.Format(
                    "select g.* , g.{0}.STAsBinary() As sharpmap_tempgeometry from {1} g WHERE {2}={3}",
                    this.GeometryColumn, this.Table, this.ObjectIdColumn, rowId);

                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 != this.GeometryColumn && 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 != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdr[col.ColumnName] = dr[col];
                                }
                            }
                            fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
                            return(fdr);
                        }
                        return(null);
                    }
                    return(null);
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Converts an FDO Geometry to a SharpMap geometry
 /// </summary>
 /// <param name="geom">The FDO geometry</param>
 /// <returns></returns>
 public static Sm.Geometry FromFdoGeometry(FdoGeometry geom, OSGeo.FDO.Geometry.FgfGeometryFactory geomFactory)
 {
     if (FdoGeometryUtil.Is2D(geom.InternalInstance))
     {
         //Get the WKB form of the geometry
         byte[] wkb = FdoGeometryFactory.Instance.GetWkb(geom.InternalInstance);
         return(GeometryFromWKB.Parse(wkb));
     }
     else
     {
         using (OSGeo.FDO.Geometry.IGeometry flattened = FdoGeometryUtil.Flatten(geom.InternalInstance, geomFactory))
         {
             //Get the WKB form of the geometry
             byte[] wkb = FdoGeometryFactory.Instance.GetWkb(flattened);
             return(GeometryFromWKB.Parse(wkb));
         }
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Function to get a specific feature's geometry from the database.
 /// </summary>
 /// <param name="oid">The object id</param>
 /// <returns>A geometry</returns>
 protected virtual IGeometry GetGeometryByIDInternal(uint oid)
 {
     using (var cn = CreateOpenDbConnection())
     {
         using (var cmd = cn.CreateCommand())
         {
             cmd.CommandText = FeatureColumns.GetSelectColumnClause(cmd, ObjectIdColumn, oid);
             using (var dr = cmd.ExecuteReader())
             {
                 if (dr.HasRows)
                 {
                     var geometry = GeometryFromWKB.Parse((byte[])dr.GetValue(0), Factory);
                     return(geometry);
                 }
             }
         }
     }
     return(null);
 }
Esempio n. 6
0
        public void Convert()
        {
            IGeometry gML0 = GeometryFromWKT.Parse(multiLinestring);
            IGeometry gLi0 = GeometryFromWKT.Parse(linestring);
            IGeometry gPl0 = GeometryFromWKT.Parse(polygon);
            IGeometry gPn0 = GeometryFromWKT.Parse(point);
            IGeometry gMp0 = GeometryFromWKT.Parse(multipoint);
            IGeometry gML1 = GeometryFromWKB.Parse(gML0.AsBinary());
            IGeometry gLi1 = GeometryFromWKB.Parse(gLi0.AsBinary());
            IGeometry gPl1 = GeometryFromWKB.Parse(gPl0.AsBinary());
            IGeometry gPn1 = GeometryFromWKB.Parse(gPn0.AsBinary());
            IGeometry gMp1 = GeometryFromWKB.Parse(gMp0.AsBinary());

            Assert.AreEqual(gML0, gML1);
            Assert.AreEqual(gLi0, gLi1);
            Assert.AreEqual(gPl0, gPl1);
            Assert.AreEqual(gPn0, gPn1);
            Assert.AreEqual(gMp0, gMp1);
        }
Esempio n. 7
0
        /// <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 OracleConnection(ConnectionString))
            {
                //Get bounding box string
                string strBbox = GetBoxFilterStr(bbox);

                //string strSQL = "SELECT AsBinary(" + this.GeometryColumn + ") AS Geom ";
                string strSQL = "SELECT g." + GeometryColumn + ".Get_WKB() ";
                strSQL += " FROM " + Table + " g WHERE ";

                if (!String.IsNullOrEmpty(_definitionQuery))
                {
                    strSQL += DefinitionQuery + " AND ";
                }

                strSQL += strBbox;

                using (OracleCommand command = new OracleCommand(strSQL, conn))
                {
                    conn.Open();
                    using (OracleDataReader dr = command.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (dr[0] != DBNull.Value)
                            {
                                Geometry geom = GeometryFromWKB.Parse((byte[])dr[0], Factory);
                                if (geom != null)
                                {
                                    features.Add(geom);
                                }
                            }
                        }
                    }
                    conn.Close();
                }
            }
            return(features);
        }
Esempio n. 8
0
        ///// <summary>
        ///// Spacial Reference ID
        ///// </summary>
        //public int SRID
        //{
        //    get
        //    {
        //        if (_srid == -2)
        //        {
        //            string strSQL = "select SRID from USER_SDO_GEOM_METADATA WHERE TABLE_NAME='" + Table + "'";

        //            using (OracleConnection conn = new OracleConnection(ConnectionString))
        //            {
        //                using (OracleCommand command = new OracleCommand(strSQL, conn))
        //                {
        //                    try
        //                    {
        //                        conn.Open();
        //                        _srid = (int) (decimal) command.ExecuteScalar();
        //                        conn.Close();
        //                    }
        //                    catch
        //                    {
        //                        _srid = -1;
        //                    }
        //                }
        //            }
        //        }
        //        return _srid;
        //    }
        //    set { throw (new ApplicationException("Spatial Reference ID cannot by set on a Oracle table")); }
        //}


        /// <summary>
        /// Returns a datarow based on a RowID
        /// </summary>
        /// <param name="oid"></param>
        /// <returns>datarow</returns>
        public override IFeature GetFeatureByOid(object oid)
        {
            using (var conn = new OracleConnection(ConnectionString))
            {
                string strSQL = "select g.* , g." + GeometryColumn + ").Get_WKB() As sharpmap_tempgeometry from " +
                                Table + " g WHERE " + ObjectIdColumn + "=:POid";
                using (var adapter = new OracleDataAdapter(strSQL, conn))
                {
                    adapter.SelectCommand.Parameters.Add("POid", oid);
                    var ds = new FeatureDataSet();
                    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 (col.ColumnName != GeometryColumn && 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];
                            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);
                            return(fdr);
                        }
                    }
                    return(null);
                }
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Boundingbox of dataset
 /// </summary>
 /// <returns>boundingbox</returns>
 public BoundingBox GetExtents()
 {
     using (SqlConnection conn = new SqlConnection(_ConnectionString))
     {
         string strSQL = string.Format("SELECT ST.AsBinary(ST.EnvelopeQueryWhere('{0}', '{1}', '{2}'))", Table,
                                       GeometryColumn, DefinitionQuery.Replace("'", "''"));
         using (SqlCommand command = new SqlCommand(strSQL, conn))
         {
             conn.Open();
             object result = command.ExecuteScalar();
             conn.Close();
             if (result == DBNull.Value)
             {
                 return(null);
             }
             BoundingBox bbox = GeometryFromWKB.Parse((byte[])result).GetBoundingBox();
             return(bbox);
         }
     }
 }
Esempio n. 10
0
        public void Convert()
        {
            var gPn0 = GeometryFromWKT.Parse(point);
            var gMp0 = GeometryFromWKT.Parse(multipoint);
            var gLi0 = GeometryFromWKT.Parse(linestring);
            var gML0 = GeometryFromWKT.Parse(multiLinestring);
            var gPl0 = GeometryFromWKT.Parse(polygon);

            var gPn1 = GeometryFromWKB.Parse(gPn0.AsBinary(), gPn0.Factory);
            var gMp1 = GeometryFromWKB.Parse(gMp0.AsBinary(), gPn0.Factory);
            var gLi1 = GeometryFromWKB.Parse(gLi0.AsBinary(), gPn0.Factory);
            var gML1 = GeometryFromWKB.Parse(gML0.AsBinary(), gPn0.Factory);
            var gPl1 = GeometryFromWKB.Parse(gPl0.AsBinary(), gPn0.Factory);

            Assert.IsTrue(gPn0.EqualsExact(gPn1));
            Assert.IsTrue(gMp0.EqualsExact(gMp1));
            Assert.IsTrue(gLi0.EqualsExact(gLi1));
            Assert.IsTrue(gML0.EqualsExact(gML1));
            Assert.IsTrue(gPl0.EqualsExact(gPl1));
        }
Esempio n. 11
0
        /// <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 (SqlConnection conn = new SqlConnection(_ConnectionString))
            {
                string strSQL = "SELECT ST.AsBinary(" + BuildGeometryExpression() + ") ";
                strSQL += "FROM ST.FilterQuery" + BuildSpatialQuerySuffix() + "(" + BuildEnvelope(bbox) + ")";

                if (!String.IsNullOrEmpty(DefinitionQuery))
                {
                    strSQL += " WHERE " + DefinitionQuery;
                }

                if (!String.IsNullOrEmpty(OrderQuery))
                {
                    strSQL += " ORDER BY " + OrderQuery;
                }

                using (SqlCommand command = new SqlCommand(strSQL, conn))
                {
                    conn.Open();
                    using (SqlDataReader 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);
        }
Esempio n. 12
0
        public void TestHugeGeometryCollection()
        {
            IGeometry geom = null;

            if (!File.Exists("TestData\\Base 64.txt"))
            {
                throw new IgnoreException("Test file not present!", new FileNotFoundException("TestData\\Base 64.txt"));
            }

            using (var sr = new StreamReader("TestData\\Base 64.txt"))
            {
                var sb = new StringBuilder(sr.ReadLine());
                while (!sr.EndOfStream)
                {
                    sb.AppendLine(sr.ReadLine());
                }
                var wkb = System.Convert.FromBase64String(sb.ToString());
                Assert.DoesNotThrow(() => geom = GeometryFromWKB.Parse(wkb, new GeometryFactory()));
            }
            Assert.IsTrue(geom.OgcGeometryType == OgcGeometryType.GeometryCollection);
        }
Esempio n. 13
0
        /// <summary>
        /// Returns geometries within the specified bounding box
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns></returns>
        public override IEnumerable <IGeometry> GetGeometriesInView(Envelope bbox, CancellationToken?cancellationToken = null)
        {
            using (var conn = new OracleConnection(ConnectionString))
            {
                //Get bounding box string
                string strBbox = GetBoxFilterStr(bbox);

                //string strSQL = "SELECT AsBinary(" + this.GeometryColumn + ") AS Geom ";
                string strSQL = "SELECT g." + GeometryColumn + ".Get_WKB() ";
                strSQL += " FROM " + Table + " g WHERE ";

                if (!String.IsNullOrEmpty(_definitionQuery))
                {
                    strSQL += DefinitionQuery + " AND ";
                }

                strSQL += strBbox;

                using (var command = new OracleCommand(strSQL, conn))
                {
                    conn.Open();
                    using (var dr = command.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (!dr.IsDBNull(0))
                            {
                                var geom = GeometryFromWKB.Parse((byte[])dr[0], Factory);
                                if (geom != null)
                                {
                                    yield return(geom);
                                }
                            }
                        }
                    }
                    conn.Close();
                }
            }
        }
Esempio n. 14
0
        ///// <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)*/ /* 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);
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Returns geometries within the specified bounding box
        /// </summary>
        /// <param name="bbox"></param>
        /// <returns></returns>
        public Collection <IGeometry> GetGeometriesInView(Envelope bbox)
        {
            var features = new Collection <IGeometry>();

            using (var conn = new SqlConnection(_connectionString))
            {
                var boxIntersect = GetBoxClause(bbox);

                var strSql = "SELECT " + GeometryColumn + " AS Geom ";
                strSql += "FROM " + Table + " WHERE ";
                strSql += boxIntersect;
                if (!String.IsNullOrEmpty(_definitionQuery))
                {
                    strSql += " AND " + DefinitionQuery;
                }

                using (var command = new SqlCommand(strSql, conn))
                {
                    conn.Open();
                    using (var dr = command.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (dr[0] != DBNull.Value)
                            {
                                var geom = GeometryFromWKB.Parse((byte[])dr[0], Factory);
                                if (geom != null)
                                {
                                    features.Add(geom);
                                }
                            }
                        }
                    }
                    conn.Close();
                }
            }
            return(features);
        }
Esempio n. 16
0
        /// <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 (SqlConnection conn = new SqlConnection(_ConnectionString))
            {
                string BoxIntersect = GetBoxClause(bbox);

                string strSQL = "SELECT " + GeometryColumn + " AS Geom ";
                strSQL += "FROM " + Table + " WHERE ";
                strSQL += BoxIntersect;
                if (!String.IsNullOrEmpty(_defintionQuery))
                {
                    strSQL += " AND " + DefinitionQuery;
                }

                using (SqlCommand command = new SqlCommand(strSQL, conn))
                {
                    conn.Open();
                    using (SqlDataReader 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);
        }
Esempio n. 17
0
        /// <summary>
        /// Gets the geometries of features that lie within the specified <see cref="GeoAPI.Geometries.Envelope"/>
        /// </summary>
        /// <param name="bbox">The bounding box</param>
        /// <returns>Geometries within the specified <see cref="GeoAPI.Geometries.Envelope"/></returns>
        protected virtual Collection <IGeometry> GetGeometriesInViewInternal(Envelope bbox)
        {
            var res = new Collection <IGeometry>();

            using (var cn = CreateOpenDbConnection())
            {
                using (var cmd = cn.CreateCommand())
                {
                    cmd.CommandText = FeatureColumns.GetSelectColumnClause(cmd, FeatureColumns.GetGeometryColumn(true), GetSpatialWhere(bbox, cmd));
                    using (var dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            while (dr.Read())
                            {
                                res.Add(GeometryFromWKB.Parse((byte[])dr.GetValue(0), Factory));
                            }
                        }
                    }
                }
            }
            return(res);
        }
Esempio n. 18
0
 /// <summary>
 /// Function to get a specific feature's geometry from the database.
 /// </summary>
 /// <param name="oid">The object id</param>
 /// <returns>A geometry</returns>
 protected virtual IGeometry GetGeometryByIDInternal(uint oid)
 {
     using (var cn = CreateOpenDbConnection())
     {
         using (var cmd = cn.CreateCommand())
         {
             cmd.CommandText = FeatureColumns.GetSelectColumnClause(cmd, _geometryColumn, oid);
             Logger.Debug(t => t("Executing query:\n{0}", PrintCommand(cmd)));
             using (var dr = cmd.ExecuteReader())
             {
                 if (dr.HasRows)
                 {
                     while (dr.Read())
                     {
                         var geometry = GeometryFromWKB.Parse((byte[])dr.GetValue(0), Factory);
                         return(geometry);
                     }
                 }
             }
         }
     }
     return(null);
 }
Esempio n. 19
0
        /// <summary>
        /// Gets the geometries of features that lie within the specified <see cref="GeoAPI.Geometries.Envelope"/>
        /// </summary>
        /// <param name="bbox">The bounding box</param>
        /// <returns>Geometries within the specified <see cref="GeoAPI.Geometries.Envelope"/></returns>
        protected virtual Collection <IGeometry> GetGeometriesInViewInternal(Envelope bbox, CancellationToken?cancellationToken = null)
        {
            var res = new Collection <IGeometry>();

            using (var cn = CreateOpenDbConnection())
            {
                using (var cmd = cn.CreateCommand())
                {
                    cmd.CommandText = FeatureColumns.GetSelectColumnClause(cmd, _geometryColumn, GetSpatialWhere(bbox, cmd));
                    Logger.Debug(t => t("Executing query:\n{0}", PrintCommand(cmd)));
                    using (var dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            while (dr.Read())
                            {
                                res.Add(GeometryFromWKB.Parse((byte[])dr.GetValue(0), Factory));
                            }
                        }
                    }
                }
            }
            return(res);
        }
Esempio n. 20
0
        /// <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#)";

                if (SRID > 0)
                {
                    strGeom = strGeom.Replace("#SRID#", SRID.ToString(Map.NumberFormatEnUs));
                }
                else
                {
                    strGeom = strGeom.Replace("#SRID#", "NULL");
                }

                strGeom = "SDO_RELATE(g." + GeometryColumn + ", " + strGeom +
                          ", 'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'";

                string strSQL = "SELECT g.* , g." + GeometryColumn + ").Get_WKB() As sharpmap_tempgeometry 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 (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);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
Esempio n. 21
0
 public static Geometry GeomFromWKB(byte[] WKB)
 {
     return(GeometryFromWKB.Parse(WKB));
 }
Esempio n. 22
0
        public IList GetFeatures(IEnvelope box)
        {
            if (box == null)
            {
                throw new ArgumentNullException("box");
            }

            using (SqlConnection conn = new SqlConnection(this._connectionString))
            {
                string strBbox = this.GetBoxFilterStr(box);
                string strSQL  = String.Format(
                    "SELECT g.*, g.{0}{1}.STAsBinary() AS sharpmap_tempgeometry FROM {2} g WHERE ",
                    //"SELECT g.*, g.{0}{1}.STAsText() AS sharpmap_tempgeometry FROM {2} g WHERE ",
                    this.GeometryColumn, this.MakeValidString, this.Table);
                if (!String.IsNullOrEmpty(this.DefinitionQuery))
                {
                    strSQL += this.DefinitionQuery + " AND ";
                }
                strSQL += strBbox;
                Debug.WriteLine(strSQL);

                Stopwatch watch = new Stopwatch();
                watch.Start();
                try
                {
                    using (SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn))
                    {
                        conn.Open();
                        System.Data.DataSet dataset = new System.Data.DataSet();
                        adapter.Fill(dataset);
                        conn.Close();
                        if (dataset.Tables.Count > 0)
                        {
                            FeatureDataTable fdt = new FeatureDataTable(dataset.Tables[0]);
                            foreach (DataColumn col in dataset.Tables[0].Columns)
                            {
                                if (col.ColumnName != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                {
                                    fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression);
                                }
                            }
                            foreach (DataRow dr in dataset.Tables[0].Rows)
                            {
                                FeatureDataRow fdr = fdt.NewRow();
                                foreach (DataColumn col in dataset.Tables[0].Columns)
                                {
                                    if (col.ColumnName != this.GeometryColumn && col.ColumnName != "sharpmap_tempgeometry")
                                    {
                                        fdr[col.ColumnName] = dr[col];
                                    }
                                }
                                fdr.Geometry = GeometryFromWKB.Parse((byte[])dr["sharpmap_tempgeometry"]);
                                //fdr.Geometry = SharpMap.Converters.WellKnownText.GeometryFromWKT.Parse(dr["sharpmap_tempgeometry"].ToString());
                                fdt.AddRow(fdr);
                            }
                            return(fdt);
                        }
                    }
                    return(null);
                }
                finally
                {
                    watch.Stop();
                    Debug.WriteLine("Elapsed miliseconds: " + watch.ElapsedMilliseconds);
                }
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Returns the data associated with all the geometries that are intersected by 'geom'
        /// </summary>
        /// <param name="spatialWhere">Geometry to intersect with</param>
        /// <param name="fds">FeatureDataSet to fill data into</param>
        protected virtual void ExecuteIntersectionQueryInternal(object spatialWhere, FeatureDataSet fds)
        {
            var fdt = CreateNewTable(true);

            fdt.BeginLoadData();

            using (var cn = CreateOpenDbConnection())
            {
                using (var cmd = cn.CreateCommand())
                {
                    string from = null;

                    var spatialWhereString = string.Empty;
                    var env = spatialWhere as Envelope;

                    if (env != null)
                    {
                        from = GetFrom(env, cmd);
                        spatialWhereString = GetSpatialWhere(env, cmd);
                    }
                    else
                    {
                        var geom = spatialWhere as IGeometry;
                        if (geom != null)
                        {
                            from = GetFrom(geom, cmd);
                            spatialWhereString = GetSpatialWhere(geom, cmd);
                        }
                    }

                    cmd.CommandText = FeatureColumns.GetSelectClause(from)
#pragma warning disable 612,618
                                      + (string.IsNullOrEmpty(DefinitionQuery)
#pragma warning restore 612,618
                               ? FeatureColumns.GetWhereClause(spatialWhereString)
                               : (" WHERE " + _definitionQuery +
                                  (string.IsNullOrEmpty(spatialWhereString)
                                            ? ""
                                            : " AND " + spatialWhereString)))

                                      + FeatureColumns.GetGroupByClause()
                                      + FeatureColumns.GetOrderByClause();

                    var numColumns = fdt.Columns.Count;
                    var geomIndex  = numColumns;

                    Logger.Debug(t => t("Executing query:\n{0}", PrintCommand(cmd)));
                    using (var dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            var data = new object[numColumns + 1];
                            if (dr.GetValues(data) > 0)
                            {
                                var loadData = new object[geomIndex];
                                Array.Copy(data, 0, loadData, 0, geomIndex);
                                var row = (FeatureDataRow)fdt.LoadDataRow(loadData, true);
                                row.Geometry = GeometryFromWKB.Parse((byte[])data[geomIndex], Factory);
                            }
                        }
                    }
                }
            }

            fdt.EndLoadData();

            fds.Tables.Add(fdt);
        }
Esempio n. 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MemoryProvider"/>
 /// </summary>
 /// <param name="wellKnownBinaryGeometry"><see cref="Geometry"/> as Well-known Binary to be included in this datasource</param>
 public MemoryProvider(byte[] wellKnownBinaryGeometry) : this(GeometryFromWKB.Parse(wellKnownBinaryGeometry))
 {
 }
Esempio n. 25
0
        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);
                    }
                }
            }
        }
Esempio n. 26
0
        /// <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 (SqlConnection conn = new SqlConnection(_ConnectionString))
            {
                string strSQL = "SELECT " + FeatureColumns + ", ST.AsBinary(" + BuildGeometryExpression() +
                                ") AS sharpmap_tempgeometry ";
                strSQL += "FROM ST.FilterQuery" + BuildSpatialQuerySuffix() + "(" + BuildEnvelope(bbox) + ")";

                if (!String.IsNullOrEmpty(DefinitionQuery))
                {
                    strSQL += " WHERE " + DefinitionQuery;
                }

                if (!String.IsNullOrEmpty(OrderQuery))
                {
                    strSQL += " ORDER BY " + OrderQuery;
                }

                using (SqlDataAdapter adapter = new SqlDataAdapter(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.StartsWith(GeometryColumn + "_Envelope_") &&
                                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.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);
                        }
                        ds.Tables.Add(fdt);
                    }
                }
            }
        }
Esempio n. 27
0
        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);
                    }
                }
            }
        }
Esempio n. 28
0
 /// <summary>
 ///     Creates a <see cref="Geometry" /> based on a WellKnownBinary byte array
 /// </summary>
 /// <param name="wkb">Well-known Binary</param>
 /// <returns></returns>
 public static Geometry GeomFromWKB(byte[] wkb)
 {
     return(GeometryFromWKB.Parse(wkb));
 }
Esempio n. 29
0
        public FeatureDataTable QueryFeatures(Geometry geom, double distance)
        {
            //Collection<Geometries.Geometry> features = new Collection<SharpMap.Geometries.Geometry>();
            using (NpgsqlConnection conn = new NpgsqlConnection(_ConnectionString))
            {
                string strGeom = "GeomFromText('" + geom.AsText() + "')";
                if (SRID > 0)
                {
                    strGeom = "setSRID(" + strGeom + "," + SRID + ")";
                }

                string strSQL = "SELECT * , AsBinary(\"" + GeometryColumn + "\") As sharpmap_tempgeometry FROM " +
                                QualifiedTable + " 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 (NpgsqlDataAdapter adapter = new NpgsqlDataAdapter(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);
                    }
                }
            }
        }
Esempio n. 30
0
        /// <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);
                    }
                }
            }
        }