Merge branch 'master' into spirit-x3

This commit is contained in:
artemp 2016-02-18 11:46:26 +01:00
commit c646fa686c
5 changed files with 39 additions and 25 deletions

View file

@ -37,6 +37,16 @@ using mapnik::query;
namespace mapnik { namespace util {
template <typename InputStream>
bool check_spatial_index(InputStream& in)
{
char header[17]; // mapnik-index
std::memset(header, 0, 17);
in.read(header,16);
return (std::strncmp(header, "mapnik-index",12) == 0);
}
template <typename Value, typename Filter, typename InputStream>
class spatial_index
{
@ -53,23 +63,13 @@ private:
static void read_envelope(InputStream& in, box2d<double>& envelope);
static void query_node(Filter const& filter, InputStream& in, std::vector<Value> & results);
static void query_first_n_impl(Filter const& filter, InputStream& in, std::vector<Value> & results, std::size_t count);
static bool check_header(InputStream& in);
};
template <typename Value, typename Filter, typename InputStream>
bool spatial_index<Value, Filter, InputStream>::check_header(InputStream& in)
{
static_assert(std::is_standard_layout<Value>::value, "Values stored in quad-tree must be standard layout type");
char header[17]; // mapnik-index
std::memset(header, 0, 17);
in.read(header,16);
return (std::strncmp(header, "mapnik-index",12) == 0);
}
template <typename Value, typename Filter, typename InputStream>
box2d<double> spatial_index<Value, Filter, InputStream>::bounding_box(InputStream& in)
{
if (!check_header(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)");
static_assert(std::is_standard_layout<Value>::value, "Values stored in quad-tree must be standard layout type");
if (!check_spatial_index(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)");
in.seekg(16 + 4, std::ios::beg);
box2d<double> box;
read_envelope(in, box);
@ -80,7 +80,8 @@ box2d<double> spatial_index<Value, Filter, InputStream>::bounding_box(InputStrea
template <typename Value, typename Filter, typename InputStream>
void spatial_index<Value, Filter, InputStream>::query(Filter const& filter, InputStream& in, std::vector<Value>& results)
{
if (!check_header(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)");
static_assert(std::is_standard_layout<Value>::value, "Values stored in quad-tree must be standard layout type");
if (!check_spatial_index(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)");
in.seekg(16, std::ios::beg);
query_node(filter, in, results);
}
@ -115,7 +116,8 @@ void spatial_index<Value, Filter, InputStream>::query_node(Filter const& filter,
template <typename Value, typename Filter, typename InputStream>
void spatial_index<Value, Filter, InputStream>::query_first_n(Filter const& filter, InputStream& in, std::vector<Value>& results, std::size_t count)
{
if (!check_header(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)");
static_assert(std::is_standard_layout<Value>::value, "Values stored in quad-tree must be standard layout type");
if (!check_spatial_index(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)");
in.seekg(16, std::ios::beg);
query_first_n_impl(filter, in, results, count);
}

View file

@ -47,6 +47,12 @@ namespace mapnik {
using value_base = util::variant<value_null, value_bool, value_integer,value_double, value_unicode_string>;
inline void to_utf8(mapnik::value_unicode_string const& input, std::string & target)
{
target.clear(); // mimic previous target.assign(...) semantics
input.toUTF8String(target); // this appends to target
}
namespace detail {
namespace {

View file

@ -211,7 +211,7 @@ std::tuple<char, bool, char, char> autodect_csv_flavour(T & stream, std::size_t
if (has_newline)
{
std::istringstream ss(buffer.data());
std::istringstream ss(std::string(buffer.begin(), buffer.end()));
std::size_t num_columns = 0;
for (std::string line; csv_utils::getline_csv(ss, line, newline, quote) && !ss.eof(); )
{

View file

@ -98,11 +98,11 @@ shape_datasource::shape_datasource(parameters const& params)
mapnik::progress_timer __stats2__(std::clog, "shape_datasource::init(get_column_description)");
#endif
std::unique_ptr<shape_io> shape_ref = std::make_unique<shape_io>(shape_name_);
init(*shape_ref);
for (int i=0;i<shape_ref->dbf().num_fields();++i)
shape_io shape(shape_name_);
init(shape);
for (int i = 0; i < shape.dbf().num_fields(); ++i)
{
field_descriptor const& fd = shape_ref->dbf().descriptor(i);
field_descriptor const& fd = shape.dbf().descriptor(i);
std::string fld_name=fd.name_;
switch (fd.type_)
{

View file

@ -23,16 +23,16 @@
#ifndef SHAPE_IO_HPP
#define SHAPE_IO_HPP
// stl
#include <memory>
#include <ios>
// mapnik
#include <mapnik/box2d.hpp>
#include <mapnik/util/noncopyable.hpp>
#include <mapnik/util/spatial_index.hpp>
// boost
#include <boost/optional.hpp>
// stl
#include <memory>
//
#include "dbfile.hpp"
#include "shapefile.hpp"
@ -72,7 +72,13 @@ public:
inline bool has_index() const
{
return (index_ && index_->is_open());
if (index_ && index_->is_open())
{
bool status = mapnik::util::check_spatial_index(index_->file());
index_->seek(0);// rewind
return status;
}
return false;
}
inline int id() const { return id_;}