use c file io wrapper in geojson/topojson plugins
This commit is contained in:
parent
9684880062
commit
4e8125d2ad
2 changed files with 11 additions and 23 deletions
|
@ -42,6 +42,7 @@
|
|||
#include <mapnik/projection.hpp>
|
||||
#include <mapnik/util/geometry_to_ds_type.hpp>
|
||||
#include <mapnik/util/variant.hpp>
|
||||
#include <mapnik/util/file_io.hpp>
|
||||
#include <mapnik/json/feature_collection_grammar.hpp>
|
||||
|
||||
#include <boost/spirit/include/qi.hpp>
|
||||
|
@ -126,21 +127,14 @@ geojson_datasource::geojson_datasource(parameters const& params)
|
|||
}
|
||||
else
|
||||
{
|
||||
#ifdef _WINDOWS
|
||||
std::unique_ptr<std::FILE, int (*)(std::FILE *)> file(_wfopen(mapnik::utf8_to_utf16(filename_).c_str(), L"rb"), fclose);
|
||||
#else
|
||||
std::unique_ptr<std::FILE, int (*)(std::FILE *)> file(std::fopen(filename_.c_str(),"rb"), std::fclose);
|
||||
#endif
|
||||
if (file == nullptr)
|
||||
mapnik::util::file file(filename_);
|
||||
if (!file.open())
|
||||
{
|
||||
throw mapnik::datasource_exception("GeoJSON Plugin: could not open: '" + filename_ + "'");
|
||||
throw mapnik::datasource_exception("TopoJSON Plugin: could not open: '" + filename_ + "'");
|
||||
}
|
||||
std::fseek(file.get(), 0, SEEK_END);
|
||||
std::size_t file_size = std::ftell(file.get());
|
||||
std::fseek(file.get(), 0, SEEK_SET);
|
||||
std::string file_buffer;
|
||||
file_buffer.resize(file_size);
|
||||
std::fread(&file_buffer[0], file_size, 1, file.get());
|
||||
file_buffer.resize(file.size());
|
||||
std::fread(&file_buffer[0], file.size(), 1, file.get());
|
||||
parse_geojson(file_buffer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <mapnik/json/topojson_grammar_impl.hpp>
|
||||
#include <mapnik/json/topojson_utils.hpp>
|
||||
#include <mapnik/util/variant.hpp>
|
||||
#include <mapnik/util/file_io.hpp>
|
||||
#include <mapnik/make_unique.hpp>
|
||||
|
||||
using mapnik::datasource;
|
||||
|
@ -170,21 +171,14 @@ topojson_datasource::topojson_datasource(parameters const& params)
|
|||
}
|
||||
else
|
||||
{
|
||||
#ifdef _WINDOWS
|
||||
std::unique_ptr<std::FILE, int (*)(std::FILE *)> file(_wfopen(mapnik::utf8_to_utf16(filename_).c_str(), L"rb"), fclose);
|
||||
#else
|
||||
std::unique_ptr<std::FILE, int (*)(std::FILE *)> file(std::fopen(filename_.c_str(),"rb"), std::fclose);
|
||||
#endif
|
||||
if (file == nullptr)
|
||||
mapnik::util::file file(filename_);
|
||||
if (!file.open())
|
||||
{
|
||||
throw mapnik::datasource_exception("TopoJSON Plugin: could not open: '" + filename_ + "'");
|
||||
}
|
||||
std::fseek(file.get(), 0, SEEK_END);
|
||||
std::size_t file_size = std::ftell(file.get());
|
||||
std::fseek(file.get(), 0, SEEK_SET);
|
||||
std::string file_buffer;
|
||||
file_buffer.resize(file_size);
|
||||
std::fread(&file_buffer[0], file_size, 1, file.get());
|
||||
file_buffer.resize(file.size());
|
||||
std::fread(&file_buffer[0], file.size(), 1, file.get());
|
||||
parse_topojson(file_buffer);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue