- aligned code style in geos plugin

This commit is contained in:
kunitoki 2011-10-23 21:19:56 +02:00
parent 2cf56bf767
commit 9967132b78
5 changed files with 91 additions and 100 deletions

View file

@ -2,7 +2,7 @@
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2010 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -19,16 +19,16 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
// $Id$
#include "geos_datasource.hpp"
#include "geos_featureset.hpp"
// stl
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <stdexcept> #include <stdexcept>
#include <cstdarg> #include <cstdarg>
#include "geos_datasource.hpp"
#include "geos_featureset.hpp"
// mapnik // mapnik
#include <mapnik/ptree_helpers.hpp> #include <mapnik/ptree_helpers.hpp>
#include <mapnik/geom_util.hpp> #include <mapnik/geom_util.hpp>
@ -44,17 +44,9 @@
// geos // geos
#include <geos_c.h> #include <geos_c.h>
using std::clog;
using std::endl;
using boost::lexical_cast; using boost::lexical_cast;
using boost::bad_lexical_cast; using boost::bad_lexical_cast;
using mapnik::datasource;
using mapnik::parameters;
DATASOURCE_PLUGIN(geos_datasource)
using mapnik::box2d; using mapnik::box2d;
using mapnik::coord2d; using mapnik::coord2d;
using mapnik::query; using mapnik::query;
@ -62,9 +54,12 @@ using mapnik::featureset_ptr;
using mapnik::layer_descriptor; using mapnik::layer_descriptor;
using mapnik::attribute_descriptor; using mapnik::attribute_descriptor;
using mapnik::datasource_exception; using mapnik::datasource_exception;
using mapnik::datasource;
using mapnik::parameters;
using mapnik::filter_in_box; using mapnik::filter_in_box;
using mapnik::filter_at_point; using mapnik::filter_at_point;
DATASOURCE_PLUGIN(geos_datasource)
void geos_notice(const char* fmt, ...) void geos_notice(const char* fmt, ...)
{ {
@ -90,17 +85,17 @@ void geos_error(const char* fmt, ...)
geos_datasource::geos_datasource(parameters const& params, bool bind) geos_datasource::geos_datasource(parameters const& params, bool bind)
: datasource(params), : datasource(params),
extent_(), extent_(),
extent_initialized_(false), extent_initialized_(false),
type_(datasource::Vector), type_(datasource::Vector),
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","utf-8")), desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding", "utf-8")),
geometry_data_(""), geometry_data_(""),
geometry_data_name_("name"), geometry_data_name_("name"),
geometry_id_(1) geometry_id_(1)
{ {
boost::optional<std::string> geometry = params.get<std::string>("wkt"); boost::optional<std::string> geometry = params.get<std::string>("wkt");
if (!geometry) throw datasource_exception("missing <wkt> parameter"); if (! geometry) throw datasource_exception("missing <wkt> parameter");
geometry_string_ = *geometry; geometry_string_ = *geometry;
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false); multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
@ -153,7 +148,7 @@ void geos_datasource::bind() const
if (! extent_initialized_) if (! extent_initialized_)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << "GEOS Plugin: initializing extent from geometry" << endl; std::clog << "GEOS Plugin: initializing extent from geometry" << std::endl;
#endif #endif
if (GEOSGeomTypeId(*geometry_) == GEOS_POINT) if (GEOSGeomTypeId(*geometry_) == GEOS_POINT)
@ -167,7 +162,7 @@ void geos_datasource::bind() const
GEOSCoordSeq_getX(cs, 0, &x); GEOSCoordSeq_getX(cs, 0, &x);
GEOSCoordSeq_getY(cs, 0, &y); GEOSCoordSeq_getY(cs, 0, &y);
extent_.init(x,y,x,y); extent_.init(x, y, x, y);
extent_initialized_ = true; extent_initialized_ = true;
} }
else else
@ -177,7 +172,7 @@ void geos_datasource::bind() const
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
char* wkt = GEOSGeomToWKT(*envelope); char* wkt = GEOSGeomToWKT(*envelope);
clog << "GEOS Plugin: getting coord sequence from: " << wkt << endl; std::clog << "GEOS Plugin: getting coord sequence from: " << wkt << std::endl;
GEOSFree(wkt); GEOSFree(wkt);
#endif #endif
@ -188,7 +183,7 @@ void geos_datasource::bind() const
if (cs != NULL) if (cs != NULL)
{ {
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << "GEOS Plugin: iterating boundary points" << endl; std::clog << "GEOS Plugin: iterating boundary points" << std::endl;
#endif #endif
double x, y; double x, y;
@ -196,8 +191,8 @@ void geos_datasource::bind() const
miny = std::numeric_limits<float>::max(), miny = std::numeric_limits<float>::max(),
maxx = -std::numeric_limits<float>::max(), maxx = -std::numeric_limits<float>::max(),
maxy = -std::numeric_limits<float>::max(); maxy = -std::numeric_limits<float>::max();
unsigned int num_points;
unsigned int num_points;
GEOSCoordSeq_getSize(cs, &num_points); GEOSCoordSeq_getSize(cs, &num_points);
for (unsigned int i = 0; i < num_points; ++i) for (unsigned int i = 0; i < num_points; ++i)
@ -211,7 +206,7 @@ void geos_datasource::bind() const
if (y > maxy) maxy = y; if (y > maxy) maxy = y;
} }
extent_.init(minx,miny,maxx,maxy); extent_.init(minx, miny, maxx, maxy);
extent_initialized_ = true; extent_initialized_ = true;
} }
} }
@ -220,7 +215,9 @@ void geos_datasource::bind() const
} }
if (! extent_initialized_) if (! extent_initialized_)
{
throw datasource_exception("GEOS Plugin: cannot determine extent for <wkt> geometry"); throw datasource_exception("GEOS Plugin: cannot determine extent for <wkt> geometry");
}
is_bound_ = true; is_bound_ = true;
} }
@ -237,21 +234,21 @@ int geos_datasource::type() const
box2d<double> geos_datasource::envelope() const box2d<double> geos_datasource::envelope() const
{ {
if (!is_bound_) bind(); if (! is_bound_) bind();
return extent_; return extent_;
} }
layer_descriptor geos_datasource::get_descriptor() const layer_descriptor geos_datasource::get_descriptor() const
{ {
if (!is_bound_) bind(); if (! is_bound_) bind();
return desc_; return desc_;
} }
featureset_ptr geos_datasource::features(query const& q) const featureset_ptr geos_datasource::features(query const& q) const
{ {
if (!is_bound_) bind(); if (! is_bound_) bind();
const mapnik::box2d<double> extent = q.get_bbox(); const mapnik::box2d<double> extent = q.get_bbox();
@ -265,7 +262,7 @@ featureset_ptr geos_datasource::features(query const& q) const
<< "))"; << "))";
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << "GEOS Plugin: using extent: " << s.str() << endl; std::clog << "GEOS Plugin: using extent: " << s.str() << std::endl;
#endif #endif
return boost::make_shared<geos_featureset>(*geometry_, return boost::make_shared<geos_featureset>(*geometry_,
@ -279,13 +276,13 @@ featureset_ptr geos_datasource::features(query const& q) const
featureset_ptr geos_datasource::features_at_point(coord2d const& pt) const featureset_ptr geos_datasource::features_at_point(coord2d const& pt) const
{ {
if (!is_bound_) bind(); if (! is_bound_) bind();
std::ostringstream s; std::ostringstream s;
s << "POINT(" << pt.x << " " << pt.y << ")"; s << "POINT(" << pt.x << " " << pt.y << ")";
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << "GEOS Plugin: using point: " << s.str() << endl; std::clog << "GEOS Plugin: using point: " << s.str() << std::endl;
#endif #endif
return boost::make_shared<geos_featureset>(*geometry_, return boost::make_shared<geos_featureset>(*geometry_,
@ -296,4 +293,3 @@ featureset_ptr geos_datasource::features_at_point(coord2d const& pt) const
desc_.get_encoding(), desc_.get_encoding(),
multiple_geometries_); multiple_geometries_);
} }

View file

@ -2,7 +2,7 @@
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2010 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
#ifndef GEOS_DATASOURCE_HPP #ifndef GEOS_DATASOURCE_HPP
#define GEOS_DATASOURCE_HPP #define GEOS_DATASOURCE_HPP
@ -36,28 +35,28 @@
class geos_datasource : public mapnik::datasource class geos_datasource : public mapnik::datasource
{ {
public: public:
geos_datasource(mapnik::parameters const& params, bool bind=true); geos_datasource(mapnik::parameters const& params, bool bind = true);
virtual ~geos_datasource (); virtual ~geos_datasource ();
int type() const; int type() const;
static std::string name(); static std::string name();
mapnik::featureset_ptr features(mapnik::query const& q) const; mapnik::featureset_ptr features(mapnik::query const& q) const;
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const; mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
mapnik::box2d<double> envelope() const; mapnik::box2d<double> envelope() const;
mapnik::layer_descriptor get_descriptor() const; mapnik::layer_descriptor get_descriptor() const;
void bind() const; void bind() const;
private:
mutable mapnik::box2d<double> extent_; private:
mutable bool extent_initialized_; mutable mapnik::box2d<double> extent_;
int type_; mutable bool extent_initialized_;
mutable mapnik::layer_descriptor desc_; int type_;
mutable geos_feature_ptr geometry_; mutable mapnik::layer_descriptor desc_;
mutable std::string geometry_data_; mutable geos_feature_ptr geometry_;
mutable std::string geometry_data_name_; mutable std::string geometry_data_;
mutable int geometry_id_; mutable std::string geometry_data_name_;
std::string geometry_string_; mutable int geometry_id_;
bool multiple_geometries_; std::string geometry_string_;
bool multiple_geometries_;
}; };
#endif // GEOS_DATASOURCE_HPP #endif // GEOS_DATASOURCE_HPP

View file

@ -2,7 +2,7 @@
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2010 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public

View file

@ -2,7 +2,7 @@
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2010 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -19,8 +19,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
// stl
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
@ -35,12 +35,8 @@
#include <mapnik/unicode.hpp> #include <mapnik/unicode.hpp>
#include <mapnik/feature_factory.hpp> #include <mapnik/feature_factory.hpp>
// ogr
#include "geos_featureset.hpp" #include "geos_featureset.hpp"
using std::clog;
using std::endl;
using mapnik::query; using mapnik::query;
using mapnik::box2d; using mapnik::box2d;
using mapnik::coord2d; using mapnik::coord2d;
@ -59,14 +55,14 @@ geos_featureset::geos_featureset(GEOSGeometry* geometry,
const std::string& field_name, const std::string& field_name,
const std::string& encoding, const std::string& encoding,
bool multiple_geometries) bool multiple_geometries)
: geometry_(geometry), : geometry_(geometry),
tr_(new transcoder(encoding)), tr_(new transcoder(encoding)),
extent_(extent), extent_(extent),
identifier_(identifier), identifier_(identifier),
field_(field), field_(field),
field_name_(field_name), field_name_(field_name),
multiple_geometries_(multiple_geometries), multiple_geometries_(multiple_geometries),
already_rendered_(false) already_rendered_(false)
{ {
} }
@ -84,12 +80,12 @@ feature_ptr geos_featureset::next()
{ {
bool render_geometry = true; bool render_geometry = true;
if (*extent_ != NULL && GEOSisValid(*extent_) && !GEOSisEmpty(*extent_)) if (*extent_ != NULL && GEOSisValid(*extent_) && ! GEOSisEmpty(*extent_))
{ {
const int type = GEOSGeomTypeId(*extent_); const int type = GEOSGeomTypeId(*extent_);
render_geometry = false; render_geometry = false;
switch ( type ) switch (type)
{ {
case GEOS_POINT: case GEOS_POINT:
if (GEOSIntersects(*extent_, geometry_)) if (GEOSIntersects(*extent_, geometry_))
@ -97,6 +93,7 @@ feature_ptr geos_featureset::next()
render_geometry = true; render_geometry = true;
} }
break; break;
case GEOS_POLYGON: case GEOS_POLYGON:
if (GEOSContains(*extent_, geometry_) if (GEOSContains(*extent_, geometry_)
|| GEOSWithin(geometry_, *extent_) || GEOSWithin(geometry_, *extent_)
@ -105,9 +102,10 @@ feature_ptr geos_featureset::next()
render_geometry = true; render_geometry = true;
} }
break; break;
default:
default:
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << "GEOS Plugin: unknown extent geometry_type=" << type << endl; std::clog << "GEOS Plugin: unknown extent geometry_type=" << type << std::endl;
#endif #endif
break; break;
} }
@ -138,4 +136,3 @@ feature_ptr geos_featureset::next()
return feature_ptr(); return feature_ptr();
} }

View file

@ -2,7 +2,7 @@
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2010 Artem Pavlenko * Copyright (C) 2011 Artem Pavlenko
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -19,7 +19,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
//$Id$
#ifndef GEOS_FEATURESET_HPP #ifndef GEOS_FEATURESET_HPP
#define GEOS_FEATURESET_HPP #define GEOS_FEATURESET_HPP
@ -40,28 +39,28 @@
class geos_featureset : public mapnik::Featureset class geos_featureset : public mapnik::Featureset
{ {
public: public:
geos_featureset(GEOSGeometry* geometry, geos_featureset(GEOSGeometry* geometry,
GEOSGeometry* extent, GEOSGeometry* extent,
int identifier, int identifier,
const std::string& field, const std::string& field,
const std::string& field_name, const std::string& field_name,
const std::string& encoding, const std::string& encoding,
bool multiple_geometries); bool multiple_geometries);
virtual ~geos_featureset(); virtual ~geos_featureset();
mapnik::feature_ptr next(); mapnik::feature_ptr next();
private: private:
GEOSGeometry* geometry_; GEOSGeometry* geometry_;
boost::scoped_ptr<mapnik::transcoder> tr_; boost::scoped_ptr<mapnik::transcoder> tr_;
geos_feature_ptr extent_; geos_feature_ptr extent_;
int identifier_; int identifier_;
std::string field_; std::string field_;
std::string field_name_; std::string field_name_;
bool multiple_geometries_; bool multiple_geometries_;
bool already_rendered_; bool already_rendered_;
geos_featureset(const geos_featureset&); geos_featureset(const geos_featureset&);
const geos_featureset& operator=(const geos_featureset&); const geos_featureset& operator=(const geos_featureset&);
}; };
#endif // GEOS_FEATURESET_HPP #endif // GEOS_FEATURESET_HPP