本文整理汇总了C++中mapnik::query类的典型用法代码示例。如果您正苦于以下问题:C++ query类的具体用法?C++ query怎么用?C++ query使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了query类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_feature
feature_ptr rasterlite_featureset::get_feature(mapnik::query const& q)
{
MAPNIK_LOG_DEBUG(rasterlite) << "rasterlite_featureset: Running get_feature";
feature_ptr feature(feature_factory::create(ctx_,1));
double x0, y0, x1, y1;
rasterliteGetExtent (dataset_, &x0, &y0, &x1, &y1);
box2d<double> raster_extent(x0, y0, x1, y1);
box2d<double> intersect = raster_extent.intersect(q.get_bbox());
const int width = static_cast<int>(std::get<0>(q.resolution()) * intersect.width() + 0.5);
const int height = static_cast<int>(std::get<0>(q.resolution()) * intersect.height() + 0.5);
const double pixel_size = (intersect.width() >= intersect.height()) ?
(intersect.width() / (double) width) : (intersect.height() / (double) height);
MAPNIK_LOG_DEBUG(rasterlite) << "rasterlite_featureset: Raster extent=" << raster_extent;
MAPNIK_LOG_DEBUG(rasterlite) << "rasterlite_featureset: View extent=" << q.get_bbox();
MAPNIK_LOG_DEBUG(rasterlite) << "rasterlite_featureset: Intersect extent=" << intersect;
MAPNIK_LOG_DEBUG(rasterlite) << "rasterlite_featureset: Query resolution=" << std::get<0>(q.resolution()) << "," << std::get<1>(q.resolution());
MAPNIK_LOG_DEBUG(rasterlite) << "rasterlite_featureset: Size=" << width << " " << height;
MAPNIK_LOG_DEBUG(rasterlite) << "rasterlite_featureset: Pixel Size=" << pixel_size;
if (width > 0 && height > 0)
{
int size = 0;
void* raster = 0;
if (rasterliteGetRawImageByRect(dataset_,
intersect.minx(),
intersect.miny(),
intersect.maxx(),
intersect.maxy(),
pixel_size,
width,
height,
GAIA_RGBA_ARRAY,
&raster,
&size) == RASTERLITE_OK)
{
if (size > 0)
{
mapnik::image_rgba8 image(width,height);
unsigned char* raster_data = static_cast<unsigned char*>(raster);
std::memcpy(image.bytes(), raster_data, size);
feature->set_raster(std::make_shared<mapnik::raster>(intersect, std::move(image), 1.0));
MAPNIK_LOG_DEBUG(rasterlite) << "rasterlite_featureset: Done";
}
else
{
MAPNIK_LOG_ERROR(rasterlite) << "Rasterlite Plugin: Error " << rasterliteGetLastError (dataset_);
}
}
return feature;
}
return feature_ptr();
}
示例2: features
mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) const
{
// if the query box intersects our world extent then query for features
mapnik::box2d<double> const& box = q.get_bbox();
if (extent_.intersects(box))
{
geojson_featureset::array_type index_array;
if (tree_)
{
tree_->query(boost::geometry::index::intersects(box),std::back_inserter(index_array));
// sort index array to preserve original feature ordering in GeoJSON
std::sort(index_array.begin(),index_array.end(),
[] (item_type const& item0, item_type const& item1)
{
return item0.second.first < item1.second.first;
});
if (cache_features_)
{
return std::make_shared<geojson_featureset>(features_, std::move(index_array));
}
else
{
return std::make_shared<geojson_memory_index_featureset>(filename_, std::move(index_array));
}
}
else if (has_disk_index_)
{
mapnik::filter_in_box filter(q.get_bbox());
return std::make_shared<geojson_index_featureset>(filename_, filter);
}
}
// otherwise return an empty featureset
return mapnik::make_invalid_featureset();
}
示例3: features
mapnik::featureset_ptr csv_datasource::features(mapnik::query const& q) const
{
for (auto const& name : q.property_names())
{
bool found_name = false;
for (auto const& header : headers_)
{
if (header == name)
{
found_name = true;
break;
}
}
if (!found_name)
{
std::ostringstream s;
s << "CSV Plugin: no attribute '" << name << "'. Valid attributes are: "
<< boost::algorithm::join(headers_, ",") << ".";
throw mapnik::datasource_exception(s.str());
}
}
mapnik::box2d<double> const& box = q.get_bbox();
if (extent_.intersects(box))
{
if (tree_)
{
csv_featureset::array_type index_array;
tree_->query(boost::geometry::index::intersects(box),std::back_inserter(index_array));
std::sort(index_array.begin(),index_array.end(),
[] (item_type const& item0, item_type const& item1)
{
return item0.second.first < item1.second.first;
});
if (inline_string_.empty())
{
return std::make_shared<csv_featureset>(filename_, locator_, separator_, quote_, headers_, ctx_, std::move(index_array));
}
else
{
return std::make_shared<csv_inline_featureset>(inline_string_, locator_, separator_, quote_, headers_, ctx_, std::move(index_array));
}
}
else if (has_disk_index_)
{
mapnik::filter_in_box filter(q.get_bbox());
return std::make_shared<csv_index_featureset>(filename_, filter, locator_, separator_, quote_, headers_, ctx_);
}
}
return mapnik::featureset_ptr();
}
示例4: features
virtual mapnik::featureset_ptr features(mapnik::query const& q) const
{
mapnik::box2d<double> const& actual_bbox = q.get_bbox();
REQUIRE(actual_bbox.minx() == Approx(expected_query_bbox_.minx()));
REQUIRE(actual_bbox.miny() == Approx(expected_query_bbox_.miny()));
REQUIRE(actual_bbox.maxx() == Approx(expected_query_bbox_.maxx()));
REQUIRE(actual_bbox.maxy() == Approx(expected_query_bbox_.maxy()));
return mapnik::memory_datasource::features(q);
}
示例5: features
mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) const
{
// if the query box intersects our world extent then query for features
mapnik::box2d<double> const& b = q.get_bbox();
if (extent_.intersects(b))
{
box_type box(point_type(b.minx(),b.miny()),point_type(b.maxx(),b.maxy()));
return std::make_shared<geojson_featureset>(features_, tree_.find(box));
}
// otherwise return an empty featureset pointer
return mapnik::featureset_ptr();
}
示例6: features
mapnik::featureset_ptr topojson_datasource::features(mapnik::query const& q) const
{
// if the query box intersects our world extent then query for features
mapnik::box2d<double> const& box = q.get_bbox();
if (extent_.intersects(box))
{
topojson_featureset::array_type index_array;
if (tree_)
{
tree_->query(boost::geometry::index::intersects(box),std::back_inserter(index_array));
return std::make_shared<topojson_featureset>(topo_, *tr_, std::move(index_array));
}
}
// otherwise return an empty featureset pointer
return mapnik::featureset_ptr();
}
示例7: features
mapnik::featureset_ptr python_datasource::features(mapnik::query const& q) const
{
try
{
// if the query box intersects our world extent then query for features
if (envelope().intersects(q.get_bbox()))
{
ensure_gil lock;
boost::python::object features(datasource_.attr("features")(q));
// if 'None' was returned, return an empty feature set
if(features.ptr() == boost::python::object().ptr())
{
return mapnik::featureset_ptr();
}
return std::make_shared<python_featureset>(features);
}
// otherwise return an empty featureset pointer
return mapnik::featureset_ptr();
}
catch ( boost::python::error_already_set )
{
throw mapnik::datasource_exception(extractException());
}
}
示例8: features
mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) const
{
// if the query box intersects our world extent then query for features
mapnik::box2d<double> const& b = q.get_bbox();
if (extent_.intersects(b))
{
box_type box(point_type(b.minx(),b.miny()),point_type(b.maxx(),b.maxy()));
#if BOOST_VERSION >= 105600
geojson_featureset::array_type index_array;
if (tree_)
{
tree_->query(boost::geometry::index::intersects(box),std::back_inserter(index_array));
return std::make_shared<geojson_featureset>(features_, std::move(index_array));
}
#else
if (tree_)
{
return std::make_shared<geojson_featureset>(features_, tree_->find(box));
}
#endif
}
// otherwise return an empty featureset pointer
return mapnik::featureset_ptr();
}
示例9: get_feature
feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
{
feature_ptr feature = feature_factory::create(ctx_,1);
GDALRasterBand * red = 0;
GDALRasterBand * green = 0;
GDALRasterBand * blue = 0;
GDALRasterBand * alpha = 0;
GDALRasterBand * grey = 0;
/*
#ifdef MAPNIK_LOG
double tr[6];
dataset_.GetGeoTransform(tr);
const double dx = tr[1];
const double dy = tr[5];
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: dx_=" << dx_ << " dx=" << dx << " dy_=" << dy_ << "dy=" << dy;
#endif
*/
CoordTransform t(raster_width_, raster_height_, raster_extent_, 0, 0);
box2d<double> intersect = raster_extent_.intersect(q.get_bbox());
box2d<double> box = t.forward(intersect);
//size of resized output pixel in source image domain
double margin_x = 1.0 / (fabs(dx_) * boost::get<0>(q.resolution()));
double margin_y = 1.0 / (fabs(dy_) * boost::get<1>(q.resolution()));
if (margin_x < 1)
{
margin_x = 1.0;
}
if (margin_y < 1)
{
margin_y = 1.0;
}
//select minimum raster containing whole box
int x_off = rint(box.minx() - margin_x);
int y_off = rint(box.miny() - margin_y);
int end_x = rint(box.maxx() + margin_x);
int end_y = rint(box.maxy() + margin_y);
//clip to available data
if (x_off < 0)
{
x_off = 0;
}
if (y_off < 0)
{
y_off = 0;
}
if (end_x > (int)raster_width_)
{
end_x = raster_width_;
}
if (end_y > (int)raster_height_)
{
end_y = raster_height_;
}
int width = end_x - x_off;
int height = end_y - y_off;
// don't process almost invisible data
if (box.width() < 0.5)
{
width = 0;
}
if (box.height() < 0.5)
{
height = 0;
}
//calculate actual box2d of returned raster
box2d<double> feature_raster_extent(x_off, y_off, x_off + width, y_off + height);
intersect = t.backward(feature_raster_extent);
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Raster extent=" << raster_extent_;
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: View extent=" << intersect;
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Query resolution=" << boost::get<0>(q.resolution()) << "," << boost::get<1>(q.resolution());
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: StartX=" << x_off << " StartY=" << y_off << " Width=" << width << " Height=" << height;
if (width > 0 && height > 0)
{
double width_res = boost::get<0>(q.resolution());
double height_res = boost::get<1>(q.resolution());
int im_width = int(width_res * intersect.width() + 0.5);
int im_height = int(height_res * intersect.height() + 0.5);
// if layer-level filter_factor is set, apply it
if (filter_factor_)
{
im_width *= filter_factor_;
im_height *= filter_factor_;
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Applying layer filter_factor=" << filter_factor_;
}
// otherwise respect symbolizer level factor applied to query, default of 1.0
else
{
//.........这里部分代码省略.........
示例10: get_feature
feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
{
feature_ptr feature = feature_factory::create(ctx_,1);
int raster_has_nodata = 0;
double raster_nodata = 0;
GDALRasterBand * red = 0;
GDALRasterBand * green = 0;
GDALRasterBand * blue = 0;
GDALRasterBand * alpha = 0;
GDALRasterBand * grey = 0;
CPLErr raster_io_error = CE_None;
/*
#ifdef MAPNIK_LOG
double tr[6];
dataset_.GetGeoTransform(tr);
const double dx = tr[1];
const double dy = tr[5];
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: dx_=" << dx_ << " dx=" << dx << " dy_=" << dy_ << "dy=" << dy;
#endif
*/
view_transform t(raster_width_, raster_height_, raster_extent_, 0, 0);
box2d<double> intersect = raster_extent_.intersect(q.get_bbox());
box2d<double> box = t.forward(intersect);
//size of resized output pixel in source image domain
double margin_x = 1.0 / (std::fabs(dx_) * std::get<0>(q.resolution()));
double margin_y = 1.0 / (std::fabs(dy_) * std::get<1>(q.resolution()));
if (margin_x < 1)
{
margin_x = 1.0;
}
if (margin_y < 1)
{
margin_y = 1.0;
}
//select minimum raster containing whole box
int x_off = rint(box.minx() - margin_x);
int y_off = rint(box.miny() - margin_y);
int end_x = rint(box.maxx() + margin_x);
int end_y = rint(box.maxy() + margin_y);
//clip to available data
if (x_off < 0)
{
x_off = 0;
}
if (y_off < 0)
{
y_off = 0;
}
if (end_x > (int)raster_width_)
{
end_x = raster_width_;
}
if (end_y > (int)raster_height_)
{
end_y = raster_height_;
}
int width = end_x - x_off;
int height = end_y - y_off;
// don't process almost invisible data
if (box.width() < 0.5)
{
width = 0;
}
if (box.height() < 0.5)
{
height = 0;
}
//calculate actual box2d of returned raster
box2d<double> feature_raster_extent(x_off, y_off, x_off + width, y_off + height);
intersect = t.backward(feature_raster_extent);
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Raster extent=" << raster_extent_;
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: View extent=" << intersect;
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: Query resolution=" << std::get<0>(q.resolution()) << "," << std::get<1>(q.resolution());
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: StartX=" << x_off << " StartY=" << y_off << " Width=" << width << " Height=" << height;
if (width > 0 && height > 0)
{
double width_res = std::get<0>(q.resolution());
double height_res = std::get<1>(q.resolution());
int im_width = int(width_res * intersect.width() + 0.5);
int im_height = int(height_res * intersect.height() + 0.5);
double filter_factor = q.get_filter_factor();
im_width = int(im_width * filter_factor + 0.5);
im_height = int(im_height * filter_factor + 0.5);
// case where we need to avoid upsampling so that the
// image can be later scaled within raster_symbolizer
if (im_width >= width || im_height >= height)
{
im_width = width;
//.........这里部分代码省略.........
示例11: features
mapnik::featureset_ptr rasterizer_datasource::features(const mapnik::query& q) const
{
std::clog << "Rasterizer::features"
<< ", resolution_type=(" << q.resolution().head << "," << q.resolution().tail.head << ")"
<< ", scale_denominator=" << q.scale_denominator()
<< ", bbox=[" << q.get_bbox().minx() << "," << q.get_bbox().miny() << "," << q.get_bbox().maxx() << "," << q.get_bbox().maxy() << "]"
<< std::endl;
double resx=q.resolution().head,
resy=q.resolution().tail.head,
bbox_width=q.get_bbox().width(),
bbox_height=q.get_bbox().height();
int pixel_width=round(bbox_width * resx),
pixel_height=round(bbox_height * resy);
if (pixel_width<=0 || pixel_height<=0) {
std::clog << "Illegal rasterizer display metrics" << std::endl;
return mapnik::featureset_ptr();
}
std::clog << "Rasterizer generating image of size (" << pixel_width << "," << pixel_height << ")" << std::endl;
// Setup for render
mapnik::feature_ptr feature(mapnik::feature_factory::create(1));
mapnik::image_data_32 image(pixel_width, pixel_height);
rasterize_params params(q, image);
rasterize(params);
// Prepare and return the raster feature
feature->set_raster(boost::make_shared<mapnik::raster>(q.get_bbox(), image));
return boost::make_shared<singleton_featureset>(singleton_featureset(feature));
}
示例12: get_feature
feature_ptr rasterlite_featureset::get_feature(mapnik::query const& q)
{
#ifdef MAPNIK_DEBUG
std::clog << "Rasterlite Plugin: get_feature" << "\n";
#endif
feature_ptr feature(new Feature(1));
double x0, y0, x1, y1;
rasterliteGetExtent (dataset_, &x0, &y0, &x1, &y1);
box2d<double> raster_extent(x0,y0,x1,y1);
box2d<double> intersect = raster_extent.intersect(q.get_bbox());
int width = static_cast<int>(q.resolution() * intersect.width() + 0.5);
int height = static_cast<int>(q.resolution() * intersect.height() + 0.5);
double pixel_size = (intersect.width() >= intersect.height()) ?
(intersect.width() / (double) width) : (intersect.height() / (double) height);
#ifdef MAPNIK_DEBUG
std::clog << "Rasterlite Plugin: Raster extent=" << raster_extent << "\n";
std::clog << "Rasterlite Plugin: View extent=" << q.get_bbox() << "\n";
std::clog << "Rasterlite Plugin: Intersect extent=" << intersect << "\n";
std::clog << "Rasterlite Plugin: Query resolution=" << q.resolution() << "\n";
std::clog << "Rasterlite Plugin: Size=" << width << " " << height << "\n";
std::clog << "Rasterlite Plugin: Pixel Size=" << pixel_size << "\n";
#endif
if (width > 0 && height > 0)
{
int size;
void *raster;
if (rasterliteGetRawImageByRect(dataset_,
intersect.minx(), intersect.miny(), intersect.maxx(), intersect.maxy(),
pixel_size, width, height, GAIA_RGBA_ARRAY, &raster, &size) == RASTERLITE_OK)
{
if (size > 0)
{
mapnik::image_data_32 image(width, height);
image.set(0xffffffff);
unsigned char* raster_data = static_cast<unsigned char*>(raster);
unsigned char* image_data = image.getBytes();
memcpy (image_data, raster_data, size);
feature->set_raster(mapnik::raster_ptr(new mapnik::raster(intersect,image)));
free (raster);
#ifdef MAPNIK_DEBUG
std::clog << "Rasterlite Plugin: Done" << "\n";
#endif
}
else
{
#ifdef MAPNIK_DEBUG
std::clog << "Rasterlite Plugin: Error=" << rasterliteGetLastError (dataset_) << "\n";
#endif
}
}
return feature;
}
return feature_ptr();
}
示例13: get_feature
feature_ptr gdal_featureset::get_feature(mapnik::query const& q)
{
feature_ptr feature(new Feature(1));
GDALRasterBand * red = 0;
GDALRasterBand * green = 0;
GDALRasterBand * blue = 0;
GDALRasterBand * alpha = 0;
GDALRasterBand * grey = 0;
/*
double tr[6];
dataset_.GetGeoTransform(tr);
double dx = tr[1];
double dy = tr[5];
std::clog << "dx_: " << dx_ << " dx: " << dx << " dy_: " << dy_ << "dy: " << dy << "\n";
*/
CoordTransform t(raster_width_,raster_height_,raster_extent_,0,0);
box2d<double> intersect = raster_extent_.intersect(q.get_bbox());
box2d<double> box = t.forward(intersect);
//size of resized output pixel in source image domain
double margin_x = 1.0/(fabs(dx_)*boost::get<0>(q.resolution()));
double margin_y = 1.0/(fabs(dy_)*boost::get<1>(q.resolution()));
if (margin_x < 1)
margin_x = 1.0;
if (margin_y < 1)
margin_y = 1.0;
//select minimum raster containing whole box
int x_off = rint(box.minx() - margin_x);
int y_off = rint(box.miny() - margin_y);
int end_x = rint(box.maxx() + margin_x);
int end_y = rint(box.maxy() + margin_y);
//clip to available data
if (x_off < 0)
x_off = 0;
if (y_off < 0)
y_off = 0;
if (end_x > (int)raster_width_)
end_x = raster_width_;
if (end_y > (int)raster_height_)
end_y = raster_height_;
int width = end_x - x_off;
int height = end_y - y_off;
// don't process almost invisible data
if (box.width() < 0.5)
width = 0;
if (box.height() < 0.5)
height = 0;
//calculate actual box2d of returned raster
box2d<double> feature_raster_extent(x_off, y_off, x_off+width, y_off+height);
intersect = t.backward(feature_raster_extent);
#ifdef MAPNIK_DEBUG
std::clog << "GDAL Plugin: Raster extent=" << raster_extent_ << std::endl;
std::clog << "GDAL Plugin: View extent=" << intersect << std::endl;
std::clog << "GDAL Plugin: Query resolution=" << boost::get<0>(q.resolution()) << "," << boost::get<1>(q.resolution()) << std::endl;
std::clog << boost::format("GDAL Plugin: StartX=%d StartY=%d Width=%d Height=%d") % x_off % y_off % width % height << std::endl;
#endif
if (width > 0 && height > 0)
{
double width_res = boost::get<0>(q.resolution());
double height_res = boost::get<1>(q.resolution());
int im_width = int(width_res * intersect.width() + 0.5);
int im_height = int(height_res * intersect.height() + 0.5);
// if layer-level filter_factor is set, apply it
if (filter_factor_)
{
im_width *= filter_factor_;
im_height *= filter_factor_;
}
// otherwise respect symbolizer level factor applied to query, default of 1.0
else
{
double sym_downsample_factor = q.get_filter_factor();
im_width *= sym_downsample_factor;
im_height *= sym_downsample_factor;
}
// case where we need to avoid upsampling so that the
// image can be later scaled within raster_symbolizer
if (im_width >= width || im_height >= height)
{
im_width = width;
im_height = height;
}
if (im_width > 0 && im_height > 0)
{
mapnik::image_data_32 image(im_width, im_height);
image.set(0xffffffff);
#ifdef MAPNIK_DEBUG
std::clog << "GDAL Plugin: Image Size=(" << im_width << "," << im_height << ")" << std::endl;
std::clog << "GDAL Plugin: Reading band " << band_ << std::endl;
#endif
//.........这里部分代码省略.........