Skip to content
Browse files

double csv parsing speeds when handling wkt encoded geometries - refs #…

  • Loading branch information...
1 parent bf3efbe commit a3254965fed2b3a7d294b7e34ea272a9702b5f7f @springmeyer springmeyer committed Aug 23, 2012
Showing with 15 additions and 59 deletions.
  1. +1 −4 include/mapnik/wkt/wkt_factory.hpp
  2. +2 −0 include/mapnik/wkt/wkt_grammar.hpp
  3. +12 −55 plugins/input/csv/csv_datasource.cpp
View
5 include/mapnik/wkt/wkt_factory.hpp
@@ -26,6 +26,7 @@
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/geometry.hpp>
+#include <mapnik/wkt/wkt_grammar.hpp>
// boost
#include <boost/utility.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
@@ -37,10 +38,6 @@
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);
#if BOOST_VERSION >= 104700
View
2 include/mapnik/wkt/wkt_grammar.hpp
@@ -97,6 +97,8 @@ namespace mapnik { namespace wkt {
: wkt_grammar::base_type(geometry_tagged_text)
{
using qi::no_case;
+ using qi::_1;
+ using qi::_2;
using boost::phoenix::push_back;
geometry_tagged_text = point_tagged_text
View
67 plugins/input/csv/csv_datasource.cpp
@@ -432,6 +432,7 @@ void csv_datasource::parse_csv(T& stream,
}
mapnik::transcoder tr(desc_.get_encoding());
+ mapnik::wkt_parser parse_wkt;
while (std::getline(stream,csv_line,newline))
{
@@ -538,69 +539,25 @@ void csv_datasource::parse_csv(T& stream,
break;
}
- // optimize simple "POINT (x y)"
- // using this shaved 2 seconds off csv that took 8 seconds total to parse
- if (value.find("POINT") == 0)
+ if (parse_wkt.parse(value, feature->paths()))
{
- using boost::phoenix::ref;
- 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();
- }
- }
+ parsed_wkt = true;
}
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
{
- 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();
- }
+ MAPNIK_LOG_ERROR(csv) << s.str();
}
}
}

0 comments on commit a325496

Please sign in to comment.
Something went wrong with that request. Please try again.