@@ -102,16 +102,27 @@ bool table_is_empty(pg_conn_t const &db_connection, std::string const &schema,
102102tile_extent get_extent_from_db (pg_conn_t const &db_connection,
103103 std::string const &schema,
104104 std::string const &table,
105- std::string const &column, uint32_t zoom)
105+ std::string const &column, bool raster,
106+ uint32_t zoom)
106107{
107108 if (table_is_empty (db_connection, schema, table)) {
108109 return {};
109110 }
110111
111- auto const result = db_connection.exec (
112- " SELECT ST_XMin(e), ST_YMin(e), ST_XMax(e), ST_YMax(e)"
113- " FROM ST_EstimatedExtent('{}', '{}', '{}') AS e" ,
114- schema, table, column);
112+ pg_result_t result;
113+ if (raster) {
114+ result = db_connection.exec (
115+ " SELECT ST_XMin(extent), ST_YMin(extent),"
116+ " ST_XMax(extent), ST_YMax(extent)"
117+ " FROM raster_columns WHERE r_table_schema='{}'"
118+ " AND r_table_name='{}' AND r_raster_column = '{}'" ,
119+ schema, table, column);
120+ } else {
121+ result = db_connection.exec (
122+ " SELECT ST_XMin(e), ST_YMin(e), ST_XMax(e), ST_YMax(e)"
123+ " FROM ST_EstimatedExtent('{}', '{}', '{}') AS e" ,
124+ schema, table, column);
125+ }
115126
116127 if (result.num_tuples () == 0 || result.is_null (0 , 0 )) {
117128 return {};
@@ -135,6 +146,7 @@ tile_extent get_extent_from_db(pg_conn_t const &db_connection,
135146 params_t const ¶ms, uint32_t zoom)
136147{
137148 auto const schema = params.get_string (" schema" , default_schema);
149+
138150 std::string table;
139151 if (params.has (" src_table" )) {
140152 table = params.get_string (" src_table" );
@@ -147,8 +159,15 @@ tile_extent get_extent_from_db(pg_conn_t const &db_connection,
147159 } else {
148160 throw std::runtime_error{" Need 'src_table' or 'src_tables' param." };
149161 }
162+
150163 auto const geom_column = params.get_string (" geom_column" , " geom" );
151- return get_extent_from_db (db_connection, schema, table, geom_column, zoom);
164+ auto const raster_column = params.get_string (" raster_column" , " " );
165+
166+ bool const is_raster = raster_column != " " ;
167+
168+ return get_extent_from_db (db_connection, schema, table,
169+ is_raster ? raster_column : geom_column,
170+ is_raster, zoom);
152171}
153172
154173void get_tiles_from_table (pg_conn_t const &connection, std::string const &table,
0 commit comments