2011-10-22 14:04:05 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2011-12-05 22:30:55 +00:00
|
|
|
#include <mapnik/datasource.hpp>
|
|
|
|
#include <boost/filesystem/operations.hpp>
|
2009-02-15 13:51:07 +00:00
|
|
|
#include "dataset_deliverer.h"
|
|
|
|
#include "basiccurl.h"
|
|
|
|
#include <sstream>
|
|
|
|
|
2011-10-22 14:04:05 +00:00
|
|
|
osm_dataset * dataset_deliverer::dataset = NULL;
|
2009-02-16 23:10:58 +00:00
|
|
|
std::string dataset_deliverer::last_bbox = "";
|
2010-11-13 21:43:38 +00:00
|
|
|
std::string dataset_deliverer::last_filename = "";
|
2009-02-15 13:51:07 +00:00
|
|
|
|
2011-10-22 14:04:05 +00:00
|
|
|
osm_dataset* dataset_deliverer::load_from_file(const string& file, const string& parser)
|
2009-02-15 13:51:07 +00:00
|
|
|
{
|
2011-10-22 14:04:05 +00:00
|
|
|
// Only actually load from file if we haven't done so already
|
|
|
|
if (dataset == NULL)
|
|
|
|
{
|
2011-12-05 22:30:55 +00:00
|
|
|
if (!boost::filesystem::exists(file))
|
|
|
|
{
|
|
|
|
throw mapnik::datasource_exception("OSM Plugin: '" + file + "' does not exist");
|
|
|
|
}
|
|
|
|
|
2011-10-22 14:04:05 +00:00
|
|
|
dataset = new osm_dataset;
|
|
|
|
if (dataset->load(file.c_str(), parser) == false)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
atexit(dataset_deliverer::release);
|
|
|
|
last_filename = file;
|
|
|
|
}
|
|
|
|
else if(file != last_filename)
|
|
|
|
{
|
|
|
|
dataset = new osm_dataset;
|
|
|
|
if (dataset->load(file.c_str(), parser) == false)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
last_filename = file;
|
|
|
|
}
|
|
|
|
return dataset;
|
2009-02-15 13:51:07 +00:00
|
|
|
}
|
|
|
|
|
2011-10-22 14:04:05 +00:00
|
|
|
osm_dataset* dataset_deliverer::load_from_url(const string& url, const string& bbox, const string& parser)
|
2009-02-15 13:51:07 +00:00
|
|
|
{
|
2011-10-22 14:04:05 +00:00
|
|
|
if (dataset == NULL)
|
|
|
|
{
|
|
|
|
dataset = new osm_dataset;
|
|
|
|
if (dataset->load_from_url(url.c_str(), bbox, parser) == false)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
atexit(dataset_deliverer::release);
|
2011-11-14 03:37:50 +00:00
|
|
|
last_bbox = bbox;
|
2011-10-22 14:04:05 +00:00
|
|
|
}
|
|
|
|
else if (bbox != last_bbox)
|
|
|
|
{
|
2009-04-28 20:07:18 +00:00
|
|
|
#ifdef MAPNIK_DEBUG
|
2011-10-22 14:04:05 +00:00
|
|
|
std::cerr << "Osm Plugin: BBOXES ARE DIFFERENT: " << last_bbox << "," << bbox << std::endl;
|
2009-04-28 20:07:18 +00:00
|
|
|
#endif
|
|
|
|
|
2011-10-22 14:04:05 +00:00
|
|
|
// Reload the dataset
|
|
|
|
dataset->clear();
|
|
|
|
if (dataset->load_from_url(url.c_str(), bbox, parser) == false)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_bbox = bbox;
|
|
|
|
}
|
|
|
|
return dataset;
|
2009-02-15 13:51:07 +00:00
|
|
|
}
|