2011-10-22 16:04:05 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2015-06-16 12:49:16 +02:00
|
|
|
* Copyright (C) 2015 Artem Pavlenko
|
2011-10-22 16:04:05 +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,
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2012-04-08 02:20:56 +02:00
|
|
|
// mapnik
|
|
|
|
#include <mapnik/debug.hpp>
|
2011-12-05 23:30:55 +01:00
|
|
|
#include <mapnik/datasource.hpp>
|
2013-06-03 04:28:24 +02:00
|
|
|
#include <mapnik/util/fs.hpp>
|
2012-04-08 02:20:56 +02:00
|
|
|
|
|
|
|
// std
|
|
|
|
#include <sstream>
|
|
|
|
|
2009-02-15 14:51:07 +01:00
|
|
|
#include "dataset_deliverer.h"
|
|
|
|
|
2013-11-27 16:52:47 +01:00
|
|
|
osm_dataset * dataset_deliverer::dataset = nullptr;
|
2009-02-17 00:10:58 +01:00
|
|
|
std::string dataset_deliverer::last_bbox = "";
|
2010-11-13 22:43:38 +01:00
|
|
|
std::string dataset_deliverer::last_filename = "";
|
2009-02-15 14:51:07 +01:00
|
|
|
|
2011-10-22 16:04:05 +02:00
|
|
|
osm_dataset* dataset_deliverer::load_from_file(const string& file, const string& parser)
|
2009-02-15 14:51:07 +01:00
|
|
|
{
|
2011-10-22 16:04:05 +02:00
|
|
|
// Only actually load from file if we haven't done so already
|
2013-11-27 16:52:47 +01:00
|
|
|
if (dataset == nullptr)
|
2011-10-22 16:04:05 +02:00
|
|
|
{
|
2013-06-03 04:28:24 +02:00
|
|
|
if (!mapnik::util::exists(file))
|
2011-12-05 23:30:55 +01:00
|
|
|
{
|
|
|
|
throw mapnik::datasource_exception("OSM Plugin: '" + file + "' does not exist");
|
|
|
|
}
|
|
|
|
|
2011-10-22 16:04:05 +02:00
|
|
|
dataset = new osm_dataset;
|
|
|
|
if (dataset->load(file.c_str(), parser) == false)
|
|
|
|
{
|
2013-11-27 16:52:47 +01:00
|
|
|
return nullptr;
|
2011-10-22 16:04:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
atexit(dataset_deliverer::release);
|
|
|
|
last_filename = file;
|
|
|
|
}
|
|
|
|
else if(file != last_filename)
|
|
|
|
{
|
|
|
|
dataset = new osm_dataset;
|
|
|
|
if (dataset->load(file.c_str(), parser) == false)
|
|
|
|
{
|
2013-11-27 16:52:47 +01:00
|
|
|
return nullptr;
|
2011-10-22 16:04:05 +02:00
|
|
|
}
|
|
|
|
last_filename = file;
|
|
|
|
}
|
|
|
|
return dataset;
|
2009-02-15 14:51:07 +01:00
|
|
|
}
|