From 95ca3a02f84f1c560936dedfdd28ffb25309866d Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Sun, 22 Mar 2015 12:14:11 -0700 Subject: [PATCH] update pgsql2sqlite to new geometry --- include/mapnik/geometry_empty.hpp | 84 +++++++++++++++++++++++++++++ utils/pgsql2sqlite/pgsql2sqlite.hpp | 11 ++-- 2 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 include/mapnik/geometry_empty.hpp diff --git a/include/mapnik/geometry_empty.hpp b/include/mapnik/geometry_empty.hpp new file mode 100644 index 000000000..2b8146392 --- /dev/null +++ b/include/mapnik/geometry_empty.hpp @@ -0,0 +1,84 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2015 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_GEOMETRY_EMPTY_HPP +#define MAPNIK_GEOMETRY_EMPTY_HPP + +#include + +namespace mapnik { namespace new_geometry { + +namespace detail { + +struct geometry_empty +{ + bool operator() (mapnik::new_geometry::geometry const& geom) const + { + return mapnik::util::apply_visitor(*this, geom); + } + + bool operator() (mapnik::new_geometry::point const&) const + { + return false; + } + + bool operator() (mapnik::new_geometry::line_string const& geom) const + { + return geom.empty(); + } + + bool operator() (mapnik::new_geometry::polygon const& geom) const + { + return geom.empty(); + } + + bool operator() (mapnik::new_geometry::multi_point const& geom) const + { + return geom.empty(); + } + + bool operator() (mapnik::new_geometry::multi_line_string const& geom) const + { + return geom.empty(); + } + + bool operator() (mapnik::new_geometry::multi_polygon const& geom) const + { + return geom.empty(); + } + + bool operator() (mapnik::new_geometry::geometry_collection const& geom) const + { + return geom.empty(); + } +}; + +} + +inline bool empty(mapnik::new_geometry::geometry const& geom) +{ + return detail::geometry_empty()(geom); +} + +}} + +#endif // MAPNIK_GEOMETRY_EMPTY_HPP diff --git a/utils/pgsql2sqlite/pgsql2sqlite.hpp b/utils/pgsql2sqlite/pgsql2sqlite.hpp index 52483033d..73d5c439f 100644 --- a/utils/pgsql2sqlite/pgsql2sqlite.hpp +++ b/utils/pgsql2sqlite/pgsql2sqlite.hpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include "connection_manager.hpp" #include "cursorresultset.hpp" @@ -387,21 +389,18 @@ void pgsql2sqlite(Connection conn, if (oid == geometry_oid) { mapnik::Feature feat(ctx,pkid); - if (geometry_utils::from_wkb(feat.paths(),buf,size,wkbGeneric) - && feat.num_geometries() > 0) + mapnik::new_geometry::geometry geom = geometry_utils::from_wkb(buf, size, wkbGeneric); + if (!mapnik::new_geometry::empty(geom)) { - geometry_type const& geom=feat.get_geometry(0); - box2d bbox = ::mapnik::envelope(geom); + box2d bbox = mapnik::new_geometry::envelope(geom); if (bbox.valid()) { sqlite::record_type rec; - rec.push_back(sqlite::value_type(pkid)); rec.push_back(sqlite::value_type(bbox.minx())); rec.push_back(sqlite::value_type(bbox.maxx())); rec.push_back(sqlite::value_type(bbox.miny())); rec.push_back(sqlite::value_type(bbox.maxy())); - spatial_index.insert_record(rec); empty_geom = false; }