Skip to content

Commit

Permalink
good
Browse files Browse the repository at this point in the history
  • Loading branch information
zhixiong-tang committed Nov 12, 2023
1 parent d68e73d commit 5df343c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion headers
Submodule headers updated 1 files
+0 −0 include/mio/mio.hpp
19 changes: 19 additions & 0 deletions src/geobuf/geobuf_plus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,31 @@
#include "planet.hpp"
#include <spdlog/spdlog.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <mio/mio.hpp>

namespace cubao
{

struct GeobufPlus
{
GeobufPlus() = default;
mio::shared_ummap_source mmap;

bool mmap_init(const std::string &path) {
mmap = std::make_shared<mio::ummap_source>(path);
int cursor = 10;
if (std::string((const char *)mmap.data(), cursor) != "GeobufPlus") {
spdlog::error("invalid geobuf plus file, wrong magic");
return false;
}
auto xx = mmap[cursor];
int num_features = *(const int*)(mmap.data() + cursor);
spdlog::info("#features: {}", num_features);
return true;
}

void init(const std::string &header_bytes) {}
mapbox::geojson::feature_collection decode(const std::string &bytes) const
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ PYBIND11_MODULE(_pybind11_geobuf, m)
using GeobufPlus = cubao::GeobufPlus;
py::class_<GeobufPlus>(m, "GeobufPlus", py::module_local()) //
.def(py::init<>())
.def("mmap_init", &GeobufPlus::mmap_init, "path"_a)
.def("init", &GeobufPlus::init, "header_bytes"_a)
//
.def_static(
Expand Down
5 changes: 4 additions & 1 deletion tests/test_geobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,10 @@ def test_query():
from pybind11_geobuf import GeobufPlus

ipath = f"{__pwd}/../data/suzhoubeizhan.json"
print(GeobufPlus.encode(ipath, f"{__pwd}/../build/export.pbf"))
opath = f"{__pwd}/../build/export.pbf"
# print(GeobufPlus.encode(ipath, opath))
gbp = GeobufPlus()
print(gbp.mmap_init(opath))

np.set_printoptions(suppress=True)
pwd = os.path.abspath(os.path.dirname(__file__))
Expand Down

0 comments on commit 5df343c

Please sign in to comment.