Merge commit '562fada9d0f680f59b2d9f396c95320a0d753479' into harfbuzz

This commit is contained in:
Hermann Kraus 2013-03-16 13:03:11 +01:00
commit 77fadc8209
24 changed files with 436 additions and 389 deletions

View file

@ -16,6 +16,8 @@ mapnik:
clean:
@python scons/scons.py -c --config=cache --implicit-cache --max-drift=1
@if test -e ".sconsign.dblite"; then rm ".sconsign.dblite"; fi
@find ./ -name "*.os" -exec rm {} \;
@find ./ -name "*.o" -exec rm {} \;
distclean:
if test -e ".sconf_temp/"; then rm -r ".sconf_temp/"; fi

View file

@ -93,6 +93,8 @@ private:
typedef MAPNIK_DECL context<std::map<std::string,std::size_t> > context_type;
typedef MAPNIK_DECL boost::shared_ptr<context_type> context_ptr;
static const value default_value;
class MAPNIK_DECL feature_impl : private boost::noncopyable
{
friend class feature_kv_iterator;
@ -126,7 +128,6 @@ public:
put_new(key,value(val));
}
void put(context_type::key_type const& key, value const& val)
{
context_type::map_type::const_iterator itr = ctx_->mapping_.find(key);
@ -141,7 +142,6 @@ public:
}
}
void put_new(context_type::key_type const& key, value const& val)
{
context_type::map_type::const_iterator itr = ctx_->mapping_.find(key);
@ -158,7 +158,6 @@ public:
}
}
bool has_key(context_type::key_type const& key) const
{
return (ctx_->mapping_.find(key) != ctx_->mapping_.end());
@ -170,14 +169,14 @@ public:
if (itr != ctx_->mapping_.end())
return get(itr->second);
else
throw std::out_of_range(std::string("Key does not exist: '") + key + "'");
return default_value;
}
value_type const& get(std::size_t index) const
{
if (index < data_.size())
return data_[index];
throw std::out_of_range("Index out of range");
return default_value;
}
boost::optional<value_type const&> get_optional(std::size_t index) const

View file

