Updated svg_mapper

Updated 07_graph_route_example.cpp using svg_mapper now


[SVN r59787]
This commit is contained in:
Barend Gehrels 2010-02-20 17:28:53 +00:00
parent eeef35e569
commit c16c094b9e
4 changed files with 31 additions and 41 deletions

View File

@ -31,7 +31,7 @@
#include <boost/geometry/extensions/gis/io/wkt/read_wkt.hpp>
// For output:
#include <boost/geometry/extensions/io/svg/write_svg.hpp>
#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
// For distance-calculations over the Earth:
#include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
@ -79,18 +79,6 @@ void read_wkt(std::string const& filename, std::vector<Tuple>& tuples, Box& box)
}
}
// Boilerplate code to initialize the SVG XML.
// Note that this is (on purpose) not part of the library but of this sample.
// GGL itself only streams small pieces of SVG, in any coordinate system
void svg_header(std::ofstream& stream)
{
stream << "<?xml version=\"1.0\" standalone=\"no\"?>" << std::endl;
stream << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"" << std::endl;
stream << "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" << std::endl;
stream << "<svg width=\"100%\" height=\"100%\" version=\"1.1\"" << std::endl;
stream << "xmlns=\"http://www.w3.org/2000/svg\">" << std::endl;
}
// Code to define properties for Boost Graph's
@ -361,40 +349,32 @@ int main()
}
// Create the SVG
typedef boost::geometry::point_xy<int> svg_point_type;
std::ofstream stream("routes.svg");
svg_header(stream);
boost::geometry::strategy::transform::map_transformer
<
point_type,
svg_point_type, true, true
> matrix(box, 1000, 800);
boost::geometry::svg_mapper<point_type> mapper(stream, 600, 600);
// Map roads
BOOST_FOREACH(road_type const& road, roads)
{
boost::geometry::linestring<svg_point_type> line;
boost::geometry::transform(road.get<0>(), line, matrix);
stream << boost::geometry::svg(line, "stroke:rgb(128,128,128);stroke-width:1") << std::endl;
mapper.add(road.get<0>());
}
// Map the calculated route as thicker green transparent markation
BOOST_FOREACH(road_type const& road, roads)
{
boost::geometry::linestring<svg_point_type> line;
boost::geometry::transform(route, line, matrix);
stream << boost::geometry::svg(line, "stroke:rgb(0, 255, 0);stroke-width:6;opacity:0.5") << std::endl;
mapper.map(road.get<0>(),
"stroke:rgb(128,128,128);stroke-width:1");
}
mapper.map(route,
"stroke:rgb(0, 255, 0);stroke-width:6;opacity:0.5");
// Map cities
BOOST_FOREACH(city_type const& city, cities)
{
svg_point_type point;
boost::geometry::transform(city.get<0>(), point, matrix);
stream << boost::geometry::svg(point, "fill:rgb(255,255,0);stroke:rgb(0,0,0);stroke-width:1") << std::endl;
mapper.map(city.get<0>(),
"fill:rgb(255,255,0);stroke:rgb(0,0,0);stroke-width:1");
mapper.text(city.get<0>(), city.get<1>(),
"fill:rgb(0,0,0);font-family:Arial;font-size:10px", 5, 5);
}
stream << "</svg>" << std::endl;
return 0;
}

View File

@ -1,13 +1,12 @@
// Boost.Geometry (aka GGL, Generic Geometry Library) test file
//
// Copyright Barend Gehrels 2007-2009, Geodan, Amsterdam, the Netherlands
// Copyright Bruno Lalande 2008, 2009
// Copyright Barend Gehrels 2009-2010, Geodan, Amsterdam, the Netherlands
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef GGL_TEST_UTIL_SVG_MAPPER_HPP
#define GGL_TEST_UTIL_SVG_MAPPER_HPP
#ifndef BOOST_GEOMETRY_IO_SVG_MAPPER_HPP
#define BOOST_GEOMETRY_IO_SVG_MAPPER_HPP
#include <cstdio>
@ -32,6 +31,11 @@
#include <boost/geometry/extensions/io/svg/write_svg.hpp>
namespace boost { namespace geometry
{
#ifndef DOXYGEN_NO_DISPATCH
namespace dispatch
{
@ -167,7 +171,14 @@ inline void svg_map(std::ostream& stream,
template <typename P>
class svg_mapper
{
typedef boost::geometry::strategy::transform::map_transformer<P, boost::geometry::point_xy<int>, true, true> transformer_type;
typedef boost::geometry::strategy::transform::map_transformer
<
P,
boost::geometry::point_xy<int>,
true,
true
> transformer_type;
boost::geometry::box<P> bbox;
transformer_type* matrix;
std::ostream& stream;
@ -236,5 +247,6 @@ public :
};
}} // namespace boost::geometry
#endif // GGL_TEST_UTIL_SVG_MAPPER_HPP
#endif // BOOST_GEOMETRY_IO_SVG_MAPPER_HPP

View File

@ -44,7 +44,6 @@
#include <boost/geometry/algorithms/distance.hpp>
#include <boost/geometry/algorithms/envelope.hpp>
#include <boost/geometry/algorithms/for_each.hpp>
#include <boost/geometry/algorithms/intermediate.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/geometry/algorithms/intersects.hpp>
#include <boost/geometry/algorithms/length.hpp>
@ -52,7 +51,6 @@
#include <boost/geometry/algorithms/num_points.hpp>
#include <boost/geometry/algorithms/perimeter.hpp>
#include <boost/geometry/algorithms/sectionalize.hpp>
#include <boost/geometry/algorithms/selected.hpp>
#include <boost/geometry/algorithms/simplify.hpp>
#include <boost/geometry/algorithms/transform.hpp>
#include <boost/geometry/algorithms/union.hpp>