Merge branch 'master' into geometry_cleanup
This commit is contained in:
commit
108d1559c1
6 changed files with 359 additions and 1 deletions
|
@ -32,6 +32,7 @@
|
|||
#include <mapnik/wkt/wkt_factory.hpp>
|
||||
#include <mapnik/wkb.hpp>
|
||||
#include <mapnik/util/geometry_to_wkb.hpp>
|
||||
#include <mapnik/util/geometry_to_wkt.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
|
@ -88,6 +89,16 @@ PyObject* to_wkb( geometry_type const& geom)
|
|||
((const char*)wkb->buffer(),wkb->size());
|
||||
}
|
||||
|
||||
std::string to_wkt( geometry_type const& geom)
|
||||
{
|
||||
std::string wkt; // Use Python String directly ?
|
||||
bool result = mapnik::util::to_wkt(wkt,geom);
|
||||
if (!result)
|
||||
{
|
||||
throw std::runtime_error("Generate WKT failed");
|
||||
}
|
||||
return wkt;
|
||||
}
|
||||
|
||||
void export_geometry()
|
||||
{
|
||||
|
@ -105,6 +116,7 @@ void export_geometry()
|
|||
// .def("__str__",&geometry_type::to_string)
|
||||
.def("type",&geometry_type::type)
|
||||
.def("to_wkb",&to_wkb)
|
||||
.def("to_wkt",&to_wkt)
|
||||
// TODO add other geometry_type methods
|
||||
;
|
||||
|
||||
|
|
70
include/mapnik/util/container_adapter.hpp
Normal file
70
include/mapnik/util/container_adapter.hpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef CONTAINER_ADAPTER_HPP
|
||||
#define CONTAINER_ADAPTER_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/global.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/util/vertex_iterator.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/spirit/include/karma.hpp>
|
||||
|
||||
namespace boost { namespace spirit { namespace traits {
|
||||
|
||||
template <>
|
||||
struct is_container<mapnik::geometry_type const> : mpl::true_ {} ;
|
||||
|
||||
template <>
|
||||
struct container_iterator<mapnik::geometry_type const>
|
||||
{
|
||||
typedef mapnik::util::vertex_iterator<double> type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct begin_container<mapnik::geometry_type const>
|
||||
{
|
||||
static mapnik::util::vertex_iterator<double>
|
||||
call (mapnik::geometry_type const& g)
|
||||
{
|
||||
return mapnik::util::vertex_iterator<double>(g.data());
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct end_container<mapnik::geometry_type const>
|
||||
{
|
||||
static mapnik::util::vertex_iterator<double>
|
||||
call (mapnik::geometry_type const& g)
|
||||
{
|
||||
return mapnik::util::vertex_iterator<double>();
|
||||
}
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif // CONTAINER_ADAPTER_HPP
|
65
include/mapnik/util/geometry_svg_generator.hpp
Normal file
65
include/mapnik/util/geometry_svg_generator.hpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef MAPNIK_GEOMETRY_SVG_GENERATOR_HPP
|
||||
#define MAPNIK_GEOMETRY_SVG_GENERATOR_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/global.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/util/vertex_iterator.hpp>
|
||||
#include <mapnik/util/container_adapter.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/spirit/include/karma.hpp>
|
||||
#include <boost/spirit/include/phoenix_core.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
#include <boost/spirit/include/phoenix_fusion.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
|
||||
//#define BOOST_SPIRIT_USE_PHOENIX_V3 1
|
||||
|
||||
namespace mapnik { namespace util {
|
||||
|
||||
namespace karma = boost::spirit::karma;
|
||||
namespace phoenix = boost::phoenix;
|
||||
|
||||
template <typename OutputIterator>
|
||||
bool generate_svg (OutputIterator sink, mapnik::geometry_type const& geom)
|
||||
{
|
||||
using boost::spirit::karma::double_;
|
||||
using boost::spirit::karma::uint_;
|
||||
using boost::spirit::karma::generate;
|
||||
return generate (sink,
|
||||
// begin grammar
|
||||
((&uint_(mapnik::SEG_MOVETO) << 'M' | 'L')
|
||||
<< " " << double_ << " " << double_) % ' '
|
||||
// end grammar
|
||||
, geom);
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif // MAPNIK_GEOMETRY_SVG_GENERATOR_HPP
|
53
include/mapnik/util/geometry_to_wkt.hpp
Normal file
53
include/mapnik/util/geometry_to_wkt.hpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef MAPNIK_GEOMETRY_TO_WKT_HPP
|
||||
#define MAPNIK_GEOMETRY_TO_WKT_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/global.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/util/vertex_iterator.hpp>
|
||||
#include <mapnik/util/geometry_wkt_generator.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/spirit/include/karma.hpp>
|
||||
|
||||
namespace mapnik { namespace util {
|
||||
|
||||
namespace karma = boost::spirit::karma;
|
||||
|
||||
bool to_wkt(std::string & wkt, mapnik::geometry_type const& geom)
|
||||
{
|
||||
typedef std::back_insert_iterator<std::string> sink_type;
|
||||
sink_type sink(wkt);
|
||||
wkt_generator<sink_type> generator;
|
||||
bool result = karma::generate(sink, generator, geom);
|
||||
return result;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
|
||||
#endif // MAPNIK_GEOMETRY_TO_WKT_HPP
|
159
include/mapnik/util/geometry_wkt_generator.hpp
Normal file
159
include/mapnik/util/geometry_wkt_generator.hpp
Normal file
|
@ -0,0 +1,159 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2011 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
//$Id$
|
||||
|
||||
#ifndef MAPNIK_GEOMETRY_WKT_GENERATOR_HPP
|
||||
#define MAPNIK_GEOMETRY_WKT_GENERATOR_HPP
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/global.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/util/vertex_iterator.hpp>
|
||||
#include <mapnik/util/container_adapter.hpp>
|
||||
|
||||
// boost
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/spirit/include/karma.hpp>
|
||||
#include <boost/spirit/include/phoenix_core.hpp>
|
||||
#include <boost/spirit/include/phoenix_operator.hpp>
|
||||
#include <boost/spirit/include/phoenix_fusion.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
#include <boost/spirit/home/phoenix/statement/if.hpp>
|
||||
#include <boost/fusion/include/boost_tuple.hpp>
|
||||
|
||||
|
||||
//#define BOOST_SPIRIT_USE_PHOENIX_V3 1
|
||||
|
||||
namespace mapnik { namespace util {
|
||||
|
||||
namespace karma = boost::spirit::karma;
|
||||
namespace phoenix = boost::phoenix;
|
||||
|
||||
struct get_type
|
||||
{
|
||||
template <typename T>
|
||||
struct result { typedef int type; };
|
||||
|
||||
int operator() (geometry_type const& geom) const
|
||||
{
|
||||
return (int)geom.type();
|
||||
}
|
||||
};
|
||||
|
||||
struct get_first
|
||||
{
|
||||
template <typename T>
|
||||
struct result { typedef geometry_type::value_type const type; };
|
||||
|
||||
geometry_type::value_type const operator() (geometry_type const& geom) const
|
||||
{
|
||||
geometry_type::value_type coord;
|
||||
boost::get<0>(coord) = geom.get_vertex(0,&boost::get<1>(coord),&boost::get<2>(coord));
|
||||
return coord;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct coordinate_policy : karma::real_policies<T>
|
||||
{
|
||||
typedef boost::spirit::karma::real_policies<T> base_type;
|
||||
static int floatfield(T n) { return base_type::fmtflags::fixed; }
|
||||
};
|
||||
|
||||
|
||||
template <typename OutputIterator>
|
||||
struct wkt_generator :
|
||||
karma::grammar<OutputIterator, geometry_type const& ()>
|
||||
{
|
||||
|
||||
wkt_generator()
|
||||
: wkt_generator::base_type(wkt)
|
||||
{
|
||||
using boost::spirit::karma::uint_;
|
||||
using boost::spirit::karma::_val;
|
||||
using boost::spirit::karma::_1;
|
||||
using boost::spirit::karma::lit;
|
||||
using boost::spirit::karma::_a;
|
||||
using boost::spirit::karma::_r1;
|
||||
using boost::spirit::karma::eps;
|
||||
|
||||
wkt = point | linestring | polygon
|
||||
;
|
||||
|
||||
point = &uint_(mapnik::Point)[_1 = _type(_val)]
|
||||
<< lit("Point(") << point_coord [_1 = _first(_val)] << lit(')')
|
||||
;
|
||||
|
||||
linestring = &uint_(mapnik::LineString)[_1 = _type(_val)]
|
||||
<< lit("LineString(")
|
||||
<< coords
|
||||
<< lit(')')
|
||||
;
|
||||
|
||||
polygon = &uint_(mapnik::Polygon)[_1 = _type(_val)]
|
||||
<< lit("Polygon(")
|
||||
<< coords2
|
||||
<< lit("))")
|
||||
;
|
||||
|
||||
point_coord = &uint_ << coord_type << lit(' ') << coord_type
|
||||
;
|
||||
|
||||
polygon_coord %= ( &uint_(mapnik::SEG_MOVETO) << eps[_r1 += 1]
|
||||
<< karma::string[ if_ (_r1 > 1) [_1 = "),("]
|
||||
.else_[_1 = "("] ] | &uint_ << ",")
|
||||
<< coord_type
|
||||
<< lit(' ')
|
||||
<< coord_type
|
||||
;
|
||||
|
||||
coords2 %= *polygon_coord(_a)
|
||||
;
|
||||
|
||||
coords = point_coord % lit(',')
|
||||
;
|
||||
|
||||
}
|
||||
// rules
|
||||
karma::rule<OutputIterator, geometry_type const& ()> wkt;
|
||||
karma::rule<OutputIterator, geometry_type const& ()> point;
|
||||
karma::rule<OutputIterator, geometry_type const& ()> linestring;
|
||||
karma::rule<OutputIterator, geometry_type const& ()> polygon;
|
||||
|
||||
karma::rule<OutputIterator, geometry_type const& ()> coords;
|
||||
karma::rule<OutputIterator, karma::locals<unsigned>, geometry_type const& ()> coords2;
|
||||
karma::rule<OutputIterator, geometry_type::value_type ()> point_coord;
|
||||
karma::rule<OutputIterator, geometry_type::value_type const& (unsigned& )> polygon_coord;
|
||||
|
||||
// phoenix functions
|
||||
phoenix::function<get_type > _type;
|
||||
phoenix::function<get_first> _first;
|
||||
//
|
||||
karma::real_generator<double, coordinate_policy<double> > coord_type;
|
||||
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
|
||||
#endif // MAPNIK_GEOMETRY_WKT_GENERATOR_HPP
|
|
@ -20,7 +20,6 @@ Known values for OPTION are:
|
|||
--help display this help and exit
|
||||
-v --version output version information
|
||||
--git-revision output git hash
|
||||
--svn-revision output svn revision information (deprecated)
|
||||
EOF
|
||||
|
||||
exit $1
|
||||
|
|
Loading…
Reference in a new issue