-
Notifications
You must be signed in to change notification settings - Fork 7
/
rasterizer_datasource.cpp
72 lines (56 loc) · 1.96 KB
/
rasterizer_datasource.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* rasterizer_datasource.cpp
*
* Created on: Aug 10, 2011
* Author: stella
*/
#include "rasterizer_datasource.hpp"
// Stdlib
#include <math.h>
// Mapnik
#include <mapnik/feature_factory.hpp>
// Local
#include "singleton_featureset.hpp"
rasterizer_datasource::rasterizer_datasource(const mapnik::parameters& params, bool bind):
chained_datasource(params, bind)
{
}
rasterizer_datasource::~rasterizer_datasource()
{
}
int rasterizer_datasource::type() const
{
return datasource::Raster;
}
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));
}
mapnik::featureset_ptr rasterizer_datasource::features_at_point(mapnik::coord2d const& pt) const
{
// Point queries not supported
return mapnik::featureset_ptr();
}