Skip to content

Commit

Permalink
double csv parsing speeds when handling wkt encoded geometries - refs #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Aug 23, 2012
1 parent bf3efbe commit a325496
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 59 deletions.
5 changes: 1 addition & 4 deletions include/mapnik/wkt/wkt_factory.hpp
Expand Up @@ -26,6 +26,7 @@
// mapnik // mapnik
#include <mapnik/config.hpp> #include <mapnik/config.hpp>
#include <mapnik/geometry.hpp> #include <mapnik/geometry.hpp>
#include <mapnik/wkt/wkt_grammar.hpp>
// boost // boost
#include <boost/utility.hpp> #include <boost/utility.hpp>
#include <boost/ptr_container/ptr_vector.hpp> #include <boost/ptr_container/ptr_vector.hpp>
Expand All @@ -37,10 +38,6 @@


namespace mapnik { namespace mapnik {


namespace wkt {
template <typename Iterator> struct wkt_collection_grammar;
}

MAPNIK_DECL bool from_wkt(std::string const& wkt, boost::ptr_vector<geometry_type> & paths); MAPNIK_DECL bool from_wkt(std::string const& wkt, boost::ptr_vector<geometry_type> & paths);


#if BOOST_VERSION >= 104700 #if BOOST_VERSION >= 104700
Expand Down
2 changes: 2 additions & 0 deletions include/mapnik/wkt/wkt_grammar.hpp
Expand Up @@ -97,6 +97,8 @@ namespace mapnik { namespace wkt {
: wkt_grammar::base_type(geometry_tagged_text) : wkt_grammar::base_type(geometry_tagged_text)
{ {
using qi::no_case; using qi::no_case;
using qi::_1;
using qi::_2;
using boost::phoenix::push_back; using boost::phoenix::push_back;


geometry_tagged_text = point_tagged_text geometry_tagged_text = point_tagged_text
Expand Down
67 changes: 12 additions & 55 deletions plugins/input/csv/csv_datasource.cpp
Expand Up @@ -432,6 +432,7 @@ void csv_datasource::parse_csv(T& stream,
} }


mapnik::transcoder tr(desc_.get_encoding()); mapnik::transcoder tr(desc_.get_encoding());
mapnik::wkt_parser parse_wkt;


while (std::getline(stream,csv_line,newline)) while (std::getline(stream,csv_line,newline))
{ {
Expand Down Expand Up @@ -538,69 +539,25 @@ void csv_datasource::parse_csv(T& stream,
break; break;
} }


// optimize simple "POINT (x y)" if (parse_wkt.parse(value, feature->paths()))
// using this shaved 2 seconds off csv that took 8 seconds total to parse
if (value.find("POINT") == 0)
{ {
using boost::phoenix::ref; parsed_wkt = true;
using boost::spirit::qi::_1;
std::string::const_iterator str_beg = value.begin();
std::string::const_iterator str_end = value.end();
bool r = qi::phrase_parse(str_beg,str_end,
(
qi::lit("POINT") >> '('
>> double_[ref(x) = _1]
>> double_[ref(y) = _1] >> ')'
),
ascii::space);

if (r && (str_beg == str_end))
{
mapnik::geometry_type * pt = new mapnik::geometry_type(mapnik::Point);
pt->move_to(x,y);
feature->add_geometry(pt);
parsed_wkt = true;
}
else
{
std::ostringstream s;
s << "CSV Plugin: expected well known text geometry: could not parse row "
<< line_number
<< ",column "
<< i << " - found: '"
<< value << "'";
if (strict_)
{
throw mapnik::datasource_exception(s.str());
}
else
{
MAPNIK_LOG_ERROR(csv) << s.str();
}
}
} }
else else
{ {
if (mapnik::from_wkt(value, feature->paths())) std::ostringstream s;
s << "CSV Plugin: expected well known text geometry: could not parse row "
<< line_number
<< ",column "
<< i << " - found: '"
<< value << "'";
if (strict_)
{ {
parsed_wkt = true; throw mapnik::datasource_exception(s.str());
} }
else else
{ {
std::ostringstream s; MAPNIK_LOG_ERROR(csv) << s.str();
s << "CSV Plugin: expected well known text geometry: could not parse row "
<< line_number
<< ",column "
<< i << " - found: '"
<< value << "'";
if (strict_)
{
throw mapnik::datasource_exception(s.str());
}
else
{
MAPNIK_LOG_ERROR(csv) << s.str();
}
} }
} }
} }
Expand Down

0 comments on commit a325496

Please sign in to comment.