示例#1
0
        /// <summary>
        /// Computes a bounding box which covers all geometries in <see cref="Table"/>.
        /// </summary>
        /// <returns>
        /// The bounding box which describes the maximum extents
        /// of the data retrieved by the data source.
        /// </returns>
        public BoundingBox GetExtents()
        {
            using (PgConnection conn = new PgConnection(_connectionString))
            {
                string sql = String.Format("SELECT EXTENT({0}) FROM {1}",
                                           GeometryColumn,
                                           Table);

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


                sql += ";";

                using (PgCommand command = new PgCommand(sql, conn))
                {
                    conn.Open();

                    BoundingBox bbox;

                    try
                    {
                        PgBox2D result = (PgBox2D)command.ExecuteScalar();
                        bbox =
                            new BoundingBox(result.LowerLeft.X, result.LowerLeft.Y, result.UpperRight.X,
                                            result.UpperRight.Y);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Box2d couldn't fetched from table. ", ex);
                    }
                    finally
                    {
                        conn.Close();
                    }

                    return(bbox);
                }
            }
        }
示例#2
0
        private void obtainSpatialReference()
        {
            // Get the Srid for the table
            string sql = "SELECT srid FROM geometry_columns WHERE f_table_name = @Table";

            using (PgConnection conn = new PgConnection(_connectionString))
            {
                using (PgCommand command = new PgCommand(sql, conn))
                {
                    try
                    {
                        conn.Open();

                        command.Parameters.Add(new PgParameter("@Table", PgDbType.VarChar));
                        command.Parameters[0].Value = Table;

                        _srid = (int)command.ExecuteScalar();
                    }
                    catch (PgException) {}
                }
            }
        }
示例#3
0
        /// <summary>
        /// Returns the number of features in the dataset
        /// </summary>
        /// <returns>number of features</returns>
        public int GetFeatureCount()
        {
            int count;

            using (PgConnection conn = new PgConnection(_connectionString))
            {
                string sql = "SELECT COUNT(*) FROM " + Table;

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

                using (PgCommand command = new PgCommand(sql, conn))
                {
                    conn.Open();
                    count = (int)command.ExecuteScalar();
                    conn.Close();
                }
            }
            return(count);
        }
示例#4
0
        /// <summary>
        /// Queries the PostGIS database to get the name of the Geometry Column. This is used if the columnname isn't specified in the constructor
        /// </summary>
        /// <remarks></remarks>
        /// <returns>Name of column containing geometry</returns>
        private string GetGeometryColumn()
        {
            string strSQL = "select f_geometry_column from geometry_columns WHERE f_table_name = @Table'";

            using (PgConnection conn = new PgConnection(_ConnectionString))
                using (PgCommand command = new PgCommand(strSQL, conn))
                {
                    conn.Open();

                    command.Parameters.Add(new PgParameter("@Table", PgDbType.VarChar));
                    command.Parameters[0].Value = this._Table;

                    object columnname = command.ExecuteScalar();
                    conn.Close();

                    if (columnname == System.DBNull.Value)
                    {
                        throw new ApplicationException("Table '" + this.Table + "' does not contain a geometry column");
                    }
                    return((string)columnname);
                }
        }
示例#5
0
        /// <summary>
        /// Returns the number of features in the dataset
        /// </summary>
        /// <returns>number of features</returns>
        public int GetFeatureCount()
        {
            int count = 0;

            using (PgConnection conn = new PgConnection(_ConnectionString))
            {
                string strSQL = "SELECT COUNT(*) FROM " + this.Table;

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

                using (PgCommand command = new PgCommand(strSQL, conn))
                {
                    conn.Open();
                    count = Convert.ToInt32(command.ExecuteScalar());
                    conn.Close();
                }
            }
            return(count);
        }
示例#6
0
        /// <summary>
        /// Boundingbox of dataset
        /// </summary>
        /// <returns>boundingbox</returns>
        public IEnvelope GetExtents()
        {
            using (PgConnection conn = new PgConnection(_ConnectionString))
            {
                string strSQL = String.Format("SELECT EXTENT({0}) FROM {1}",
                                              this.GeometryColumn,
                                              this.Table);

                if (!String.IsNullOrEmpty(_defintionQuery))
                    strSQL += " WHERE " + this.DefinitionQuery;


                strSQL += ";";

                using (PgCommand command = new PgCommand(strSQL, conn))
                {
                    conn.Open();

                    IEnvelope bbox = null;
                    try
                    {
                        PostgreSql.Data.PgTypes.PgBox2D result = (PostgreSql.Data.PgTypes.PgBox2D)command.ExecuteScalar();
                        bbox = SharpMap.Converters.Geometries.GeometryFactory.CreateEnvelope(result.LowerLeft.X, result.UpperRight.X, result.LowerLeft.Y, result.UpperRight.Y);
                    }
                    catch (System.Exception ex)
                    {
                        throw new Exception("Box2d couldn't fetched from table. " + ex.Message);
                    }
                    finally
                    {
                        conn.Close();
                    }

                    return bbox;
                }
            }
        }
