wkb_buffer_ptr to_wkb(geometry_container const& paths, wkbByteOrder byte_order ) { if (paths.size() == 1) { // single geometry return to_wkb(paths.front(), byte_order); } if (paths.size() > 1) { // multi geometry or geometry collection std::vector<wkb_buffer_ptr> wkb_cont; bool collection = false; int multi_type = 0; size_t multi_size = 1 + 4 + 4; for (auto const& geom : paths) { wkb_buffer_ptr wkb = to_wkb(geom,byte_order); multi_size += wkb->size(); int type = static_cast<int>(geom.type()); if (multi_type > 0 && multi_type != geom.type()) collection = true; multi_type = type; wkb_cont.push_back(std::move(wkb)); } wkb_buffer_ptr multi_wkb = std::make_unique<wkb_buffer>(multi_size); wkb_stream ss(multi_wkb->buffer(), multi_wkb->size()); ss.write(reinterpret_cast<char*>(&byte_order),1); multi_type = collection ? 7 : multi_type + 3; write(ss,multi_type, 4, byte_order); write(ss,paths.size(),4,byte_order); for ( wkb_buffer_ptr const& wkb : wkb_cont) { ss.write(wkb->buffer(),wkb->size()); } return std::move(multi_wkb); } return wkb_buffer_ptr(); }
wkb_buffer_ptr to_wkb(geometry_container const& paths, wkbByteOrder byte_order ) { if (paths.size() == 1) { // single geometry return to_wkb(paths.front(), byte_order); } if (paths.size() > 1) { // multi geometry or geometry collection std::vector<wkb_buffer_ptr> wkb_cont; bool collection = false; int multi_type = 0; size_t multi_size = 1 + 4 + 4; geometry_container::const_iterator itr = paths.begin(); geometry_container::const_iterator end = paths.end(); for ( ; itr!=end; ++itr) { wkb_buffer_ptr wkb = to_wkb(*itr,byte_order); multi_size += wkb->size(); int type = static_cast<int>(itr->type()); if (multi_type > 0 && multi_type != itr->type()) collection = true; multi_type = type; wkb_cont.push_back(std::move(wkb)); } wkb_buffer_ptr multi_wkb( new wkb_buffer(multi_size)); wkb_stream ss(multi_wkb->buffer(), multi_wkb->size()); ss.write(reinterpret_cast<char*>(&byte_order),1); multi_type = collection ? 7 : multi_type + 3; write(ss,multi_type, 4, byte_order); write(ss,paths.size(),4,byte_order); for ( wkb_buffer_ptr const& wkb : wkb_cont) { ss.write(wkb->buffer(),wkb->size()); } return std::move(multi_wkb); } return wkb_buffer_ptr(); }