@ -0,0 +1,74 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2012 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
*
*****************************************************************************/
#ifndef MAPNIK_TRIM_HPP
#define MAPNIK_TRIM_HPP
// stl
#include <string>
#include <algorithm>
namespace mapnik { namespace util {
/*
https://github.com/mapnik/mapnik/issues/1633
faster trim (than boost::trim)
that intentionally does not respect
std::locale to avoid overhead in cases
where the locale is not critical
*/
static inline bool not_whitespace(int ch)
{
if (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t') return false;
return true;
}
// trim from start
static inline std::string & ltrim(std::string & s)
{
s.erase(s.begin(), std::find_if(s.begin(), s.end(), not_whitespace));
return s;
}
// trim from end
static inline std::string & rtrim(std::string & s)
{
s.erase(std::find_if(s.rbegin(), s.rend(), not_whitespace).base(), s.end());
return s;
}
// trim from both ends
static inline void trim(std::string & s)
{
ltrim(rtrim(s));
}
static inline std::string trim_copy(std::string s)
{
return ltrim(rtrim(s));
}
}} // end of namespace mapnik
#endif // MAPNIK_TRIM_HPP

View file

@ -41,6 +41,7 @@
#include <mapnik/util/geometry_to_ds_type.hpp>
#include <mapnik/util/conversions.hpp>
#include <mapnik/boolean.hpp>
#include <mapnik/util/trim.hpp>
// stl
#include <sstream>
@ -68,7 +69,7 @@ csv_datasource::csv_datasource(parameters const& params, bool bind)
separator_(*params_.get<std::string>("separator", "")),
quote_(*params_.get<std::string>("quote", "")),
headers_(),
manual_headers_(boost::trim_copy(*params_.get<std::string>("headers", ""))),
manual_headers_(mapnik::util::trim_copy(*params_.get<std::string>("headers", ""))),
strict_(*params_.get<mapnik::boolean>("strict", false)),
quiet_(*params_.get<mapnik::boolean>("quiet", false)),
filesize_max_(*params_.get<float>("filesize_max", 20.0)), // MB
@ -196,7 +197,7 @@ void csv_datasource::parse_csv(T & stream,
// if user has not passed a separator manually
// then attempt to detect by reading first line
std::string sep = boost::trim_copy(separator);
std::string sep = mapnik::util::trim_copy(separator);
if (sep.empty())
{
// default to ','
@ -240,10 +241,10 @@ void csv_datasource::parse_csv(T & stream,
typedef boost::escaped_list_separator<char> escape_type;
std::string esc = boost::trim_copy(escape);
std::string esc = mapnik::util::trim_copy(escape);
if (esc.empty()) esc = "\\";
std::string quo = boost::trim_copy(quote);
std::string quo = mapnik::util::trim_copy(quote);
if (quo.empty()) quo = "\"";
MAPNIK_LOG_DEBUG(csv) << "csv_datasource: csv grammar: sep: '" << sep
@ -281,7 +282,7 @@ void csv_datasource::parse_csv(T & stream,
unsigned idx(0);
for (; beg != tok.end(); ++beg)
{
std::string val = boost::trim_copy(*beg);
std::string val = mapnik::util::trim_copy(*beg);
std::string lower_val = boost::algorithm::to_lower_copy(val);
if (lower_val == "wkt"
|| (lower_val.find("geom") != std::string::npos))
@ -324,7 +325,7 @@ void csv_datasource::parse_csv(T & stream,
Tokenizer::iterator beg = tok.begin();
std::string val;
if (beg != tok.end())
val = boost::trim_copy(*beg);
val = mapnik::util::trim_copy(*beg);
// skip blank lines
if (val.empty())
@ -338,7 +339,7 @@ void csv_datasource::parse_csv(T & stream,
for (; beg != tok.end(); ++beg)
{
++idx;
val = boost::trim_copy(*beg);
val = mapnik::util::trim_copy(*beg);
if (val.empty())
{
if (strict_)
@ -522,7 +523,7 @@ void csv_datasource::parse_csv(T & stream,
}
else
{
value = boost::trim_copy(*beg);
value = mapnik::util::trim_copy(*beg);
++beg;
}

View file

@ -32,9 +32,9 @@
#include <mapnik/sql_utils.hpp>
#include <mapnik/feature_factory.hpp>
#include <mapnik/util/conversions.hpp>
#include <mapnik/util/trim.hpp>
// boost
#include <boost/algorithm/string.hpp>
#include <boost/spirit/include/qi.hpp>
// stl
@ -182,8 +182,7 @@ feature_ptr postgis_featureset::next()
case 1042: //bpchar
{
std::string str(buf);
boost::trim(str);
std::string str = mapnik::util::trim_copy(buf);
feature->put(name, tr_->transcode(str.c_str()));
break;
}

View file

@ -44,6 +44,7 @@ shape_featureset<filterT>::shape_featureset(filterT const& filter,
: filter_(filter),
shape_(shape_name, false),
query_ext_(),
feature_bbox_(),
tr_(new transcoder(encoding)),
file_length_(file_length),
row_limit_(row_limit),
@ -62,176 +63,74 @@ feature_ptr shape_featureset<filterT>::next()
return feature_ptr();
}
std::streampos pos = shape_.shp().pos();
// skip null shapes
while (pos > 0 && pos < std::streampos(file_length_ * 2))
while (shape_.shp().pos() < std::streampos(file_length_ * 2))
{
shape_.move_to(pos);
if (shape_.type() == shape_io::shape_null)
shape_.move_to(shape_.shp().pos());
shape_file::record_type record(shape_.reclength_ * 2);
shape_.shp().read_record(record);
int type = record.read_ndr_integer();
// skip null shapes
if (type == shape_io::shape_null) continue;
feature_ptr feature(feature_factory::create(ctx_, shape_.id_));
switch (type)
{
pos += std::streampos(12);
}
else
case shape_io::shape_point:
case shape_io::shape_pointm:
case shape_io::shape_pointz:
{
double x = record.read_double();
double y = record.read_double();
if (!filter_.pass(mapnik::box2d<double>(x,y,x,y)))
continue;
std::auto_ptr<geometry_type> point(new geometry_type(mapnik::Point));
point->move_to(x, y);
feature->paths().push_back(point);
break;
}
}
if (pos < std::streampos(file_length_ * 2))
{
int type = shape_.type();
feature_ptr feature(feature_factory::create(ctx_, shape_.id_));
if (type == shape_io::shape_point)
case shape_io::shape_multipoint:
case shape_io::shape_multipointm:
case shape_io::shape_multipointz:
{
double x = shape_.shp().read_double();
double y = shape_.shp().read_double();
geometry_type* point = new geometry_type(mapnik::Point);
point->move_to(x, y);
feature->add_geometry(point);
++count_;
shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue;
int num_points = record.read_ndr_integer();
for (int i = 0; i < num_points; ++i)
{
double x = record.read_double();
double y = record.read_double();
std::auto_ptr<geometry_type> point(new geometry_type(mapnik::Point));
point->move_to(x, y);
feature->paths().push_back(point);
}
break;
}
else if (type == shape_io::shape_pointm)
case shape_io::shape_polyline:
case shape_io::shape_polylinem:
case shape_io::shape_polylinez:
{
double x = shape_.shp().read_double();
double y = shape_.shp().read_double();
// skip m
shape_.shp().skip(8);
geometry_type* point = new geometry_type(mapnik::Point);
point->move_to(x, y);
feature->add_geometry(point);
++count_;
shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue;
shape_io::read_polyline(record, feature->paths());
break;
}
else if (type == shape_io::shape_pointz)
case shape_io::shape_polygon:
case shape_io::shape_polygonm:
case shape_io::shape_polygonz:
{
double x = shape_.shp().read_double();
double y = shape_.shp().read_double();
// skip z
shape_.shp().skip(8);
// skip m if exists: OGR bug
if (shape_.reclength_ == 18)
{
shape_.shp().skip(8);
}
geometry_type* point = new geometry_type(mapnik::Point);
point->move_to(x, y);
feature->add_geometry(point);
++count_;
shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue;
shape_io::read_polygon(record, feature->paths());
break;
}
else
{
// skip shapes
for (;;)
{
std::streampos pos = shape_.shp().pos();
if (shape_.type() == shape_io::shape_null)
{
pos += std::streampos(12);
// TODO handle the shapes
MAPNIK_LOG_WARN(shape) << "shape_featureset: NULL SHAPE len=" << shape_.reclength_;
}
else if (filter_.pass(shape_.current_extent()))
{
break;
}
else
{
pos += std::streampos(2 * shape_.reclength_ - 36);
}
if (pos > 0 && pos < std::streampos(file_length_ * 2))
{
shape_.move_to(pos);
}
else
{
MAPNIK_LOG_DEBUG(shape) << "shape_featureset: Total shapes read=" << count_;
return feature_ptr();
}
}
switch (type)
{
case shape_io::shape_multipoint:
{
int num_points = shape_.shp().read_ndr_integer();
for (int i = 0; i < num_points; ++i)
{
double x = shape_.shp().read_double();
double y = shape_.shp().read_double();
geometry_type* point = new geometry_type(mapnik::Point);
point->move_to(x, y);
feature->add_geometry(point);
}
++count_;
break;
}
case shape_io::shape_multipointm:
{
int num_points = shape_.shp().read_ndr_integer();
for (int i = 0; i < num_points; ++i)
{
double x = shape_.shp().read_double();
double y = shape_.shp().read_double();
geometry_type* point = new geometry_type(mapnik::Point);
point->move_to(x, y);
feature->add_geometry(point);
}
// skip m
shape_.shp().skip(2 * 8 + 8 * num_points);
++count_;
break;
}
case shape_io::shape_multipointz:
{
int num_points = shape_.shp().read_ndr_integer();
for (int i = 0; i < num_points; ++i)
{
double x = shape_.shp().read_double();
double y = shape_.shp().read_double();
geometry_type* point = new geometry_type(mapnik::Point);
point->move_to(x, y);
feature->add_geometry(point);
}
// skip z
shape_.shp().skip(2 * 8 + 8 * num_points);
// check if we have measure data
if (shape_.reclength_ == (unsigned)(num_points * 16 + 36))
{
// skip m
shape_.shp().skip(2 * 8 + 8 * num_points);
}
++count_;
break;
}
case shape_io::shape_polyline:
case shape_io::shape_polylinem:
case shape_io::shape_polylinez:
{
shape_.read_polyline(feature->paths());
++count_;
break;
}
case shape_io::shape_polygon:
case shape_io::shape_polygonm:
case shape_io::shape_polygonz:
{
shape_.read_polygon(feature->paths());
++count_;
break;
}
}
default :
MAPNIK_LOG_DEBUG(shape) << "shape_featureset: Unsupported type" << type;
return feature_ptr();
}
// FIXME: https://github.com/mapnik/mapnik/issues/1020
feature->set_id(shape_.id_);
if (attr_ids_.size())
@ -251,15 +150,12 @@ feature_ptr shape_featureset<filterT>::next()
MAPNIK_LOG_ERROR(shape) << "Shape Plugin: error processing attributes";
}
}
++count_;
return feature;
}
else
{
MAPNIK_LOG_DEBUG(shape) << "shape_featureset: Total shapes read=" << count_;
return feature_ptr();
}
MAPNIK_LOG_DEBUG(shape) << "shape_featureset: Total shapes read=" << count_;
return feature_ptr();
}
template <typename filterT>

View file

@ -56,6 +56,7 @@ private:
filterT filter_;
shape_io shape_;
box2d<double> query_ext_;
mutable box2d<double> feature_bbox_;
boost::scoped_ptr<transcoder> tr_;
long file_length_;
std::vector<int> attr_ids_;

View file

@ -49,7 +49,8 @@ shape_index_featureset<filterT>::shape_index_featureset(filterT const& filter,
shape_(shape),
tr_(new transcoder(encoding)),
row_limit_(row_limit),
count_(0)
count_(0),
feature_bbox_()
{
shape_.shp().skip(100);
setup_attributes(ctx_, attribute_names, shape_name, shape_,attr_ids_);
@ -58,18 +59,18 @@ shape_index_featureset<filterT>::shape_index_featureset(filterT const& filter,
if (index)
{
#ifdef SHAPE_MEMORY_MAPPED_FILE
//shp_index<filterT,stream<mapped_file_source> >::query(filter, index->file(), ids_);
shp_index<filterT,boost::interprocess::ibufferstream>::query(filter, index->file(), ids_);
//shp_index<filterT,stream<mapped_file_source> >::query(filter, index->file(), offsets_);
shp_index<filterT,boost::interprocess::ibufferstream>::query(filter, index->file(), offsets_);
#else
shp_index<filterT,std::ifstream>::query(filter, index->file(), ids_);
shp_index<filterT,std::ifstream>::query(filter, index->file(), offsets_);
#endif
}
std::sort(ids_.begin(), ids_.end());
std::sort(offsets_.begin(), offsets_.end());
MAPNIK_LOG_DEBUG(shape) << "shape_index_featureset: Query size=" << ids_.size();
MAPNIK_LOG_DEBUG(shape) << "shape_index_featureset: Query size=" << offsets_.size();
itr_ = ids_.begin();
itr_ = offsets_.begin();
}
template <typename filterT>
@ -80,103 +81,67 @@ feature_ptr shape_index_featureset<filterT>::next()
return feature_ptr();
}
if (itr_ != ids_.end())
while ( itr_ != offsets_.end())
{
int pos = *itr_++;
shape_.move_to(pos);
int type = shape_.type();
shape_.move_to(*itr_++);
shape_file::record_type record(shape_.reclength_ * 2);
shape_.shp().read_record(record);
int type = record.read_ndr_integer();
feature_ptr feature(feature_factory::create(ctx_,shape_.id_));
if (type == shape_io::shape_point)
{
double x = shape_.shp().read_double();
double y = shape_.shp().read_double();
geometry_type* point = new geometry_type(mapnik::Point);
point->move_to(x, y);
feature->add_geometry(point);
++count_;
}
else if (type == shape_io::shape_pointm)
{
double x = shape_.shp().read_double();
double y = shape_.shp().read_double();
// skip m
shape_.shp().skip(8);
geometry_type* point = new geometry_type(mapnik::Point);
point->move_to(x, y);
feature->add_geometry(point);
++count_;
}
else if (type == shape_io::shape_pointz)
{
double x = shape_.shp().read_double();
double y = shape_.shp().read_double();
// skip z
shape_.shp().skip(8);
// skip m if exists
if (shape_.reclength_ == 8 + 36)
{
shape_.shp().skip(8);
}
geometry_type* point = new geometry_type(mapnik::Point);
point->move_to(x, y);
feature->add_geometry(point);
++count_;
}
else
{
while(! filter_.pass(shape_.current_extent()) &&
itr_ != ids_.end())
{
if (shape_.type() != shape_io::shape_null)
{
pos = *itr_++;
shape_.move_to(pos);
}
else
{
return feature_ptr();
}
}
switch (type)
{
case shape_io::shape_multipoint:
case shape_io::shape_multipointm:
case shape_io::shape_multipointz:
{
int num_points = shape_.shp().read_ndr_integer();
for (int i = 0; i < num_points; ++i)
{
double x = shape_.shp().read_double();
double y = shape_.shp().read_double();
geometry_type* point = new geometry_type(mapnik::Point);
point->move_to(x, y);
feature->add_geometry(point);
}
// ignore m and z for now
++count_;
break;
}
case shape_io::shape_polyline:
case shape_io::shape_polylinem:
case shape_io::shape_polylinez:
{
shape_.read_polyline(feature->paths());
++count_;
break;
}
case shape_io::shape_polygon:
case shape_io::shape_polygonm:
case shape_io::shape_polygonz:
{
shape_.read_polygon(feature->paths());
++count_;
break;
}
}
switch (type)
{
case shape_io::shape_point:
case shape_io::shape_pointm:
case shape_io::shape_pointz:
{
double x = record.read_double();
double y = record.read_double();
std::auto_ptr<geometry_type> point(new geometry_type(mapnik::Point));
point->move_to(x, y);
feature->paths().push_back(point);
break;
}
case shape_io::shape_multipoint:
case shape_io::shape_multipointm:
case shape_io::shape_multipointz:
{
shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue;
int num_points = record.read_ndr_integer();
for (int i = 0; i < num_points; ++i)
{
double x = record.read_double();
double y = record.read_double();
std::auto_ptr<geometry_type> point(new geometry_type(mapnik::Point));
point->move_to(x, y);
feature->paths().push_back(point);
}
break;
}
case shape_io::shape_polyline:
case shape_io::shape_polylinem:
case shape_io::shape_polylinez:
{
shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue;
shape_io::read_polyline(record,feature->paths());
break;
}
case shape_io::shape_polygon:
case shape_io::shape_polygonm:
case shape_io::shape_polygonz:
{
shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue;
shape_io::read_polygon(record,feature->paths());
break;
}
default :
MAPNIK_LOG_DEBUG(shape) << "shape_index_featureset: Unsupported type" << type;
return feature_ptr();
}
// FIXME
feature->set_id(shape_.id_);
if (attr_ids_.size())
@ -196,14 +161,12 @@ feature_ptr shape_index_featureset<filterT>::next()
MAPNIK_LOG_ERROR(shape) << "Shape Plugin: error processing attributes";
}
}
++count_;
return feature;
}
else
{
MAPNIK_LOG_DEBUG(shape) << "shape_index_featureset: " << count_ << " features";
return feature_ptr();
}
MAPNIK_LOG_DEBUG(shape) << "shape_index_featureset: " << count_ << " features";
return feature_ptr();
}

View file

@ -60,11 +60,12 @@ private:
context_ptr ctx_;
shape_io & shape_;
boost::scoped_ptr<transcoder> tr_;
std::vector<int> ids_;
std::vector<int>::iterator itr_;
std::vector<std::streampos> offsets_;
std::vector<std::streampos>::iterator itr_;
std::vector<int> attr_ids_;
const int row_limit_;
mutable int count_;
mutable box2d<double> feature_bbox_;
};
#endif // SHAPE_INDEX_FEATURESET_HPP

View file

@ -65,27 +65,11 @@ shape_io::shape_io(std::string const& shape_name, bool open_index)
shape_io::~shape_io() {}
void shape_io::move_to(int pos)
void shape_io::move_to(std::streampos pos)
{
shp_.seek(pos);
id_ = shp_.read_xdr_integer();
reclength_ = shp_.read_xdr_integer();
type_ = static_cast<shape_io::shapeType>(shp_.read_ndr_integer());
if (type_ != shape_null && type_ != shape_point && type_ != shape_pointm && type_ != shape_pointz)
{
shp_.read_envelope(cur_extent_);
}
}
shape_io::shapeType shape_io::type() const
{
return type_;
}
const box2d<double>& shape_io::current_extent() const
{
return cur_extent_;
}
shape_file& shape_io::shp()
@ -98,11 +82,17 @@ dbf_file& shape_io::dbf()
return dbf_;
}
void shape_io::read_polyline(mapnik::geometry_container & geom)
void shape_io::read_bbox(shape_file::record_type & record, mapnik::box2d<double> & bbox)
{
shape_file::record_type record(reclength_ * 2 - 36);
shp_.read_record(record);
double lox = record.read_double();
double loy = record.read_double();
double hix = record.read_double();
double hiy = record.read_double();
bbox.init(lox, loy, hix, hiy);
}
void shape_io::read_polyline( shape_file::record_type & record, mapnik::geometry_container & geom)
{
int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer();
if (num_parts == 1)
@ -155,30 +145,10 @@ void shape_io::read_polyline(mapnik::geometry_container & geom)
geom.push_back(line);
}
}
// z-range
//double z0=record.read_double();
//double z1=record.read_double();
//for (int i=0;i<num_points;++i)
// {
// double z=record.read_double();
// }
// m-range
//double m0=record.read_double();
//double m1=record.read_double();
//for (int i=0;i<num_points;++i)
//{
// double m=record.read_double();
//}
}
void shape_io::read_polygon(mapnik::geometry_container & geom)
void shape_io::read_polygon(shape_file::record_type & record, mapnik::geometry_container & geom)
{
shape_file::record_type record(reclength_ * 2 - 36);
shp_.read_record(record);
int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer();
std::vector<int> parts(num_parts);
@ -218,20 +188,4 @@ void shape_io::read_polygon(mapnik::geometry_container & geom)
geom.push_back(poly);
}
// z-range
//double z0=record.read_double();
//double z1=record.read_double();
//for (int i=0;i<num_points;++i)
//{
// double z=record.read_double();
//}
// m-range
//double m0=record.read_double();
//double m1=record.read_double();
//for (int i=0;i<num_points;++i)
//{
// double m=record.read_double();
//}
}

View file

@ -72,11 +72,11 @@ public:
return (index_ && index_->is_open());
}
void move_to(int id);
shapeType type() const;
const box2d<double>& current_extent() const;
void read_polyline(mapnik::geometry_container & geom);
void read_polygon(mapnik::geometry_container & geom);
void move_to(std::streampos pos);
static void read_bbox(shape_file::record_type & record, mapnik::box2d<double> & bbox);
static void read_polyline(shape_file::record_type & record,mapnik::geometry_container & geom);
static void read_polygon(shape_file::record_type & record,mapnik::geometry_container & geom);
shapeType type_;
shape_file shp_;
dbf_file dbf_;