示例#7
0
        /// <summary>
        /// Queries the PostGIS database to get the name of the Geometry Column. This is used if the columnname isn't specified in the constructor
        /// </summary>
        /// <remarks></remarks>
        /// <returns>Name of column containing geometry</returns>
        private string GetGeometryColumn()
        {
            string strSQL = "select f_geometry_column from geometry_columns WHERE f_table_name = @Table'";

            using (PgConnection conn = new PgConnection(_ConnectionString))
            using (PgCommand command = new PgCommand(strSQL, conn))
            {
                conn.Open();

                command.Parameters.Add(new PgParameter("@Table", PgDbType.VarChar));
                command.Parameters[0].Value = this._Table;

                object columnname = command.ExecuteScalar();
                conn.Close();

                if (columnname == System.DBNull.Value)
                    throw new ApplicationException("Table '" + this.Table + "' does not contain a geometry column");
                return (string)columnname;
            }
        }
示例#8
0
        /// <summary>
        /// Returns the number of features in the dataset
        /// </summary>
        /// <returns>number of features</returns>
        public int GetFeatureCount()
        {
            int count = 0;
            using (PgConnection conn = new PgConnection(_ConnectionString))
            {
                string strSQL = "SELECT COUNT(*) FROM " + this.Table;

                if (!String.IsNullOrEmpty(_defintionQuery))
                    strSQL += " WHERE " + this.DefinitionQuery;

                using (PgCommand command = new PgCommand(strSQL, conn))
                {
                    conn.Open();
                    count = (int)command.ExecuteScalar();
                    conn.Close();
                }
            }
            return count;
        }
示例#9
0
        /// <summary>
        /// Boundingbox of dataset
        /// </summary>
        /// <returns>boundingbox</returns>
        public BoundingBox GetExtents()
        {
            using (PgConnection conn = new PgConnection(_ConnectionString))
            {
                string strSQL = String.Format("SELECT EXTENT({0}) FROM {1}",
                                              GeometryColumn,
                                              Table);

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


                strSQL += ";";

                using (PgCommand command = new PgCommand(strSQL, conn))
                {
                    conn.Open();

                    BoundingBox bbox = null;
                    try
                    {
                        PgBox2D result = (PgBox2D) command.ExecuteScalar();
                        bbox = new BoundingBox(result.LowerLeft.X, result.LowerLeft.Y, result.UpperRight.X,
                                               result.UpperRight.Y);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Box2d couldn't fetched from table. " + ex.Message);
                    }
                    finally
                    {
                        conn.Close();
                    }

                    return bbox;
                }
            }
        }
示例#10
0
        /// <summary>
        /// Boundingbox of dataset
        /// </summary>
        /// <returns>boundingbox</returns>
        public SharpMap.Geometries.BoundingBox GetExtents()
        {
            using (PgConnection conn = new PgConnection(_ConnectionString))
            {
                string strSQL = String.Format("SELECT EXTENT({0}) FROM {1}",
                                              this.GeometryColumn,
                                              this.Table);

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


                strSQL += ";";

                using (PgCommand command = new PgCommand(strSQL, conn))
                {
                    conn.Open();

                    SharpMap.Geometries.BoundingBox bbox = null;
                    try
                    {
                        PostgreSql.Data.PgTypes.PgBox2D result = (PostgreSql.Data.PgTypes.PgBox2D)command.ExecuteScalar();
                        bbox = new SharpMap.Geometries.BoundingBox(result.LowerLeft.X, result.LowerLeft.Y, result.UpperRight.X, result.UpperRight.Y);
                    }
                    catch (System.Exception ex)
                    {
                        throw new Exception("Box2d couldn't fetched from table. " + ex.Message);
                    }
                    finally
                    {
                        conn.Close();
                    }

                    return(bbox);
                }
            }
        }