Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first pass at encoded image support

  • Loading branch information...
commit 8efa888981cc63a4c62efc80ddab870f49e1dee8 1 parent 22545c0
@springmeyer springmeyer authored
View
7 Makefile
@@ -22,9 +22,14 @@ python: python/vector_tile_pb2.py
test/run-test: Makefile src/vector_tile.pb.cc test/vector_tile.cpp test/test_utils.hpp src/*
@$(CXX) -o ./test/run-test test/vector_tile.cpp src/vector_tile.pb.cc -I./src $(CXXFLAGS) $(MAPNIK_CXXFLAGS) $(PROTOBUF_CXXFLAGS) $(COMMON_FLAGS) $(MAPNIK_LDFLAGS) $(PROTOBUF_LDFLAGS) $(LDFLAGS) -Wno-unused-private-field
-test: test/run-test test/run-geom-test src/vector_tile.pb.cc test/catch.hpp
+test: test/run-test test/run-geom-test ./test/run-raster-test src/vector_tile.pb.cc test/catch.hpp
./test/run-test
./test/run-geom-test
+ ./test/run-raster-test
+
+./test/run-raster-test: Makefile src/vector_tile.pb.cc test/raster_tile.cpp test/encoding_util.hpp test/catch.hpp
+ @$(CXX) -o ./test/run-raster-test test/raster_tile.cpp src/vector_tile.pb.cc -I./src $(CXXFLAGS) $(MAPNIK_CXXFLAGS) $(PROTOBUF_CXXFLAGS) $(COMMON_FLAGS) $(MAPNIK_LDFLAGS) $(PROTOBUF_LDFLAGS) $(LDFLAGS) -Wno-unused-private-field
+ ./test/run-raster-test
./test/run-geom-test: Makefile src/vector_tile.pb.cc test/geometry_encoding.cpp test/encoding_util.hpp src/vector_tile_geometry_encoder.hpp test/catch.hpp
@$(CXX) -o ./test/run-geom-test test/geometry_encoding.cpp src/vector_tile.pb.cc -I./src $(CXXFLAGS) $(MAPNIK_CXXFLAGS) $(PROTOBUF_CXXFLAGS) $(COMMON_FLAGS) $(MAPNIK_LDFLAGS) $(PROTOBUF_LDFLAGS) $(LDFLAGS) -Wno-unused-private-field
View
3  proto/vector_tile.proto
@@ -60,6 +60,9 @@ message tile {
// also encoded as deltas to the previous position. The original
// position is (0,0)
repeated uint32 geometry = 4 [ packed = true ];
+
+ optional bytes raster = 5;
+
}
message layer {
View
8 src/vector_tile_backend_pbf.hpp
@@ -77,6 +77,14 @@ namespace mapnik { namespace vector {
{
}
+ void add_tile_feature_raster(std::string const& image_buffer)
+ {
+ if (current_feature_)
+ {
+ current_feature_->set_raster(image_buffer);
+ }
+ }
+
void stop_tile_feature()
{
if (current_feature_)
View
20 src/vector_tile_datasource.hpp
@@ -20,6 +20,7 @@
#include <mapnik/feature.hpp>
#include <mapnik/feature_factory.hpp>
#include <mapnik/geom_util.hpp>
+#include <mapnik/image_reader.hpp>
#include <memory>
#include <stdexcept>
@@ -130,6 +131,25 @@ namespace mapnik { namespace vector {
{
mapnik::vector::tile_feature const& f = layer_.features(itr_);
mapnik::value_integer feature_id = itr_++;
+ if (f.has_raster())
+ {
+ std::string const& image_buffer = f.raster();
+ MAPNIK_UNIQUE_PTR<mapnik::image_reader> reader(mapnik::get_image_reader(image_buffer.data(),image_buffer.size()));
+ if (reader.get())
+ {
+ if (f.has_id())
+ {
+ feature_id = f.id();
+ }
+ mapnik::feature_ptr feature = mapnik::feature_factory::create(ctx_,feature_id);
+ MAPNIK_SHARED_PTR<mapnik::image_32> image_ptr = MAPNIK_MAKE_SHARED<mapnik::image_32>(reader->width(),reader->height());
+ mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(filter_.box_,reader->width(),reader->height(),1);
+ reader->read(0,0,raster->data_);
+ feature->set_raster(raster);
+ add_attributes(feature,f,layer_,tr_);
+ return feature;
+ }
+ }
if (f.geometry_size() <= 0)
{
continue;
View
23 src/vector_tile_processor.hpp
@@ -18,6 +18,8 @@
#include <mapnik/box2d.hpp>
#include <mapnik/version.hpp>
#include <mapnik/noncopyable.hpp>
+#include <mapnik/image_util.hpp>
+#include <mapnik/raster.hpp>
// agg
#ifdef CONV_CLIPPER
@@ -223,6 +225,27 @@ namespace mapnik { namespace vector {
mapnik::feature_ptr feature = features->next();
if (feature) {
backend_.start_tile_layer(lay.name());
+ raster_ptr const& source = feature->get_raster();
+ if (source)
+ {
+ box2d<double> target_ext = box2d<double>(source->ext_);
+ prj_trans.backward(target_ext, PROJ_ENVELOPE_POINTS);
+ box2d<double> ext = t_.forward(target_ext);
+ int start_x = static_cast<int>(std::floor(ext.minx()+.5));
+ int start_y = static_cast<int>(std::floor(ext.miny()+.5));
+ int end_x = static_cast<int>(std::floor(ext.maxx()+.5));
+ int end_y = static_cast<int>(std::floor(ext.maxy()+.5));
+ int raster_width = end_x - start_x;
+ int raster_height = end_y - start_y;
+ if (raster_width > 0 && raster_height > 0)
+ {
+ backend_.start_tile_feature(*feature);
+ backend_.add_tile_feature_raster(mapnik::save_to_string(source->data_,"png"));
+ }
+ backend_.stop_tile_layer();
+ return;
+ }
+ // vector pathway
while (feature)
{
boost::ptr_vector<mapnik::geometry_type> & paths = feature->paths();
View
BIN  test/natural_earth.tif
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.