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 1ac16d5 commit bab72ab
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 11 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
2 changes: 1 addition & 1 deletion test/vector_tile.cpp
Expand Up @@ -951,7 +951,7 @@ TEST_CASE( "vector tile from simplified geojson", "should create vector tile wit
CHECK( n_err == 0 );
std::string geojson_string;
CHECK( mapnik::util::to_geojson(geojson_string,projected_geom) );
CHECK( geojson_string == "{\"type\":\"MultiPolygon\",\"coordinates\":[[[[160.42640625,11.4238608092025],[160.41375,11.404562686369],[160.3996875,11.3949131331061],[160.3996875,11.3990486960562],[160.39265625,11.4031841988239],[160.3940625,11.3976701817588],[160.38703125,11.3838846711709],[160.39265625,11.3825060833676],[160.39125,11.3618264654176],[160.3378125,11.3397665531013],[160.3434375,11.3604477708622],[160.26609375,11.3094313929343],[160.28296875,11.3011576095711],[160.29,11.2128890967052],[160.28296875,11.1990947005919],[160.28859375,11.1866791818427],[160.318125,11.1784018737118],[160.31390625,11.1701243292693],[160.318125,11.1646058351055],[160.3265625,11.1632261951713],[160.27875,11.1094151318478],[160.25203125,11.1135547973836],[160.2703125,11.1245936181879],[160.25484375,11.128733068196],[160.22109375,11.1025155587833],[160.2196875,11.0707754241188],[160.205625,11.07491563701],[160.205625,11.068015249669],[160.17890625,11.0583544343014],[160.19015625,11.0569742918251],[160.1859375,11.0473131126319],[160.21828125,11.0611146997615],[160.273125,11.0583544343014],[160.27171875,11.0611146997615],[160.25484375,11.0652550492086],[160.26890625,11.0914759027807],[160.32234375,11.095615822671],[160.340625,11.0887159236072],[160.34625,11.0942358558913],[160.3603125,11.0997556838987],[160.36171875,11.1080352302834],[160.374375,11.1149346728405],[160.39125,11.1052754075802],[160.4053125,11.1273532580621],[160.39265625,11.1370117917052],[160.51078125,11.1866791818427],[160.50796875,11.179781441482],[160.531875,11.1715039364132],[160.55578125,11.1135547973836],[160.576875,11.1328724593753],[160.58671875,11.1273532580621],[160.599375,11.1259734413925],[160.62046875,11.1121749153987],[160.6246875,11.1149346728405],[160.65,11.0969957829327],[160.6584375,11.0997556838987],[160.62328125,11.1342522433585],[160.61765625,11.128733068196],[160.610625,11.153568532114],[160.54734375,11.1604668956365],[160.56140625,11.1687447155659],[160.54875,11.1770222993774],[160.52203125,11.2115096867066],[160.5234375,11.2349587608161],[160.49390625,11.2032330885061],[160.475625,11.2101302701253],[160.464375,11.201853632445],[160.4165625,11.2073714172179],[160.42078125,11.2184066708578],[160.374375,11.2266828344767],[160.374375,11.2184066708578],[160.37015625,11.2170272871975],[160.3490625,11.2335794562443],[160.35609375,11.2363380587922],[160.35609375,11.2446137080958],[160.363125,11.2584059287671],[160.35328125,11.2639226320335],[160.351875,11.2859883867159],[160.32796875,11.2721974885629],[160.31953125,11.2763348275162],[160.36171875,11.3149471157772],[160.37296875,11.2901255270268],[160.40671875,11.3066734916869],[160.40671875,11.3011576095711],[160.41796875,11.3052945311095],[160.419375,11.3370089442254],[160.4109375,11.33838775199],[160.3940625,11.3756130442004],[160.4025,11.3838846711709],[160.3996875,11.3852632522956],[160.40390625,11.3907775099941],[160.40671875,11.3866418267411],[160.419375,11.3990486960562],[160.41515625,11.404562686369],[160.419375,11.4114550237293],[160.42359375,11.4114550237293],[160.42640625,11.4238608092025]],[[160.34625,11.1149346728405],[160.3490625,11.1135547973836],[160.34484375,11.1107950268865],[160.34625,11.1149346728405]],[[160.34203125,11.1480497233847],[160.34484375,11.1466700048322],[160.34625,11.1383915560672],[160.34203125,11.1480497233847]],[[160.57125,11.1549482179223],[160.576875,11.150809140847],[160.57265625,11.1425308098987],[160.57125,11.1549482179223]]],[[[160.35609375,11.3687198381851],[160.34625,11.3632051533067],[160.35328125,11.3604477708622],[160.35609375,11.3687198381851]]]]}" );
CHECK( geojson_string == "{\"type\":\"Polygon\",\"coordinates\":[[[160.42359375,11.422482415387],[160.40671875,11.3976701817587],[160.396875,11.3935345987523],[160.39828125,11.4018057045895],[160.39265625,11.4004272036667],[160.38984375,11.3811274888866],[160.3940625,11.3838846711709],[160.3771875,11.3521754635814],[160.33921875,11.3590690696413],[160.35046875,11.3645838345287],[160.3575,11.3645838345287],[160.3575,11.3756130442004],[160.28859375,11.3480392200085],[160.295625,11.3287359579627],[160.26328125,11.3080524456288],[160.295625,11.1866791818427],[160.31671875,11.1811610026871],[160.318125,11.1770222993774],[160.31390625,11.1687447155658],[160.3125,11.1494294353899],[160.2703125,11.1107950268865],[160.2421875,11.1149346728405],[160.23796875,11.0997556838987],[160.25625,11.095615822671],[160.21828125,11.0735355725517],[160.21546875,11.0652550492086],[160.2084375,11.0762956949617],[160.20140625,11.0638749392263],[160.19015625,11.0528338254201],[160.18453125,11.0528338254201],[160.183125,11.0486933005675],[160.24640625,11.0583544343014],[160.26890625,11.0555941428522],[160.250625,11.0804358297701],[160.28015625,11.0942358558912],[160.295625,11.0845759059922],[160.2928125,11.0721555015877],[160.318125,11.0790557913425],[160.31953125,11.0942358558912],[160.33359375,11.103895486443],[160.34484375,11.0900959164514],[160.35609375,11.103895486443],[160.363125,11.0969957829326],[160.36453125,11.1052754075802],[160.36171875,11.1121749153987],[160.37578125,11.1149346728405],[160.39828125,11.1080352302833],[160.36734375,11.1756427184796],[160.48125,11.1852996469051],[160.48546875,11.1825405573265],[160.5121875,11.1852996469051],[160.5459375,11.1342522433584],[160.56421875,11.1301128717933],[160.55578125,11.1204541093718],[160.56140625,11.1135547973836],[160.588125,11.1314926688533],[160.62328125,11.1121749153987],[160.633125,11.1135547973836],[160.6471875,11.1025155587832],[160.64296875,11.1176944041668],[160.63734375,11.1190742600349],[160.62328125,11.1342522433584],[160.62046875,11.1287330681959],[160.6078125,11.1480497233847],[160.61203125,11.1480497233847],[160.6134375,11.1563278971794],[160.5909375,11.1425308098987],[160.576875,11.1480497233847],[160.57125,11.1549482179223],[160.57125,11.1494294353899],[160.57828125,11.1452902797332],[160.57265625,11.1425308098987],[160.57125,11.1494294353899],[160.54875,11.1577075698847],[160.554375,11.1797814414819],[160.54875,11.1770222993774],[160.5628125,11.2087508469621],[160.5234375,11.2059919808932],[160.52203125,11.203233088506],[160.50515625,11.2184066708578],[160.49390625,11.203233088506],[160.46296875,11.2046125379891],[160.46296875,11.201853632445],[160.4165625,11.2115096867065],[160.41796875,11.2211654184182],[160.39546875,11.2266828344767],[160.35609375,11.2225447823168],[160.35328125,11.2363380587921],[160.3659375,11.2473722050632],[160.351875,11.2915045605452],[160.32375,11.2721974885629],[160.32234375,11.2846093266964],[160.35328125,11.3080524456288],[160.351875,11.3149471157772],[160.3659375,11.3204627323768],[160.36171875,11.2997786224589],[160.3828125,11.3011576095711],[160.37859375,11.3080524456288],[160.38140625,11.3094313929343],[160.3828125,11.3011576095711],[160.408125,11.3039155638971],[160.408125,11.2997786224589],[160.425,11.3094313929343],[160.41234375,11.3411453475586],[160.3996875,11.3301148056307],[160.40953125,11.3700984927314],[160.39265625,11.3618264654175],[160.396875,11.3797488877286],[160.4053125,11.3893989555911],[160.40953125,11.3866418267411],[160.419375,11.4004272036667],[160.41515625,11.4059411672241],[160.419375,11.4114550237293],[160.425,11.412833471123],[160.42359375,11.422482415387]],[[160.34203125,11.1480497233847],[160.35046875,11.1397713138873],[160.34625,11.1383915560672],[160.34203125,11.1480497233847]],[[160.3603125,11.1439105480884],[160.363125,11.1425308098987],[160.3603125,11.1383915560672],[160.3603125,11.1439105480884]]]}");
}

mapnik::geometry::geometry<double> round_trip2(mapnik::geometry::geometry<double> const& geom,
Expand Down

0 comments on commit bab72ab

Please sign in to comment.