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
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* Copyright (C) 2006 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
|
|
|
|
|
|
|
//$Id: datasource.hpp 43 2005-04-22 18:52:47Z pavlenko $
|
|
|
|
|
|
|
|
#ifndef DATASOURCE_HPP
|
|
|
|
#define DATASOURCE_HPP
|
2006-10-04 13:22:18 +02:00
|
|
|
// mapnik
|
|
|
|
#include <mapnik/config.hpp>
|
|
|
|
#include <mapnik/ctrans.hpp>
|
|
|
|
#include <mapnik/params.hpp>
|
|
|
|
#include <mapnik/feature.hpp>
|
|
|
|
#include <mapnik/query.hpp>
|
|
|
|
#include <mapnik/feature_layer_desc.hpp>
|
2007-10-08 20:10:31 +02:00
|
|
|
// boost
|
|
|
|
#include <boost/utility.hpp>
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
// stl
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2005-12-12 14:15:33 +01:00
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
namespace mapnik {
|
|
|
|
typedef MAPNIK_DECL boost::shared_ptr<Feature> feature_ptr;
|
|
|
|
|
2006-03-22 16:52:29 +01:00
|
|
|
struct MAPNIK_DECL Featureset
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2005-09-08 15:09:04 +02:00
|
|
|
virtual feature_ptr next()=0;
|
2005-06-14 17:06:59 +02:00
|
|
|
virtual ~Featureset() {};
|
|
|
|
};
|
1. hit_test implementation for geometry objects:
bool hit_test(double x, double y, double tol);
2. added image_view(unsigned x, unsigned y, unsigned width, unsigned height)
allowing to select region from image data e.g (in Python):
im = Image(2048,2048)
view = im.view(0,0,256,256)
save_to_file(filename,type, view)
3. changed envelope method to return vy value in datasource classes
4. features_at_point impl for shape and postgis plug-ins
2006-11-25 12:02:59 +01:00
|
|
|
|
|
|
|
typedef MAPNIK_DECL boost::shared_ptr<Featureset> featureset_ptr;
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2006-03-22 16:52:29 +01:00
|
|
|
class MAPNIK_DECL datasource_exception : public std::exception
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
|
|
|
private:
|
2007-09-25 20:47:12 +02:00
|
|
|
std::string message_;
|
2005-06-14 17:06:59 +02:00
|
|
|
public:
|
2007-09-25 20:47:12 +02:00
|
|
|
datasource_exception(const std::string& message=std::string("no reason"))
|
2006-05-23 18:52:10 +02:00
|
|
|
:message_(message) {}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2006-05-23 18:52:10 +02:00
|
|
|
~datasource_exception() throw() {}
|
|
|
|
virtual const char* what() const throw()
|
|
|
|
{
|
|
|
|
return message_.c_str();
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
};
|
|
|
|
|
2006-05-23 18:52:10 +02:00
|
|
|
class MAPNIK_DECL datasource : private boost::noncopyable
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2006-05-23 18:52:10 +02:00
|
|
|
public:
|
2007-03-16 11:11:37 +01:00
|
|
|
enum datasource_t {
|
2006-05-23 18:52:10 +02:00
|
|
|
Vector,
|
|
|
|
Raster
|
|
|
|
};
|
|
|
|
|
|
|
|
datasource (parameters const& params)
|
|
|
|
: params_(params) {}
|
|
|
|
|
2009-03-01 22:09:09 +01: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.
|
|
|
|
*/
|
2006-05-23 18:52:10 +02:00
|
|
|
parameters const& params() const
|
|
|
|
{
|
|
|
|
return params_;
|
|
|
|
}
|
|
|
|
|
2009-03-01 22:09:09 +01:00
|
|
|
/*!
|
|
|
|
* @brief Get the type of the datasource
|
|
|
|
* @return The type of the datasource (Vector or Raster)
|
|
|
|
*/
|
2006-05-23 18:52:10 +02:00
|
|
|
virtual int type() const=0;
|
2009-03-01 22:09:09 +01:00
|
|
|
|
2006-05-23 18:52:10 +02:00
|
|
|
virtual featureset_ptr features(const query& q) const=0;
|
2006-10-16 23:29:54 +02:00
|
|
|
virtual featureset_ptr features_at_point(coord2d const& pt) const=0;
|
1. hit_test implementation for geometry objects:
bool hit_test(double x, double y, double tol);
2. added image_view(unsigned x, unsigned y, unsigned width, unsigned height)
allowing to select region from image data e.g (in Python):
im = Image(2048,2048)
view = im.view(0,0,256,256)
save_to_file(filename,type, view)
3. changed envelope method to return vy value in datasource classes
4. features_at_point impl for shape and postgis plug-ins
2006-11-25 12:02:59 +01:00
|
|
|
virtual Envelope<double> envelope() const=0;
|
|
|
|
virtual layer_descriptor get_descriptor() const=0;
|
2006-05-23 18:52:10 +02:00
|
|
|
virtual ~datasource() {};
|
2006-11-29 13:28:17 +01:00
|
|
|
protected:
|
|
|
|
parameters params_;
|
2005-06-14 17:06:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::string datasource_name();
|
2005-12-14 18:01:09 +01:00
|
|
|
typedef datasource* create_ds(const parameters& params);
|
2005-06-14 17:06:59 +02:00
|
|
|
typedef void destroy_ds(datasource *ds);
|
|
|
|
|
2005-12-12 14:15:33 +01:00
|
|
|
|
|
|
|
class datasource_deleter
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2005-12-12 14:15:33 +01:00
|
|
|
public:
|
2006-05-23 18:52:10 +02:00
|
|
|
void operator() (datasource* ds)
|
|
|
|
{
|
|
|
|
delete ds;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
};
|
|
|
|
|
1. hit_test implementation for geometry objects:
bool hit_test(double x, double y, double tol);
2. added image_view(unsigned x, unsigned y, unsigned width, unsigned height)
allowing to select region from image data e.g (in Python):
im = Image(2048,2048)
view = im.view(0,0,256,256)
save_to_file(filename,type, view)
3. changed envelope method to return vy value in datasource classes
4. features_at_point impl for shape and postgis plug-ins
2006-11-25 12:02:59 +01:00
|
|
|
typedef boost::shared_ptr<datasource> datasource_ptr;
|
2005-12-12 14:15:33 +01:00
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
|
|
|
|
#define DATASOURCE_PLUGIN(classname) \
|
2007-01-17 12:43:11 +01:00
|
|
|
extern "C" MAPNIK_EXP std::string datasource_name() \
|
2006-10-04 13:22:18 +02:00
|
|
|
{ \
|
|
|
|
return classname::name(); \
|
|
|
|
} \
|
2007-01-17 12:43:11 +01:00
|
|
|
extern "C" MAPNIK_EXP datasource* create(const parameters ¶ms) \
|
2006-05-23 18:52:10 +02:00
|
|
|
{ \
|
|
|
|
return new classname(params); \
|
|
|
|
} \
|
2007-01-17 12:43:11 +01:00
|
|
|
extern "C" MAPNIK_EXP void destroy(datasource *ds) \
|
2006-05-23 18:52:10 +02:00
|
|
|
{ \
|
|
|
|
delete ds; \
|
|
|
|
} \
|
2006-10-04 13:22:18 +02:00
|
|
|
//
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2006-10-04 13:22:18 +02:00
|
|
|
|
|
|
|
#endif //DATASOURCE_HPP
|