- aligned code style in geos plugin
This commit is contained in:
parent
d7f68cc8f5
commit
cf3f6156c3
5 changed files with 91 additions and 100 deletions
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* 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
|
||||
* 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
// $Id$
|
||||
|
||||
#include "geos_datasource.hpp"
|
||||
#include "geos_featureset.hpp"
|
||||
|
||||
// stl
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <cstdarg>
|
||||
|
||||
#include "geos_datasource.hpp"
|
||||
#include "geos_featureset.hpp"
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/ptree_helpers.hpp>
|
||||
#include <mapnik/geom_util.hpp>
|
||||
|
@ -44,17 +44,9 @@
|
|||
// geos
|
||||
#include <geos_c.h>
|
||||
|
||||
using std::clog;
|
||||
using std::endl;
|
||||
|
||||
using boost::lexical_cast;
|
||||
using boost::bad_lexical_cast;
|
||||
|
||||
using mapnik::datasource;
|
||||
using mapnik::parameters;
|
||||
|
||||
DATASOURCE_PLUGIN(geos_datasource)
|
||||
|
||||
using mapnik::box2d;
|
||||
using mapnik::coord2d;
|
||||
using mapnik::query;
|
||||
|
@ -62,9 +54,12 @@ using mapnik::featureset_ptr;
|
|||
using mapnik::layer_descriptor;
|
||||
using mapnik::attribute_descriptor;
|
||||
using mapnik::datasource_exception;
|
||||
using mapnik::datasource;
|
||||
using mapnik::parameters;
|
||||
using mapnik::filter_in_box;
|
||||
using mapnik::filter_at_point;
|
||||
|
||||
DATASOURCE_PLUGIN(geos_datasource)
|
||||
|
||||
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)
|
||||
: datasource(params),
|
||||
extent_(),
|
||||
extent_initialized_(false),
|
||||
type_(datasource::Vector),
|
||||
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","utf-8")),
|
||||
geometry_data_(""),
|
||||
geometry_data_name_("name"),
|
||||
geometry_id_(1)
|
||||
: datasource(params),
|
||||
extent_(),
|
||||
extent_initialized_(false),
|
||||
type_(datasource::Vector),
|
||||
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding", "utf-8")),
|
||||
geometry_data_(""),
|
||||
geometry_data_name_("name"),
|
||||
geometry_id_(1)
|
||||
{
|
||||
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;
|
||||
|
||||
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
|
||||
|
@ -153,7 +148,7 @@ void geos_datasource::bind() const
|
|||
if (! extent_initialized_)
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << "GEOS Plugin: initializing extent from geometry" << endl;
|
||||
std::clog << "GEOS Plugin: initializing extent from geometry" << std::endl;
|
||||
#endif
|
||||
|
||||
if (GEOSGeomTypeId(*geometry_) == GEOS_POINT)
|
||||
|
@ -167,7 +162,7 @@ void geos_datasource::bind() const
|
|||
GEOSCoordSeq_getX(cs, 0, &x);
|
||||
GEOSCoordSeq_getY(cs, 0, &y);
|
||||
|
||||
extent_.init(x,y,x,y);
|
||||
extent_.init(x, y, x, y);
|
||||
extent_initialized_ = true;
|
||||
}
|
||||
else
|
||||
|
@ -177,7 +172,7 @@ void geos_datasource::bind() const
|
|||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
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);
|
||||
#endif
|
||||
|
||||
|
@ -188,7 +183,7 @@ void geos_datasource::bind() const
|
|||
if (cs != NULL)
|
||||
{
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << "GEOS Plugin: iterating boundary points" << endl;
|
||||
std::clog << "GEOS Plugin: iterating boundary points" << std::endl;
|
||||
#endif
|
||||
|
||||
double x, y;
|
||||
|
@ -196,8 +191,8 @@ void geos_datasource::bind() const
|
|||
miny = std::numeric_limits<float>::max(),
|
||||
maxx = -std::numeric_limits<float>::max(),
|
||||
maxy = -std::numeric_limits<float>::max();
|
||||
unsigned int num_points;
|
||||
|
||||
unsigned int num_points;
|
||||
GEOSCoordSeq_getSize(cs, &num_points);
|
||||
|
||||
for (unsigned int i = 0; i < num_points; ++i)
|
||||
|
@ -211,7 +206,7 @@ void geos_datasource::bind() const
|
|||
if (y > maxy) maxy = y;
|
||||
}
|
||||
|
||||
extent_.init(minx,miny,maxx,maxy);
|
||||
extent_.init(minx, miny, maxx, maxy);
|
||||
extent_initialized_ = true;
|
||||
}
|
||||
}
|
||||
|
@ -220,7 +215,9 @@ void geos_datasource::bind() const
|
|||
}
|
||||
|
||||
if (! extent_initialized_)
|
||||
{
|
||||
throw datasource_exception("GEOS Plugin: cannot determine extent for <wkt> geometry");
|
||||
}
|
||||
|
||||
is_bound_ = true;
|
||||
}
|
||||
|
@ -237,21 +234,21 @@ int geos_datasource::type() const
|
|||
|
||||
box2d<double> geos_datasource::envelope() const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
if (! is_bound_) bind();
|
||||
|
||||
return extent_;
|
||||
}
|
||||
|
||||
layer_descriptor geos_datasource::get_descriptor() const
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
if (! is_bound_) bind();
|
||||
|
||||
return desc_;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
@ -265,7 +262,7 @@ featureset_ptr geos_datasource::features(query const& q) const
|
|||
<< "))";
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << "GEOS Plugin: using extent: " << s.str() << endl;
|
||||
std::clog << "GEOS Plugin: using extent: " << s.str() << std::endl;
|
||||
#endif
|
||||
|
||||
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
|
||||
{
|
||||
if (!is_bound_) bind();
|
||||
if (! is_bound_) bind();
|
||||
|
||||
std::ostringstream s;
|
||||
s << "POINT(" << pt.x << " " << pt.y << ")";
|
||||
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << "GEOS Plugin: using point: " << s.str() << endl;
|
||||
std::clog << "GEOS Plugin: using point: " << s.str() << std::endl;
|
||||
#endif
|
||||
|
||||
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(),
|
||||
multiple_geometries_);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* 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
|
||||
* 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
//$Id$
|
||||
|
||||
#ifndef GEOS_DATASOURCE_HPP
|
||||
#define GEOS_DATASOURCE_HPP
|
||||
|
@ -36,28 +35,28 @@
|
|||
|
||||
class geos_datasource : public mapnik::datasource
|
||||
{
|
||||
public:
|
||||
geos_datasource(mapnik::parameters const& params, bool bind=true);
|
||||
virtual ~geos_datasource ();
|
||||
int type() const;
|
||||
static std::string name();
|
||||
mapnik::featureset_ptr features(mapnik::query const& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
void bind() const;
|
||||
private:
|
||||
mutable mapnik::box2d<double> extent_;
|
||||
mutable bool extent_initialized_;
|
||||
int type_;
|
||||
mutable mapnik::layer_descriptor desc_;
|
||||
mutable geos_feature_ptr geometry_;
|
||||
mutable std::string geometry_data_;
|
||||
mutable std::string geometry_data_name_;
|
||||
mutable int geometry_id_;
|
||||
std::string geometry_string_;
|
||||
bool multiple_geometries_;
|
||||
public:
|
||||
geos_datasource(mapnik::parameters const& params, bool bind = true);
|
||||
virtual ~geos_datasource ();
|
||||
int type() const;
|
||||
static std::string name();
|
||||
mapnik::featureset_ptr features(mapnik::query const& q) const;
|
||||
mapnik::featureset_ptr features_at_point(mapnik::coord2d const& pt) const;
|
||||
mapnik::box2d<double> envelope() const;
|
||||
mapnik::layer_descriptor get_descriptor() const;
|
||||
void bind() const;
|
||||
|
||||
private:
|
||||
mutable mapnik::box2d<double> extent_;
|
||||
mutable bool extent_initialized_;
|
||||
int type_;
|
||||
mutable mapnik::layer_descriptor desc_;
|
||||
mutable geos_feature_ptr geometry_;
|
||||
mutable std::string geometry_data_;
|
||||
mutable std::string geometry_data_name_;
|
||||
mutable int geometry_id_;
|
||||
std::string geometry_string_;
|
||||
bool multiple_geometries_;
|
||||
};
|
||||
|
||||
|
||||
#endif // GEOS_DATASOURCE_HPP
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* 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
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* 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
|
||||
* 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
//$Id$
|
||||
|
||||
// stl
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
@ -35,12 +35,8 @@
|
|||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/feature_factory.hpp>
|
||||
|
||||
// ogr
|
||||
#include "geos_featureset.hpp"
|
||||
|
||||
using std::clog;
|
||||
using std::endl;
|
||||
|
||||
using mapnik::query;
|
||||
using mapnik::box2d;
|
||||
using mapnik::coord2d;
|
||||
|
@ -59,14 +55,14 @@ geos_featureset::geos_featureset(GEOSGeometry* geometry,
|
|||
const std::string& field_name,
|
||||
const std::string& encoding,
|
||||
bool multiple_geometries)
|
||||
: geometry_(geometry),
|
||||
tr_(new transcoder(encoding)),
|
||||
extent_(extent),
|
||||
identifier_(identifier),
|
||||
field_(field),
|
||||
field_name_(field_name),
|
||||
multiple_geometries_(multiple_geometries),
|
||||
already_rendered_(false)
|
||||
: geometry_(geometry),
|
||||
tr_(new transcoder(encoding)),
|
||||
extent_(extent),
|
||||
identifier_(identifier),
|
||||
field_(field),
|
||||
field_name_(field_name),
|
||||
multiple_geometries_(multiple_geometries),
|
||||
already_rendered_(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -84,12 +80,12 @@ feature_ptr geos_featureset::next()
|
|||
{
|
||||
bool render_geometry = true;
|
||||
|
||||
if (*extent_ != NULL && GEOSisValid(*extent_) && !GEOSisEmpty(*extent_))
|
||||
if (*extent_ != NULL && GEOSisValid(*extent_) && ! GEOSisEmpty(*extent_))
|
||||
{
|
||||
const int type = GEOSGeomTypeId(*extent_);
|
||||
render_geometry = false;
|
||||
|
||||
switch ( type )
|
||||
switch (type)
|
||||
{
|
||||
case GEOS_POINT:
|
||||
if (GEOSIntersects(*extent_, geometry_))
|
||||
|
@ -97,6 +93,7 @@ feature_ptr geos_featureset::next()
|
|||
render_geometry = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case GEOS_POLYGON:
|
||||
if (GEOSContains(*extent_, geometry_)
|
||||
|| GEOSWithin(geometry_, *extent_)
|
||||
|
@ -105,9 +102,10 @@ feature_ptr geos_featureset::next()
|
|||
render_geometry = true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
default:
|
||||
#ifdef MAPNIK_DEBUG
|
||||
clog << "GEOS Plugin: unknown extent geometry_type=" << type << endl;
|
||||
std::clog << "GEOS Plugin: unknown extent geometry_type=" << type << std::endl;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
@ -138,4 +136,3 @@ feature_ptr geos_featureset::next()
|
|||
|
||||
return feature_ptr();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
* 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
|
||||
* 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
|
||||
*
|
||||
*****************************************************************************/
|
||||
//$Id$
|
||||
|
||||
#ifndef GEOS_FEATURESET_HPP
|
||||
#define GEOS_FEATURESET_HPP
|
||||
|
@ -40,28 +39,28 @@
|
|||
class geos_featureset : public mapnik::Featureset
|
||||
{
|
||||
public:
|
||||
geos_featureset(GEOSGeometry* geometry,
|
||||
GEOSGeometry* extent,
|
||||
int identifier,
|
||||
const std::string& field,
|
||||
const std::string& field_name,
|
||||
const std::string& encoding,
|
||||
bool multiple_geometries);
|
||||
virtual ~geos_featureset();
|
||||
mapnik::feature_ptr next();
|
||||
geos_featureset(GEOSGeometry* geometry,
|
||||
GEOSGeometry* extent,
|
||||
int identifier,
|
||||
const std::string& field,
|
||||
const std::string& field_name,
|
||||
const std::string& encoding,
|
||||
bool multiple_geometries);
|
||||
virtual ~geos_featureset();
|
||||
mapnik::feature_ptr next();
|
||||
|
||||
private:
|
||||
GEOSGeometry* geometry_;
|
||||
boost::scoped_ptr<mapnik::transcoder> tr_;
|
||||
geos_feature_ptr extent_;
|
||||
int identifier_;
|
||||
std::string field_;
|
||||
std::string field_name_;
|
||||
bool multiple_geometries_;
|
||||
bool already_rendered_;
|
||||
GEOSGeometry* geometry_;
|
||||
boost::scoped_ptr<mapnik::transcoder> tr_;
|
||||
geos_feature_ptr extent_;
|
||||
int identifier_;
|
||||
std::string field_;
|
||||
std::string field_name_;
|
||||
bool multiple_geometries_;
|
||||
bool already_rendered_;
|
||||
|
||||
geos_featureset(const geos_featureset&);
|
||||
const geos_featureset& operator=(const geos_featureset&);
|
||||
geos_featureset(const geos_featureset&);
|
||||
const geos_featureset& operator=(const geos_featureset&);
|
||||
};
|
||||
|
||||
#endif // GEOS_FEATURESET_HPP
|
||||
|
|
Loading…
Reference in a new issue