Esempio n. 1
0
mapnik::grid::value_type get_pixel(mapnik::grid const& grid, int x, int y)
{
    if (x < static_cast<int>(grid.width()) && y < static_cast<int>(grid.height()))
    {
        mapnik::grid::data_type const & data = grid.data();
        return data(x,y);
    }
    PyErr_SetString(PyExc_IndexError, "invalid x,y for grid dimensions");
    boost::python::throw_error_already_set();
    return 0;
}
Esempio n. 2
0
int get_pixel(mapnik::grid const& grid, int x, int y)
{
    if (x < static_cast<int>(grid.width()) && y < static_cast<int>(grid.height()))
    {
        mapnik::grid::value_type const * row = grid.getRow(y);
        mapnik::grid::value_type const pixel = row[x];
        return pixel;
    }
    PyErr_SetString(PyExc_IndexError, "invalid x,y for grid dimensions");
    boost::python::throw_error_already_set();
    return 0;
}
void render_layer_for_grid(mapnik::Map const& map,
                                  mapnik::grid & grid,
                                  unsigned layer_idx,
                                  boost::python::list const& fields,
                                  double scale_factor,
                                  unsigned offset_x,
                                  unsigned offset_y)
{
    std::vector<mapnik::layer> const& layers = map.layers();
    std::size_t layer_num = layers.size();
    if (layer_idx >= layer_num) {
        std::ostringstream s;
        s << "Zero-based layer index '" << layer_idx << "' not valid, only '"
          << layer_num << "' layers are in map\n";
        throw std::runtime_error(s.str());
    }

    // convert python list to std::set
    boost::python::ssize_t num_fields = boost::python::len(fields);
    for(boost::python::ssize_t i=0; i<num_fields; i++) {
        boost::python::extract<std::string> name(fields[i]);
        if (name.check())
        {
            grid.add_field(name());
        }
        else
        {
            std::stringstream s;
            s << "list of field names must be strings";
            throw mapnik::value_error(s.str());
        }
    }

    // copy field names
    std::set<std::string> attributes = grid.get_fields();
    // todo - make this a static constant
    std::string known_id_key = "__id__";
    if (attributes.find(known_id_key) != attributes.end())
    {
        attributes.erase(known_id_key);
    }

    std::string join_field = grid.get_key();
    if (known_id_key != join_field &&
        attributes.find(join_field) == attributes.end())
    {
        attributes.insert(join_field);
    }

    mapnik::grid_renderer<mapnik::grid> ren(map,grid,scale_factor,offset_x,offset_y);
    mapnik::layer const& layer = layers[layer_idx];
    ren.apply(layer,attributes);
}
Esempio n. 4
0
bool painted(mapnik::grid const& grid)
{
    return grid.painted();
}