diff --git a/plugins/input/sqlite/sqlite_datasource.cpp b/plugins/input/sqlite/sqlite_datasource.cpp index 496238d6b..1256e5bd0 100644 --- a/plugins/input/sqlite/sqlite_datasource.cpp +++ b/plugins/input/sqlite/sqlite_datasource.cpp @@ -67,6 +67,8 @@ sqlite_datasource::sqlite_datasource(parameters const& params) row_offset_(*params.get("row_offset", 0)), row_limit_(*params.get("row_limit", 0)), intersects_token_("!intersects!"), + pixel_width_token_("!pixel_width!"), + pixel_height_token_("!pixel_height!"), desc_(sqlite_datasource::name(), *params.get("encoding", "utf-8")), format_(mapnik::wkbAuto), twkb_encoding_(false) @@ -217,7 +219,7 @@ sqlite_datasource::sqlite_datasource(parameters const& params) if (using_subquery_) { std::ostringstream s; - std::string query = populate_tokens(table_); + std::string query = populate_tokens(table_, 0, 0); s << "SELECT " << fields_ << " FROM (" << query << ") LIMIT 1"; found_types_via_subquery = sqlite_utils::detect_types_from_subquery( s.str(), @@ -339,7 +341,7 @@ sqlite_datasource::sqlite_datasource(parameters const& params) mapnik::progress_timer __stats2__(std::clog, "sqlite_datasource::init(detect_extent)"); #endif // TODO - clean this up - reducing arguments - std::string query = populate_tokens(table_); + std::string query = populate_tokens(table_, 0, 0); if (!sqlite_utils::detect_extent(dataset_, has_spatial_index_, extent_, @@ -362,7 +364,7 @@ sqlite_datasource::sqlite_datasource(parameters const& params) } -std::string sqlite_datasource::populate_tokens(std::string const& sql) const +std::string sqlite_datasource::populate_tokens(std::string const& sql, double pixel_width, double pixel_height) const { std::string populated_sql = sql; if (boost::algorithm::ifind_first(populated_sql, intersects_token_)) @@ -370,6 +372,18 @@ std::string sqlite_datasource::populate_tokens(std::string const& sql) const // replace with dummy comparison that is true boost::algorithm::ireplace_first(populated_sql, intersects_token_, "1=1"); } + if (boost::algorithm::icontains(sql, pixel_width_token_)) + { + std::ostringstream ss; + ss << pixel_width; + boost::algorithm::replace_all(populated_sql, pixel_width_token_, ss.str()); + } + if (boost::algorithm::icontains(sql, pixel_height_token_)) + { + std::ostringstream ss; + ss << pixel_height; + boost::algorithm::replace_all(populated_sql, pixel_height_token_, ss.str()); + } return populated_sql; } @@ -496,6 +510,10 @@ featureset_ptr sqlite_datasource::features(query const& q) const mapnik::box2d const& e = q.get_bbox(); std::ostringstream s; + + const double px_gw = 1.0 / std::get<0>(q.resolution()); + const double px_gh = 1.0 / std::get<1>(q.resolution()); + mapnik::context_ptr ctx = std::make_shared(); s << "SELECT " << geometry_field_; @@ -530,10 +548,8 @@ featureset_ptr sqlite_datasource::features(query const& q) const geometry_table_, intersects_token_); } - else - { - query = populate_tokens(table_); - } + + query = populate_tokens(query, px_gw, px_gh); s << query ; @@ -611,10 +627,8 @@ featureset_ptr sqlite_datasource::features_at_point(coord2d const& pt, double to geometry_table_, intersects_token_); } - else - { - query = populate_tokens(table_); - } + + query = populate_tokens(query, 0, 0); s << query ; diff --git a/plugins/input/sqlite/sqlite_datasource.hpp b/plugins/input/sqlite/sqlite_datasource.hpp index 0d4151aa8..89cbf0bab 100644 --- a/plugins/input/sqlite/sqlite_datasource.hpp +++ b/plugins/input/sqlite/sqlite_datasource.hpp @@ -62,7 +62,7 @@ private: // Fill init_statements with any statements // needed to attach auxillary databases void parse_attachdb(std::string const& attachdb) const; - std::string populate_tokens(std::string const& sql) const; + std::string populate_tokens(std::string const& sql, double pixel_width, double pixel_height) const; mapnik::box2d extent_; bool extent_initialized_; @@ -80,6 +80,8 @@ private: mapnik::value_integer row_limit_; // TODO - also add to postgis.input const std::string intersects_token_; + const std::string pixel_width_token_; + const std::string pixel_height_token_; mapnik::layer_descriptor desc_; mapnik::wkbFormat format_; bool twkb_encoding_;