static void grid2utf2(T const& grid_type, boost::python::list& l, std::vector<typename T::lookup_type>& key_order, unsigned int resolution) { typename T::data_type const& data = grid_type.data(); typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys(); typename T::key_type keys; typename T::key_type::const_iterator key_pos; typename T::feature_key_type::const_iterator feature_pos; // start counting at utf8 codepoint 32, aka space character uint16_t codepoint = 32; mapnik::grid::data_type target(data.width()/resolution,data.height()/resolution); mapnik::scale_grid(target,grid_type.data(),0.0,0.0); unsigned array_size = target.width(); for (unsigned y = 0; y < target.height(); ++y) { uint16_t idx = 0; boost::scoped_array<Py_UNICODE> line(new Py_UNICODE[array_size]); mapnik::grid::value_type * row = target.getRow(y); unsigned x; for (x = 0; x < target.width(); ++x) { feature_pos = feature_keys.find(row[x]); if (feature_pos != feature_keys.end()) { mapnik::grid::lookup_type val = feature_pos->second; key_pos = keys.find(val); if (key_pos == keys.end()) { // Create a new entry for this key. Skip the codepoints that // can't be encoded directly in JSON. if (codepoint == 34) ++codepoint; // Skip " else if (codepoint == 92) ++codepoint; // Skip backslash keys[val] = codepoint; key_order.push_back(val); line[idx++] = static_cast<Py_UNICODE>(codepoint); ++codepoint; } else { line[idx++] = static_cast<Py_UNICODE>(key_pos->second); } } // else, shouldn't get here... } l.append(boost::python::object( boost::python::handle<>( PyUnicode_FromUnicode(line.get(), array_size)))); } }
static void grid2utf(T const& grid_type, Local<Array>& l, std::vector<typename T::lookup_type>& key_order, unsigned int resolution) { typename T::feature_key_type const& feature_keys = grid_type.get_feature_keys(); typename T::key_type keys; typename T::key_type::const_iterator key_pos; typename T::feature_key_type::const_iterator feature_pos; // start counting at utf8 codepoint 32, aka space character uint16_t codepoint = 32; uint16_t row_idx = 0; unsigned array_size = static_cast<unsigned int>(grid_type.width()/resolution); for (unsigned y = 0; y < grid_type.height(); y=y+resolution) { uint16_t idx = 0; boost::scoped_array<uint16_t> line(new uint16_t[array_size]); typename T::value_type const* row = grid_type.getRow(y); for (unsigned x = 0; x < grid_type.width(); x=x+resolution) { // todo - this lookup is expensive feature_pos = feature_keys.find(row[x]); if (feature_pos != feature_keys.end()) { typename T::lookup_type const& val = feature_pos->second; key_pos = keys.find(val); if (key_pos == keys.end()) { // Create a new entry for this key. Skip the codepoints that // can't be encoded directly in JSON. if (codepoint == 34) ++codepoint; // Skip " else if (codepoint == 92) ++codepoint; // Skip backslash keys[val] = codepoint; key_order.push_back(val); line[idx++] = static_cast<uint16_t>(codepoint); ++codepoint; } else { line[idx++] = static_cast<uint16_t>(key_pos->second); } } // else, shouldn't get here... } l->Set(row_idx, String::New(line.get(),array_size)); ++row_idx; } }