2006-03-31 12:32:02 +02:00
|
|
|
/*****************************************************************************
|
2012-02-02 02:53:35 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2011-10-23 15:04:25 +02:00
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* 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,
|
2005-06-14 17:06:59 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2006-03-31 12:32:02 +02:00
|
|
|
* 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
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
*****************************************************************************/
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2011-10-23 16:09:47 +02:00
|
|
|
#ifndef MAPNIK_DATASOURCE_HPP
|
|
|
|
#define MAPNIK_DATASOURCE_HPP
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
// mapnik
|
|
|
|
#include <mapnik/config.hpp>
|
|
|
|
#include <mapnik/params.hpp>
|
|
|
|
#include <mapnik/feature.hpp>
|
|
|
|
#include <mapnik/query.hpp>
|
|
|
|
#include <mapnik/feature_layer_desc.hpp>
|
2012-12-17 03:19:52 +01:00
|
|
|
#include <mapnik/noncopyable.hpp>
|
2011-10-23 16:09:47 +02:00
|
|
|
|
2007-10-08 20:10:31 +02:00
|
|
|
// boost
|
|
|
|
#include <boost/shared_ptr.hpp>
|
2013-01-14 06:48:56 +01:00
|
|
|
#include <boost/optional.hpp>
|
2011-10-23 16:09:47 +02:00
|
|
|
|
2007-10-08 20:10:31 +02:00
|
|
|
// stl
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2005-12-12 14:15:33 +01:00
|
|
|
|
2010-10-24 10:04:16 +02:00
|
|
|
namespace mapnik {
|
2012-01-15 07:35:40 +01:00
|
|
|
|
2012-12-17 03:19:52 +01:00
|
|
|
struct MAPNIK_DECL Featureset : private mapnik::noncopyable
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2012-03-28 21:59:40 +02:00
|
|
|
virtual feature_ptr next() = 0;
|
|
|
|
virtual ~Featureset() {}
|
2010-06-02 13:03:30 +02:00
|
|
|
};
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
typedef MAPNIK_DECL boost::shared_ptr<Featureset> featureset_ptr;
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
class MAPNIK_DECL datasource_exception : public std::exception
|
|
|
|
{
|
|
|
|
public:
|
2012-09-03 20:41:51 +02:00
|
|
|
datasource_exception(std::string const& message)
|
2012-03-28 21:59:40 +02:00
|
|
|
: message_(message)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~datasource_exception() throw()
|
|
|
|
{
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
virtual const char* what() const throw()
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
return message_.c_str();
|
|
|
|
}
|
2012-03-28 21:59:40 +02:00
|
|
|
private:
|
|
|
|
std::string message_;
|
2010-06-02 13:03:30 +02:00
|
|
|
};
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2012-12-17 03:19:52 +01:00
|
|
|
class MAPNIK_DECL datasource : private mapnik::noncopyable
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2012-01-15 07:35:40 +01:00
|
|
|
public:
|
2010-06-02 13:03:30 +02:00
|
|
|
enum datasource_t {
|
|
|
|
Vector,
|
|
|
|
Raster
|
|
|
|
};
|
2010-10-24 08:34:18 +02:00
|
|
|
|
2012-01-17 07:09:46 +01:00
|
|
|
enum geometry_t {
|
|
|
|
Point = 1,
|
|
|
|
LineString = 2,
|
|
|
|
Polygon = 3,
|
|
|
|
Collection = 4
|
2012-01-15 07:35:40 +01:00
|
|
|
};
|
|
|
|
|
2011-02-02 16:09:46 +01:00
|
|
|
datasource (parameters const& params)
|
2012-12-17 22:12:31 +01:00
|
|
|
: params_(params) {}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
/*!
|
|
|
|
* @brief Get the configuration parameters of the data source.
|
|
|
|
*
|
|
|
|
* These vary depending on the type of data source.
|
|
|
|
*
|
|
|
|
* @return The configuration parameters of the data source.
|
|
|
|
*/
|
|
|
|
parameters const& params() const
|
|
|
|
{
|
2012-12-17 22:12:31 +01:00
|
|
|
return params_;
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
/*!
|
|
|
|
* @brief Get the type of the datasource
|
|
|
|
* @return The type of the datasource (Vector or Raster)
|
|
|
|
*/
|
2012-03-28 21:59:40 +02:00
|
|
|
virtual datasource_t type() const = 0;
|
2012-09-03 19:02:39 +02:00
|
|
|
virtual featureset_ptr features(query const& q) const = 0;
|
2012-09-28 15:12:10 +02:00
|
|
|
virtual featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const = 0;
|
2012-03-28 21:59:40 +02:00
|
|
|
virtual box2d<double> envelope() const = 0;
|
|
|
|
virtual boost::optional<geometry_t> get_geometry_type() const = 0;
|
|
|
|
virtual layer_descriptor get_descriptor() const = 0;
|
|
|
|
virtual ~datasource() {}
|
2010-06-02 13:03:30 +02:00
|
|
|
protected:
|
2012-12-17 22:12:31 +01:00
|
|
|
parameters params_;
|
2010-06-02 13:03:30 +02:00
|
|
|
};
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2012-07-21 03:34:41 +02:00
|
|
|
typedef const char * datasource_name();
|
2012-12-17 19:03:07 +01:00
|
|
|
typedef datasource* create_ds(parameters const& params);
|
2010-06-02 13:03:30 +02:00
|
|
|
typedef void destroy_ds(datasource *ds);
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
class datasource_deleter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void operator() (datasource* ds)
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
delete ds;
|
|
|
|
}
|
|
|
|
};
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
typedef boost::shared_ptr<datasource> datasource_ptr;
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
#define DATASOURCE_PLUGIN(classname) \
|
2012-09-03 20:41:51 +02:00
|
|
|
extern "C" MAPNIK_EXP const char * datasource_name() \
|
2010-06-02 13:03:30 +02:00
|
|
|
{ \
|
|
|
|
return classname::name(); \
|
|
|
|
} \
|
2012-12-17 19:03:07 +01:00
|
|
|
extern "C" MAPNIK_EXP datasource* create(parameters const& params) \
|
2010-06-02 13:03:30 +02:00
|
|
|
{ \
|
2012-12-17 19:03:07 +01:00
|
|
|
return new classname(params); \
|
2010-06-02 13:03:30 +02:00
|
|
|
} \
|
|
|
|
extern "C" MAPNIK_EXP void destroy(datasource *ds) \
|
|
|
|
{ \
|
|
|
|
delete ds; \
|
2012-03-28 21:59:40 +02:00
|
|
|
}
|
2011-10-23 16:09:47 +02:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2006-10-04 13:22:18 +02:00
|
|
|
|
2011-10-23 16:09:47 +02:00
|
|
|
#endif // MAPNIK_DATASOURCE_HPP
|