2010-07-06 00:37:05 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Hermann Kraus
|
|
|
|
*
|
|
|
|
* 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 METAWRITER_HPP
|
|
|
|
#define METAWRITER_HPP
|
|
|
|
|
|
|
|
// Mapnik
|
|
|
|
#include <mapnik/box2d.hpp>
|
|
|
|
#include <mapnik/feature.hpp>
|
2010-08-10 12:19:19 +00:00
|
|
|
#include <mapnik/font_engine_freetype.hpp>
|
2010-07-06 00:37:05 +00:00
|
|
|
|
|
|
|
// Boost
|
|
|
|
#include <boost/utility.hpp>
|
|
|
|
#include <boost/shared_ptr.hpp>
|
2010-07-12 15:27:33 +00:00
|
|
|
#include <boost/optional.hpp>
|
|
|
|
|
|
|
|
// STL
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
2010-07-06 00:37:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace mapnik {
|
|
|
|
|
2010-08-12 00:11:01 +00:00
|
|
|
struct placement;
|
2010-08-08 02:42:40 +00:00
|
|
|
|
|
|
|
/** Implementation of std::map that also returns const& for operator[]. */
|
2010-07-25 22:41:18 +00:00
|
|
|
class metawriter_property_map
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
metawriter_property_map() {}
|
|
|
|
UnicodeString const& operator[](std::string const& key) const;
|
|
|
|
UnicodeString& operator[](std::string const& key) {return m_[key];}
|
|
|
|
private:
|
|
|
|
std::map<std::string, UnicodeString> m_;
|
|
|
|
UnicodeString not_found_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-07-12 15:27:33 +00:00
|
|
|
/** All properties to be output by a metawriter. */
|
2010-07-14 10:34:18 +00:00
|
|
|
class metawriter_properties : public std::set<std::string>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
metawriter_properties(boost::optional<std::string> str);
|
|
|
|
metawriter_properties() {};
|
|
|
|
template <class InputIterator> metawriter_properties(
|
|
|
|
InputIterator first, InputIterator last) : std::set<std::string>(first, last) {};
|
2010-08-12 00:11:01 +00:00
|
|
|
std::string to_string() const;
|
2010-07-14 10:34:18 +00:00
|
|
|
};
|
2010-07-12 15:27:33 +00:00
|
|
|
|
2010-07-06 00:37:05 +00:00
|
|
|
/** Abstract baseclass for all metawriter classes. */
|
|
|
|
class metawriter
|
|
|
|
{
|
|
|
|
public:
|
2010-08-12 19:12:15 +00:00
|
|
|
typedef coord_transform2<CoordTransform,geometry2d> path_type;
|
2010-07-12 15:27:33 +00:00
|
|
|
metawriter(metawriter_properties dflt_properties) : dflt_properties_(dflt_properties) {}
|
2010-07-06 00:37:05 +00:00
|
|
|
virtual ~metawriter() {};
|
2010-07-12 15:27:33 +00:00
|
|
|
/** Output a rectangular area.
|
|
|
|
* \param box Area (in pixel coordinates)
|
|
|
|
* \param feature The feature being processed
|
|
|
|
* \param prj_trans Projection transformation
|
|
|
|
* \param t Cooridnate transformation
|
|
|
|
* \param properties List of properties to output
|
|
|
|
*/
|
2010-08-07 20:03:05 +00:00
|
|
|
virtual void add_box(box2d<double> const& box, Feature const& feature,
|
|
|
|
CoordTransform const& t,
|
2010-08-12 19:12:15 +00:00
|
|
|
metawriter_properties const& properties)=0;
|
2010-08-10 12:19:19 +00:00
|
|
|
virtual void add_text(placement const& placement,
|
|
|
|
face_set_ptr face,
|
|
|
|
Feature const& feature,
|
|
|
|
CoordTransform const& t,
|
2010-08-12 19:12:15 +00:00
|
|
|
metawriter_properties const& properties)=0;
|
|
|
|
virtual void add_polygon(path_type & path,
|
|
|
|
Feature const& feature,
|
|
|
|
CoordTransform const& t,
|
|
|
|
metawriter_properties const& properties)=0;
|
2010-08-12 21:39:29 +00:00
|
|
|
virtual void add_line(path_type & path,
|
|
|
|
Feature const& feature,
|
|
|
|
CoordTransform const& t,
|
|
|
|
metawriter_properties const& properties)=0;
|
2010-08-10 12:19:19 +00:00
|
|
|
|
2010-08-08 02:42:40 +00:00
|
|
|
/** Start processing.
|
|
|
|
* Write file header, init database connection, ...
|
|
|
|
*
|
|
|
|
* \param properties metawriter_property_map object with userdefined values.
|
|
|
|
* Useful for setting filename etc.
|
|
|
|
*/
|
2010-07-25 22:41:18 +00:00
|
|
|
virtual void start(metawriter_property_map const& properties) {};
|
2010-08-08 02:42:40 +00:00
|
|
|
/** Stop processing.
|
|
|
|
* Write file footer, close database connection, ...
|
|
|
|
*/
|
|
|
|
virtual void stop() {};
|
|
|
|
/** Set output size (pixels).
|
|
|
|
* All features that are completely outside this size are discarded.
|
|
|
|
*/
|
2010-08-01 15:07:50 +00:00
|
|
|
void set_size(int width, int height) { width_ = width; height_ = height; }
|
2010-08-08 02:42:40 +00:00
|
|
|
/** Set Map object's srs. */
|
2010-08-02 12:14:27 +00:00
|
|
|
virtual void set_map_srs(projection const& proj) = 0;
|
2010-08-08 02:42:40 +00:00
|
|
|
/** Return the list of default properties. */
|
2010-07-31 10:20:56 +00:00
|
|
|
metawriter_properties const& get_default_properties() const { return dflt_properties_;}
|
2010-07-12 15:27:33 +00:00
|
|
|
protected:
|
|
|
|
metawriter_properties dflt_properties_;
|
2010-08-08 02:42:40 +00:00
|
|
|
/** Output width (pixels). */
|
2010-08-01 15:07:50 +00:00
|
|
|
int width_;
|
2010-08-08 02:42:40 +00:00
|
|
|
/** Output height (pixels). */
|
2010-08-01 15:07:50 +00:00
|
|
|
int height_;
|
2010-07-06 00:37:05 +00:00
|
|
|
};
|
|
|
|
|
2010-08-08 02:42:40 +00:00
|
|
|
/** Shared pointer to metawriter object. */
|
2010-07-06 00:37:05 +00:00
|
|
|
typedef boost::shared_ptr<metawriter> metawriter_ptr;
|
2010-08-08 19:00:56 +00:00
|
|
|
/** Metawriter object + properties. */
|
2010-07-12 15:27:33 +00:00
|
|
|
typedef std::pair<metawriter_ptr, metawriter_properties> metawriter_with_properties;
|
2010-07-06 00:37:05 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|