Skip to content

Commit

Permalink
Added vector tile strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
flippmoke committed May 21, 2015
1 parent 887e82a commit 83c1035
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/vector_tile_processor.ipp
Expand Up @@ -50,6 +50,7 @@
#include <string>
#include <stdexcept>

#include "vector_tile_strategy.hpp"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
Expand Down Expand Up @@ -1249,19 +1250,13 @@ unsigned processor<T>::handle_geometry(mapnik::feature_impl const& feature,
mapnik::proj_transform const& prj_trans,
mapnik::box2d<double> const& buffered_query_ext)
{
mapnik::proj_backward_strategy proj_strat(prj_trans);
mapnik::view_strategy view_strat(t_);
mapnik::geometry::scale_rounding_strategy scale_strat(backend_.get_path_multiplier());
using sg_type = mapnik::geometry::strategy_group<mapnik::proj_backward_strategy,
mapnik::view_strategy,
mapnik::geometry::scale_rounding_strategy >;
sg_type sg(proj_strat, view_strat, scale_strat);
vector_tile_strategy vs(prj_trans, t_, backend_.get_path_multiplier());
mapnik::geometry::point<double> p1_min(buffered_query_ext.minx(), buffered_query_ext.miny());
mapnik::geometry::point<double> p1_max(buffered_query_ext.maxx(), buffered_query_ext.maxy());
mapnik::geometry::point<std::int64_t> p2_min = mapnik::geometry::transform<std::int64_t>(p1_min, sg);
mapnik::geometry::point<std::int64_t> p2_max = mapnik::geometry::transform<std::int64_t>(p1_max, sg);
mapnik::geometry::point<std::int64_t> p2_min = mapnik::geometry::transform<std::int64_t>(p1_min, vs);
mapnik::geometry::point<std::int64_t> p2_max = mapnik::geometry::transform<std::int64_t>(p1_max, vs);
box2d<int> bbox(p2_min.x, p2_min.y, p2_max.x, p2_max.y);
mapnik::geometry::geometry<std::int64_t> new_geom = mapnik::geometry::transform<std::int64_t>(geom, sg);
mapnik::geometry::geometry<std::int64_t> new_geom = mapnik::geometry::transform<std::int64_t>(geom, vs);
encoder_visitor<T> encoder(backend_,feature,bbox, area_threshold_);
if (simplify_distance_ > 0)
{
Expand Down
88 changes: 88 additions & 0 deletions src/vector_tile_strategy.hpp
@@ -0,0 +1,88 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2014 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/

#ifndef MAPNIK_VECTOR_TILE_STRATEGY_HPP
#define MAPNIK_VECTOR_TILE_STRATEGY_HPP

// mapnik
#include <mapnik/config.hpp>
#include <mapnik/util/noncopyable.hpp>
#include <mapnik/proj_transform.hpp>
#include <mapnik/view_transform.hpp>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedef"
#include <boost/geometry/core/coordinate_type.hpp>
#include <boost/geometry/core/access.hpp>
#include <boost/numeric/conversion/cast.hpp>
#pragma GCC diagnostic pop


namespace mapnik {

namespace vector_tile_impl {

struct vector_tile_strategy
{
vector_tile_strategy(proj_transform const& prj_trans,
view_transform const& tr,
double scaling)
: prj_trans_(prj_trans),
tr_(tr),
scaling_(scaling) {}

template <typename P1, typename P2>
inline bool apply(P1 const& p1, P2 & p2) const
{
using p2_type = typename boost::geometry::coordinate_type<P2>::type;
double x = boost::geometry::get<0>(p1);
double y = boost::geometry::get<1>(p1);
double z = 0.0;
if (!prj_trans_.backward(x, y, z)) return false;
tr_.forward(&x,&y);
x = x * scaling_;
y = y * scaling_;
x = std::floor(x + 0.5);
y = std::floor(y + 0.5);
boost::geometry::set<0>(p2, static_cast<p2_type>(x));
boost::geometry::set<1>(p2, static_cast<p2_type>(y));
return true;
}

template <typename P1, typename P2>
inline P2 execute(P1 const& p1, bool & status) const
{
P2 p2;
status = apply(p1, p2);
return p2;
}

proj_transform const& prj_trans_;
view_transform const& tr_;
double const scaling_;
};

}
}

#endif // MAPNIK_VECTOR_TILE_STRATEGY_HPP

0 comments on commit 83c1035

Please sign in to comment.