diff --git a/include/mapnik/json/feature_parser.hpp b/include/mapnik/json/feature_parser.hpp index 433d19e30..11d363154 100644 --- a/include/mapnik/json/feature_parser.hpp +++ b/include/mapnik/json/feature_parser.hpp @@ -25,25 +25,12 @@ // mapnik #include -#include - -// boost -#include -#include +// stl +#include namespace mapnik { namespace json { -inline bool from_geojson(std::string const& json, mapnik::feature_impl & feature) -{ - static const mapnik::transcoder tr("utf8"); - using iterator_type = char const*; - static const mapnik::json::feature_grammar g(tr); - using namespace boost::spirit; - standard::space_type space; - iterator_type start = json.c_str(); - iterator_type end = start + json.length(); - return qi::phrase_parse(start, end, (g)(boost::phoenix::ref(feature)), space); -} +bool from_geojson(std::string const& json, mapnik::feature_impl & feature); }} diff --git a/src/json/feature_from_geojson.cpp b/src/json/feature_from_geojson.cpp new file mode 100644 index 000000000..b4d0188c8 --- /dev/null +++ b/src/json/feature_from_geojson.cpp @@ -0,0 +1,45 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2016 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 + * + *****************************************************************************/ + + +// mapnik +#include +#include + +namespace mapnik { namespace json { + +bool from_geojson(std::string const& json, feature_impl & feature) +{ + try + { + const char* start = json.c_str(); + const char* end = start + json.length(); + mapnik::json::parse_feature(start, end, feature); + } + catch (...) + { + return false; + } + return true; +} + +}} diff --git a/src/json/geometry_from_geojson.cpp b/src/json/geometry_from_geojson.cpp new file mode 100644 index 000000000..58e1477d2 --- /dev/null +++ b/src/json/geometry_from_geojson.cpp @@ -0,0 +1,49 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2016 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 + * + *****************************************************************************/ + + +// mapnik +#include +#include +#include + +namespace mapnik { namespace json { + +bool from_geojson(std::string const& json, mapnik::geometry::geometry & geom) +{ + try + { + mapnik::context_ptr ctx = std::make_shared(); + mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx, -1)); // temp geometry holder + const char* start = json.c_str(); + const char* end = start + json.length(); + mapnik::json::parse_geometry(start, end, *feature); + geom = std::move(feature->get_geometry()); + } + catch (...) + { + return false; + } + return true; +} + +}}