View file

@ -20,8 +20,8 @@
*
*****************************************************************************/
#ifndef SHP_INDEX_HH
#define SHP_INDEX_HH
#ifndef SHP_INDEX_HPP
#define SHP_INDEX_HPP
// stl
#include <fstream>
@ -38,7 +38,7 @@ template <typename filterT, typename IStream = std::ifstream>
class shp_index
{
public:
static void query(const filterT& filter, IStream& file,std::vector<int>& pos);
static void query(filterT const& filter, IStream& file,std::vector<std::streampos>& pos);
private:
shp_index();
~shp_index();
@ -46,18 +46,18 @@ private:
shp_index& operator=(const shp_index&);
static int read_ndr_integer(IStream& in);
static void read_envelope(IStream& in, box2d<double>& envelope);
static void query_node(const filterT& filter, IStream& in, std::vector<int>& pos);
static void query_node(const filterT& filter, IStream& in, std::vector<std::streampos>& pos);
};
template <typename filterT, typename IStream>
void shp_index<filterT, IStream>::query(const filterT& filter, IStream& file, std::vector<int>& pos)
void shp_index<filterT, IStream>::query(const filterT& filter, IStream& file, std::vector<std::streampos>& pos)
{
file.seekg(16, std::ios::beg);
query_node(filter, file, pos);
}
template <typename filterT, typename IStream>
void shp_index<filterT, IStream>::query_node(const filterT& filter, IStream& file, std::vector<int>& ids)
void shp_index<filterT, IStream>::query_node(const filterT& filter, IStream& file, std::vector<std::streampos>& ids)
{
int offset = read_ndr_integer(file);
@ -100,4 +100,4 @@ void shp_index<filterT, IStream>::read_envelope(IStream& file, box2d<double>& en
file.read(reinterpret_cast<char*>(&envelope), sizeof(envelope));
}
#endif // SHP_INDEX_HH
#endif // SHP_INDEX_HPP

View file

@ -22,13 +22,13 @@
// mapnik
#include <mapnik/box2d.hpp>
#include <mapnik/util/trim.hpp>
// stl
#include <stdexcept>
// boost
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/spirit/include/qi.hpp>
// agg
@ -359,14 +359,17 @@ bool box2d<T>::from_string(std::string const& s)
for (boost::tokenizer<boost::char_separator<char> >::iterator beg = tok.begin();
beg != tok.end(); ++beg)
{
std::string item(*beg);
boost::trim(item);
std::string item = mapnik::util::trim_copy(*beg);
// note: we intentionally do not use mapnik::util::conversions::string2double
// here to ensure that shapeindex can statically compile mapnik::box2d without
// needing to link to libmapnik
std::string::const_iterator str_beg = item.begin();
std::string::const_iterator str_end = item.end();
bool r = boost::spirit::qi::phrase_parse(str_beg,str_end,boost::spirit::qi::double_,boost::spirit::ascii::space,d[i]);
bool r = boost::spirit::qi::phrase_parse(str_beg,
str_end,
boost::spirit::qi::double_,
boost::spirit::ascii::space,
d[i]);
if (!(r && (str_beg == str_end)))
{
break;

View file

@ -23,15 +23,14 @@
#ifdef HAVE_LIBXML2
// mapnik
#include <mapnik/debug.hpp>
#include <mapnik/xml_loader.hpp>
#include <mapnik/xml_node.hpp>
#include <mapnik/config_error.hpp>
#include <mapnik/util/trim.hpp>
// boost
#include <boost/utility.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/algorithm/string/trim.hpp>
// libxml
#include <libxml/parser.h>
@ -39,8 +38,6 @@
#include <libxml/parserInternals.h>
#include <libxml/xinclude.h>
using namespace std;
#define DEFAULT_OPTIONS (XML_PARSE_NOERROR | XML_PARSE_NOENT | XML_PARSE_NOBLANKS | XML_PARSE_DTDLOAD | XML_PARSE_NOCDATA)
namespace mapnik
@ -75,7 +72,7 @@ public:
boost::filesystem::path path(filename);
if (!boost::filesystem::exists(path))
{
throw config_error(string("Could not load map file: File does not exist"), 0, filename);
throw config_error(std::string("Could not load map file: File does not exist"), 0, filename);
}
xmlDocPtr doc = xmlCtxtReadFile(ctx_, filename.c_str(), encoding_, options_);
@ -92,13 +89,6 @@ public:
throw config_error(msg, error->line, error->file);
}
}
/*
if ( ! ctx->valid )
{
MAPNIK_LOG_WARN(libxml2_loader) << "libxml2_loader: Failed to validate DTD.";
}
*/
load(doc, node);
}
@ -114,7 +104,7 @@ public:
{
boost::filesystem::path path(base_path);
if (!boost::filesystem::exists(path)) {
throw config_error(string("Could not locate base_path '") +
throw config_error(std::string("Could not locate base_path '") +
base_path + "': file or directory does not exist");
}
}
@ -186,7 +176,7 @@ private:
case XML_TEXT_NODE:
{
std::string trimmed((const char*)cur_node->content);
boost::algorithm::trim(trimmed);
mapnik::util::trim(trimmed);
if (trimmed.empty()) break; //Don't add empty text nodes
node.add_child(trimmed, cur_node->line, true);
}

View file

@ -48,12 +48,12 @@
#include <mapnik/config_error.hpp>
#include <mapnik/util/dasharray_parser.hpp>
#include <mapnik/util/conversions.hpp>
#include <mapnik/util/trim.hpp>
#include <mapnik/marker_cache.hpp>
// boost
#include <boost/optional.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/tokenizer.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
@ -255,8 +255,7 @@ void map_parser::parse_map(Map & map, xml_node const& pt, std::string const& bas
for (boost::tokenizer<boost::char_separator<char> >::iterator beg = tokens.begin();
beg != tokens.end(); ++beg)
{
std::string item(*beg);
boost::trim(item);
std::string item = mapnik::util::trim_copy(*beg);
if (!mapnik::util::string2int(item,n[i]))
{
throw config_error(std::string("Invalid version string encountered: '")

View file

@ -23,9 +23,7 @@
// mapnik
#include <mapnik/projection.hpp>
#include <mapnik/utils.hpp>
// boost
#include <boost/algorithm/string.hpp>
#include <mapnik/util/trim.hpp>
// proj4
#include <proj_api.h>
@ -151,10 +149,7 @@ void projection::init()
std::string projection::expanded() const
{
if (proj_) {
std::string def(pj_get_def( proj_, 0 ));
//boost::algorithm::ireplace_first(def,params_,"");
boost::trim(def);
return def;
return mapnik::util::trim_copy(pj_get_def( proj_, 0 ));
}
return std::string("");
}

View file

@ -31,16 +31,15 @@
#include <boost/property_tree/detail/xml_parser_read_rapidxml.hpp>
#include <mapnik/xml_node.hpp>
#include <mapnik/config_error.hpp>
#include <mapnik/util/trim.hpp>
// boost
#include <boost/utility.hpp>
#include <boost/algorithm/string/trim.hpp>
// stl
#include <iostream>
#include <fstream>
using namespace std;
namespace rapidxml = boost::property_tree::detail::rapidxml;
namespace mapnik
{
@ -108,7 +107,7 @@ public:
// {
// boost::filesystem::path path(base_path);
// if (!boost::filesystem::exists(path)) {
// throw config_error(string("Could not locate base_path '") +
// throw config_error(std::string("Could not locate base_path '") +
// base_path + "': file or directory does not exist");
// }
// }
@ -145,7 +144,7 @@ private:
case rapidxml::node_cdata:
{
std::string trimmed(cur_node->value());
boost::trim(trimmed);
mapnik::util::trim(trimmed);
if (trimmed.empty()) break; //Don't add empty text nodes
node.add_child(trimmed, 0, true);
}

View file

@ -0,0 +1,4 @@
<Map>
<!-- backspace-->

</Map>

View file

@ -0,0 +1,2 @@
i|wkt
1|LINESTRING(-10 0, 0 20, 10 0, 15 5)
1 i wkt
2 1 LINESTRING(-10 0, 0 20, 10 0, 15 5)

View file

@ -0,0 +1,109 @@
{
"keys": [
"",
"1"
],
"data": {},
"grid": [
" ! ",
" !! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! !!! ",
" ! !!! ",
" ! !! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ",
" ! ",
" ! ! ! ",
" ! ! ",
" ! ! ! ",
" ! ! ",
" ! ! ! ",
" ! ! ",
" ! ! ! ",
" ! ! ",
" ! ! ! ",
" ! ! ",
" ! ! ! ",
" ! ! ",
" ! ! ! ",
" ! ! ",
" ! ! ! ",
" ! ! ",
" ! ! ! ",
" ! ! ",
" ! ! ! ",
" ! ! ",
" ! ! ! ",
" ! ! ",
" ! ! ! ",
" ! ! ",
" ! !! "
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View file

@ -0,0 +1,21 @@
<Map>
<Style name="line" filter-mode="first" >
<Rule>
<LineSymbolizer stroke="#000000" />
</Rule>
</Style>
<Style name="point-placement" filter-mode="first" >
<Rule>
<MarkersSymbolizer placement="point" marker-type="ellipse" fill="blue" />
</Rule>
</Style>
<Layer name="carto_tests">
<StyleName>line</StyleName>
<StyleName>point-placement</StyleName>
<Datasource>
<Parameter name="type">csv</Parameter>
<Parameter name="file">../data/marker-on-line.csv</Parameter>
<Parameter name="separator">|</Parameter>
</Datasource>
</Layer>
</Map>

View file

@ -41,6 +41,8 @@ files = [
{'name': "lines-6", 'sizes': sizes_few_square},
{'name': "lines-shield", 'sizes': sizes_few_square,'bbox':default_text_box},
{'name': "marker-multi-policy", 'sizes':[(600,400)]},
{'name': "marker-on-line", 'sizes':[(600,400)],
'bbox': mapnik.Box2d(-10, 0, 15, 20)},
{'name': "marker_line_placement_on_points"},
{'name': "whole-centroid", 'sizes':[(600,400)],
'bbox': mapnik.Box2d(736908, 4390316, 2060771, 5942346)},

View file

@ -5,6 +5,36 @@ import os
import sys
import struct
ShapeType = { 0 : "NullShape",
1 : "Point",
3 : "PolyLine",
5 : "Polygon",
8 : "MultiPoint",
11: "PointZ",
13: "PolyLineZ",
15: "PolygonZ",
18: "MultiPointZ",
21: "PointM",
23: "PolyLineM",
25: "PolygonM",
28: "MultiPointM",
31: "MultiPatch"}
def test_record(_type, record) :
if _type == 0:
print "NULL shape"
elif _type == 11: #PointZ
test_pointz(record)
def test_pointz(record):
if len(record) != 36 :
print>>sys.stderr,"BAD SHAPE FILE: expected 36 bytes got",len(record)
sys.exit(1)
_type,x,y,z,m = struct.unpack("<idddd",record)
if _type != 11:
print>>sys.stderr,"BAD SHAPE FILE: expected PointZ or NullShape got",_type
sys.exit(1)
if __name__ == "__main__" :
if len(sys.argv) !=2:
@ -24,11 +54,12 @@ if __name__ == "__main__" :
# SHP header
_,_,_,_,_,_,shp_file_length = header[0].unpack_from(shp.read(28))
_,_,lox,loy,hix,hiy,_,_,_,_ = header[1].unpack_from(shp.read(72))
version,_type,lox,loy,hix,hiy,_,_,_,_ = header[1].unpack_from(shp.read(72))
print "SHX FILE_LENGTH=",shx_file_length,"bytes"
print "SHP FILE_LENGTH=",shp_file_length,"bytes"
print "TYPE", ShapeType[_type]
print "BBOX(",lox,loy,hix,hiy,")"
record_header = struct.Struct(">II")
record = struct.Struct(">II")
@ -38,10 +69,12 @@ if __name__ == "__main__" :
offset,shx_content_length = record.unpack_from(shx.read(8))
shp.seek(offset*2, os.SEEK_SET)
record_number,content_length = record_header.unpack_from(shp.read(8))
#print (2*offset),record_number,content_length
if shx_content_length <> content_length:
print "BAD SHAPE FILE: content_lenght mismatch in SHP and SHX",shx_content_length,content_length
sys.exit(1)
##
test_record(_type, shp.read(2*content_length))
calc_total_size +=(4 + content_length)
count+=1