2006-03-31 10:32:02 +00:00
|
|
|
/*****************************************************************************
|
2012-02-02 01:53:35 +00:00
|
|
|
*
|
2006-03-31 10:32:02 +00:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
2005-06-14 15:06:59 +00:00
|
|
|
*
|
2014-11-20 14:25:50 +00:00
|
|
|
* Copyright (C) 2014 Artem Pavlenko
|
2005-06-14 15:06:59 +00:00
|
|
|
*
|
2006-03-31 10:32:02 +00: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 15:06:59 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2006-03-31 10:32:02 +00: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 15:06:59 +00:00
|
|
|
*
|
2006-03-31 10:32:02 +00:00
|
|
|
*****************************************************************************/
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2011-10-23 14:09:47 +00:00
|
|
|
#ifndef MAPNIK_DATASOURCE_HPP
|
|
|
|
#define MAPNIK_DATASOURCE_HPP
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2006-10-04 11:22:18 +00:00
|
|
|
// mapnik
|
|
|
|
#include <mapnik/config.hpp>
|
|
|
|
#include <mapnik/params.hpp>
|
|
|
|
#include <mapnik/feature.hpp>
|
|
|
|
#include <mapnik/query.hpp>
|
2014-07-23 06:57:06 +00:00
|
|
|
#include <mapnik/featureset.hpp>
|
2006-10-04 11:22:18 +00:00
|
|
|
#include <mapnik/feature_layer_desc.hpp>
|
2015-01-07 12:11:09 +00:00
|
|
|
#include <mapnik/util/noncopyable.hpp>
|
2013-05-16 15:08:42 +00:00
|
|
|
#include <mapnik/feature_style_processor_context.hpp>
|
2015-03-24 11:13:31 +00:00
|
|
|
#include <mapnik/datasource_geometry_type.hpp>
|
2011-10-23 14:09:47 +00:00
|
|
|
|
2007-10-08 18:10:31 +00:00
|
|
|
// stl
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2015-02-24 10:17:00 +00:00
|
|
|
#include <memory>
|
2005-12-12 13:15:33 +00:00
|
|
|
|
2010-10-24 08:04:16 +00:00
|
|
|
namespace mapnik {
|
2012-01-15 06:35:40 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
class MAPNIK_DECL datasource_exception : public std::exception
|
|
|
|
{
|
|
|
|
public:
|
2012-09-03 18:41:51 +00:00
|
|
|
datasource_exception(std::string const& message)
|
2012-03-28 19:59:40 +00:00
|
|
|
: message_(message)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~datasource_exception() throw()
|
|
|
|
{
|
|
|
|
}
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
virtual const char* what() const throw()
|
2005-06-14 15:06:59 +00:00
|
|
|
{
|
2010-06-02 11:03:30 +00:00
|
|
|
return message_.c_str();
|
|
|
|
}
|
2012-03-28 19:59:40 +00:00
|
|
|
private:
|
|
|
|
std::string message_;
|
2010-06-02 11:03:30 +00:00
|
|
|
};
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2015-01-07 12:11:09 +00:00
|
|
|
class MAPNIK_DECL datasource : private util::noncopyable
|
2010-06-02 11:03:30 +00:00
|
|
|
{
|
2012-01-15 06:35:40 +00:00
|
|
|
public:
|
2014-12-02 06:20:18 +00:00
|
|
|
enum datasource_t : std::uint8_t {
|
2010-06-02 11:03:30 +00:00
|
|
|
Vector,
|
|
|
|
Raster
|
|
|
|
};
|
2010-10-24 06:34:18 +00:00
|
|
|
|
2011-02-02 15:09:46 +00:00
|
|
|
datasource (parameters const& params)
|
2012-12-17 21:12:31 +00:00
|
|
|
: params_(params) {}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2010-06-02 11:03:30 +00: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 21:12:31 +00:00
|
|
|
return params_;
|
2010-06-02 11:03:30 +00:00
|
|
|
}
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2013-02-22 20:40:40 +00:00
|
|
|
parameters & params()
|
|
|
|
{
|
|
|
|
return params_;
|
|
|
|
}
|
|
|
|
|
2014-05-28 14:16:39 +00:00
|
|
|
bool operator==(datasource const& rhs) const
|
|
|
|
{
|
|
|
|
return params_ == rhs.params();
|
|
|
|
}
|
|
|
|
|
2015-04-25 08:34:25 +00:00
|
|
|
bool operator!=(datasource const& rhs) const
|
|
|
|
{
|
|
|
|
return !(*this == rhs);
|
|
|
|
}
|
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
/*!
|
|
|
|
* @brief Get the type of the datasource
|
|
|
|
* @return The type of the datasource (Vector or Raster)
|
|
|
|
*/
|
2012-03-28 19:59:40 +00:00
|
|
|
virtual datasource_t type() const = 0;
|
2013-05-16 15:08:42 +00:00
|
|
|
virtual processor_context_ptr get_context(feature_style_context_map&) const { return processor_context_ptr(); }
|
2015-03-19 11:09:07 +00:00
|
|
|
virtual featureset_ptr features_with_context(query const& q, processor_context_ptr /*ctx*/) const
|
2013-05-16 15:08:42 +00:00
|
|
|
{
|
|
|
|
// default implementation without context use features method
|
|
|
|
return features(q);
|
|
|
|
}
|
2015-03-24 11:13:31 +00:00
|
|
|
virtual boost::optional<datasource_geometry_t> get_geometry_type() const = 0;
|
2012-09-03 17:02:39 +00:00
|
|
|
virtual featureset_ptr features(query const& q) const = 0;
|
2012-09-28 13:12:10 +00:00
|
|
|
virtual featureset_ptr features_at_point(coord2d const& pt, double tol = 0) const = 0;
|
2012-03-28 19:59:40 +00:00
|
|
|
virtual box2d<double> envelope() const = 0;
|
|
|
|
virtual layer_descriptor get_descriptor() const = 0;
|
|
|
|
virtual ~datasource() {}
|
2010-06-02 11:03:30 +00:00
|
|
|
protected:
|
2012-12-17 21:12:31 +00:00
|
|
|
parameters params_;
|
2010-06-02 11:03:30 +00:00
|
|
|
};
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2014-07-07 17:23:15 +00:00
|
|
|
using datasource_name = const char* (*)();
|
|
|
|
using create_ds = datasource* (*) (parameters const&);
|
|
|
|
using destroy_ds = void (*) (datasource *);
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2010-06-02 11:03:30 +00:00
|
|
|
class datasource_deleter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void operator() (datasource* ds)
|
2005-06-14 15:06:59 +00:00
|
|
|
{
|
2010-06-02 11:03:30 +00:00
|
|
|
delete ds;
|
|
|
|
}
|
|
|
|
};
|
2005-06-14 15:06:59 +00:00
|
|
|
|
2014-07-07 17:23:15 +00:00
|
|
|
using datasource_ptr = std::shared_ptr<datasource>;
|
2012-02-02 01:53:35 +00:00
|
|
|
|
2013-05-16 18:33:23 +00:00
|
|
|
#ifdef MAPNIK_STATIC_PLUGINS
|
|
|
|
#define DATASOURCE_PLUGIN(classname)
|
|
|
|
#else
|
|
|
|
#define DATASOURCE_PLUGIN(classname) \
|
|
|
|
extern "C" MAPNIK_EXP const char * datasource_name() \
|
|
|
|
{ \
|
|
|
|
return classname::name(); \
|
|
|
|
} \
|
|
|
|
extern "C" MAPNIK_EXP datasource* create(parameters const& params) \
|
|
|
|
{ \
|
|
|
|
return new classname(params); \
|
|
|
|
} \
|
|
|
|
extern "C" MAPNIK_EXP void destroy(datasource *ds) \
|
|
|
|
{ \
|
|
|
|
delete ds; \
|
|
|
|
}
|
|
|
|
#endif
|
2011-10-23 14:09:47 +00:00
|
|
|
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|
2006-10-04 11:22:18 +00:00
|
|
|
|
2011-10-23 14:09:47 +00:00
|
|
|
#endif // MAPNIK_DATASOURCE_HPP
|