2006-10-03 08:44:04 +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
|
|
|
*
|
2006-03-31 10:32:02 +00:00
|
|
|
* Copyright (C) 2006 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.
|
2005-06-14 15:06:59 +00:00
|
|
|
*
|
2006-03-31 10:32:02 +00:00
|
|
|
* 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
|
|
|
//$Id: datasource_cache.cpp 23 2005-03-22 22:16:34Z pavlenko $
|
|
|
|
|
2006-10-04 11:22:18 +00:00
|
|
|
// stl
|
2005-06-14 15:06:59 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <stdexcept>
|
2006-10-04 11:22:18 +00:00
|
|
|
// boost
|
2005-12-23 12:31:54 +00:00
|
|
|
#include <boost/thread/mutex.hpp>
|
2005-06-14 15:06:59 +00:00
|
|
|
#include <boost/filesystem/operations.hpp>
|
2006-10-04 11:22:18 +00:00
|
|
|
// mapnik
|
|
|
|
#include <mapnik/datasource_cache.hpp>
|
2005-06-14 15:06:59 +00:00
|
|
|
|
|
|
|
namespace mapnik
|
|
|
|
{
|
|
|
|
using namespace std;
|
|
|
|
using namespace boost;
|
|
|
|
|
|
|
|
datasource_cache::datasource_cache()
|
|
|
|
{
|
|
|
|
if (lt_dlinit()) throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
datasource_cache::~datasource_cache()
|
|
|
|
{
|
|
|
|
lt_dlexit();
|
|
|
|
}
|
|
|
|
|
2005-12-12 13:15:33 +00:00
|
|
|
std::map<string,boost::shared_ptr<PluginInfo> > datasource_cache::plugins_;
|
2005-06-14 15:06:59 +00:00
|
|
|
bool datasource_cache::registered_=false;
|
|
|
|
|
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 11:02:59 +00:00
|
|
|
datasource_ptr datasource_cache::create(const parameters& params)
|
2005-06-14 15:06:59 +00: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 11:02:59 +00:00
|
|
|
datasource_ptr ds;
|
2005-06-14 15:06:59 +00:00
|
|
|
try
|
|
|
|
{
|
2005-12-14 17:01:09 +00:00
|
|
|
const std::string type=params.get("type");
|
2005-12-12 13:15:33 +00:00
|
|
|
map<string,boost::shared_ptr<PluginInfo> >::iterator itr=plugins_.find(type);
|
2005-06-14 15:06:59 +00:00
|
|
|
if (itr!=plugins_.end())
|
|
|
|
{
|
|
|
|
if (itr->second->handle())
|
|
|
|
{
|
2006-10-04 11:22:18 +00:00
|
|
|
create_ds* create_datasource =
|
|
|
|
(create_ds*) lt_dlsym(itr->second->handle(), "create");
|
2005-06-14 15:06:59 +00:00
|
|
|
if (!create_datasource)
|
|
|
|
{
|
2006-03-19 21:53:47 +00:00
|
|
|
std::clog << "Cannot load symbols: " << lt_dlerror() << std::endl;
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
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 11:02:59 +00:00
|
|
|
ds=datasource_ptr(create_datasource(params),datasource_deleter());
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-19 21:53:47 +00:00
|
|
|
std::clog << "Cannot load library: " << " "<< lt_dlerror() << std::endl;
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-19 17:13:33 +00:00
|
|
|
#ifdef MAPNIK_DEBUG
|
2006-03-19 21:53:47 +00:00
|
|
|
std::clog<<"datasource="<<ds<<" type="<<type<<std::endl;
|
2006-11-19 17:13:33 +00:00
|
|
|
#endif
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|
2006-10-03 08:44:04 +00:00
|
|
|
catch (datasource_exception& ex)
|
|
|
|
{
|
2006-11-19 17:13:33 +00:00
|
|
|
std::clog << ex.what() << "\n";
|
2006-10-03 08:44:04 +00:00
|
|
|
}
|
2005-06-14 15:06:59 +00:00
|
|
|
catch (...)
|
|
|
|
{
|
2006-11-19 17:13:33 +00:00
|
|
|
std::clog << " exception caught\n";
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|
2005-12-12 13:15:33 +00:00
|
|
|
return ds;
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool datasource_cache::insert(const std::string& type,const lt_dlhandle module)
|
|
|
|
{
|
2006-10-04 11:22:18 +00:00
|
|
|
return plugins_.insert(make_pair(type,boost::shared_ptr<PluginInfo>
|
|
|
|
(new PluginInfo(type,module)))).second;
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void datasource_cache::register_datasources(const std::string& str)
|
|
|
|
{
|
2006-03-22 15:57:12 +00:00
|
|
|
mutex::scoped_lock lock(mapnik::singleton<mapnik::datasource_cache,
|
2006-10-03 08:44:04 +00:00
|
|
|
mapnik::CreateStatic>::mutex_);
|
2006-03-22 15:57:12 +00:00
|
|
|
filesystem::path path(str);
|
|
|
|
filesystem::directory_iterator end_itr;
|
|
|
|
if (exists(path))
|
2005-06-14 15:06:59 +00:00
|
|
|
{
|
2006-03-22 15:57:12 +00:00
|
|
|
for (filesystem::directory_iterator itr(path);itr!=end_itr;++itr )
|
|
|
|
{
|
|
|
|
if (!is_directory( *itr ) && itr->leaf()[0]!='.')
|
2005-06-14 15:06:59 +00:00
|
|
|
{
|
2006-03-22 15:57:12 +00:00
|
|
|
lt_dlhandle module=lt_dlopenext(itr->string().c_str());
|
|
|
|
if (module)
|
|
|
|
{
|
2006-10-04 11:22:18 +00:00
|
|
|
datasource_name* ds_name =
|
|
|
|
(datasource_name*) lt_dlsym(module, "datasource_name");
|
2006-03-22 15:57:12 +00:00
|
|
|
if (ds_name && insert(ds_name(),module))
|
2006-11-19 17:13:33 +00:00
|
|
|
{
|
|
|
|
#ifdef MAPNIK_DEBUG
|
2006-03-22 15:57:12 +00:00
|
|
|
std::clog<<"registered datasource : "<<ds_name()<<std::endl;
|
2006-11-19 17:13:33 +00:00
|
|
|
#endif
|
2006-03-22 15:57:12 +00:00
|
|
|
registered_=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-19 17:13:33 +00:00
|
|
|
std::clog << lt_dlerror() << "\n";
|
2006-03-22 15:57:12 +00:00
|
|
|
}
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|
2005-09-09 09:38:37 +00:00
|
|
|
}
|
2005-06-14 15:06:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|