Initial check in of a GEOS input plugin: This allows constructing

geometries directly inside a XML file by specifying a WKT text.
Useful a lot for building legend images for layers or drawing fixed
geometries in the map. An update of the main SConstruct and python
bindings for this will follow. Be careful with this, as it's mainly
alpha code.
This commit is contained in:
Lucio Asnaghi 2010-11-10 10:46:09 +00:00
parent 90e51e79e8
commit f1b8ad4ee7
9 changed files with 919 additions and 0 deletions

View file

@ -0,0 +1,34 @@
pkglibdir = $(libdir)/mapnik/input
if HAVE_GEOS
pkglib_LTLIBRARIES = \
geos.la
geos_la_SOURCES = \
geos_datasource.cpp \
geos_datasource.hpp \
geos_featureset.cpp \
geos_featureset.hpp \
geos_converter.cpp \
geos_converter.hpp \
geos_feature_ptr.hpp
geos_la_LIBADD = \
${GEOS_LDFLAGS}
geos_la_CXXFLAGS = \
-Wall \
${PROFILING_CFLAGS} \
${TRACING_CFLAGS} \
${GEOS_CFLAGS} \
-I../../../include
geos_la_LDFLAGS = \
-module \
-avoid-version \
-shrext .input
endif
## File created by the gnome-build tools

View file

@ -0,0 +1,48 @@
#
# This file is part of Mapnik (c++ mapping toolkit)
#
# Copyright (C) 2007 Artem Pavlenko, Jean-Francois Doyon
#
# Mapnik 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
#
# $Id$
Import ('env')
prefix = env['PREFIX']
install_prefix = env['DESTDIR'] + '/' + prefix
geos_src = Split(
"""
geos_converter.cpp
geos_datasource.cpp
geos_featureset.cpp
"""
)
libraries = [env['PLUGINS']['geos']['lib']]
libraries = ['boost_iostreams%s' % env['BOOST_APPEND']]
if env['PLATFORM'] == 'Darwin':
libraries.append('mapnik2')
libraries.append(env['ICU_LIB_NAME'])
libraries.append('boost_system%s' % env['BOOST_APPEND'])
libraries.append('boost_filesystem%s' % env['BOOST_APPEND'])
geos_inputdriver = env.SharedLibrary('geos', source=geos_src, SHLIBPREFIX='', SHLIBSUFFIX='.input', LIBS=libraries)
env.Install(install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input', geos_inputdriver)
env.Alias('install', install_prefix + '/' + env['LIBDIR_SCHEMA'] + env['LIB_DIR_NAME'] + '/input')

View file

@ -0,0 +1,349 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2007 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
*
*****************************************************************************/
//$Id$
#include <mapnik/global.hpp>
#include <mapnik/box2d.hpp>
#include <mapnik/geometry.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/feature_layer_desc.hpp>
#include <mapnik/wkb.hpp>
#include <mapnik/unicode.hpp>
// geos
#include "geos_converter.hpp"
using std::clog;
using std::endl;
using mapnik::feature_ptr;
using mapnik::geometry_utils;
using mapnik::geometry_type;
void geos_converter::convert_geometry (const GEOSGeometry* geom, feature_ptr feature, bool multiple_geometries)
{
int type = GEOSGeomTypeId(geom);
switch ( type )
{
case GEOS_POINT:
convert_point (geom, feature);
break;
case GEOS_LINESTRING:
case GEOS_LINEARRING:
convert_linestring (geom, feature);
break;
case GEOS_POLYGON:
convert_polygon (geom, feature);
break;
case GEOS_MULTIPOINT:
if (multiple_geometries)
convert_multipoint_2 (geom, feature);
else
// Todo - using convert_multipoint_2 until we have proper multipoint handling in convert_multipoint
// http://trac.mapnik.org/ticket/458
//convert_multipoint (geom, feature);
convert_multipoint_2 (geom, feature);
break;
case GEOS_MULTILINESTRING:
if (multiple_geometries)
convert_multilinestring_2 (geom, feature);
else
convert_multilinestring (geom, feature);
break;
case GEOS_MULTIPOLYGON:
if (multiple_geometries)
convert_multipolygon_2 (geom, feature);
else
convert_multipolygon (geom, feature);
break;
case GEOS_GEOMETRYCOLLECTION:
convert_collection (geom, feature, multiple_geometries);
break;
default:
#ifdef MAPNIK_DEBUG
clog << "unknown <geos> geometry_type=" << type << endl;
#endif
break;
}
}
void geos_converter::convert_point (const GEOSGeometry* geom, feature_ptr feature)
{
double x, y;
unsigned int size;
const GEOSCoordSequence* cs = GEOSGeom_getCoordSeq(geom);
GEOSCoordSeq_getSize(cs, &size);
GEOSCoordSeq_getX(cs, 0, &x);
GEOSCoordSeq_getY(cs, 0, &y);
geometry_type* point = new geometry_type(mapnik::Point);
point->move_to (x, y);
feature->add_geometry (point);
}
void geos_converter::convert_linestring (const GEOSGeometry* geom, feature_ptr feature)
{
double x, y;
unsigned int num_points;
const GEOSCoordSequence* cs = GEOSGeom_getCoordSeq(geom);
GEOSCoordSeq_getSize(cs, &num_points);
GEOSCoordSeq_getX(cs, 0, &x);
GEOSCoordSeq_getY(cs, 0, &y);
geometry_type* line = new geometry_type(mapnik::LineString);
line->set_capacity (num_points);
line->move_to (x, y);
for (unsigned int i = 1; i < num_points; ++i)
{
GEOSCoordSeq_getX(cs, i, &x);
GEOSCoordSeq_getY(cs, i, &y);
line->line_to (x, y);
}
feature->add_geometry (line);
}
void geos_converter::convert_polygon (const GEOSGeometry* geom, feature_ptr feature)
{
double x, y;
unsigned int num_points, num_interior;
const GEOSGeometry* exterior = GEOSGetExteriorRing(geom);
const GEOSCoordSequence* es = GEOSGeom_getCoordSeq(exterior);
GEOSCoordSeq_getSize(es, &num_points);
GEOSCoordSeq_getX(es, 0, &x);
GEOSCoordSeq_getY(es, 0, &y);
num_interior = GEOSGetNumInteriorRings(geom);
unsigned int capacity = 0;
for (unsigned int r = 0; r < num_interior; r++)
{
const GEOSGeometry* gtmp = GEOSGetInteriorRingN(geom, r);
const GEOSCoordSequence* is = GEOSGeom_getCoordSeq(gtmp);
unsigned int interior_size;
GEOSCoordSeq_getSize(is, &interior_size);
capacity += interior_size;
}
geometry_type* poly = new geometry_type(mapnik::Polygon);
poly->set_capacity (num_points + capacity);
poly->move_to (x, y);
for (unsigned int i = 1; i < num_points; ++i)
{
GEOSCoordSeq_getX(es, i, &x);
GEOSCoordSeq_getY(es, i, &y);
poly->line_to (x, y);
}
for (unsigned int r = 0; r < num_interior; ++r)
{
const GEOSGeometry* gtmp = GEOSGetInteriorRingN(geom, r);
const GEOSCoordSequence* is = GEOSGeom_getCoordSeq(gtmp);
GEOSCoordSeq_getSize(is, &num_points);
GEOSCoordSeq_getX(is, 0, &x);
GEOSCoordSeq_getY(is, 0, &y);
poly->move_to(x, y);
for (unsigned int i = 1; i < num_points; ++i)
{
GEOSCoordSeq_getX(is, i, &x);
GEOSCoordSeq_getY(is, i, &y);
poly->line_to(x, y);
}
}
feature->add_geometry (poly);
}
void geos_converter::convert_multipoint (const GEOSGeometry* geom, feature_ptr feature)
{
unsigned int num_geometries = GEOSGetNumGeometries(geom);
geometry_type* point = new geometry_type(mapnik::Point);
for (unsigned int i = 0; i < num_geometries; i++)
{
const GEOSGeometry* g = GEOSGetGeometryN(geom, i);
if (g != NULL && GEOSisValid(g))
{
const GEOSCoordSequence* cs = GEOSGeom_getCoordSeq(geom);
double x, y;
//GEOSCoordSeq_getSize(cs, &size);
GEOSCoordSeq_getX(cs, 0, &x);
GEOSCoordSeq_getY(cs, 0, &y);
point->move_to (x, y);
}
}
feature->add_geometry (point);
}
void geos_converter::convert_multipoint_2 (const GEOSGeometry* geom, feature_ptr feature)
{
unsigned int num_geometries = GEOSGetNumGeometries(geom);
for (unsigned int i = 0; i < num_geometries; ++i)
{
const GEOSGeometry* g = GEOSGetGeometryN(geom, i);
if (g != NULL && GEOSisValid(g))
{
convert_point (g, feature);
}
}
}
void geos_converter::convert_multilinestring (const GEOSGeometry* geom, feature_ptr feature)
{
/*
int num_geometries = geom->getNumGeometries ();
int num_points = 0;
for (int i=0;i<num_geometries;i++)
{
OGRLineString* ls = static_cast<OGRLineString*>(geom->getGeometryRef (i));
num_points += ls->getNumPoints ();
}
geometry_type* line = new geometry_type(mapnik::LineString);
line->set_capacity (num_points);
for (int i=0;i<num_geometries;i++)
{
OGRLineString* ls = static_cast<OGRLineString*>(geom->getGeometryRef (i));
num_points = ls->getNumPoints ();
line->move_to (ls->getX (0), ls->getY (0));
for (int i=1;i<num_points;++i)
{
line->line_to (ls->getX (i), ls->getY (i));
}
}
feature->add_geometry (line);
*/
}
void geos_converter::convert_multilinestring_2 (const GEOSGeometry* geom, feature_ptr feature)
{
unsigned int num_geometries = GEOSGetNumGeometries(geom);
for (unsigned int i = 0; i < num_geometries; ++i)
{
const GEOSGeometry* g = GEOSGetGeometryN(geom, i);
if (g != NULL && GEOSisValid(g))
{
convert_linestring (g, feature);
}
}
}
void geos_converter::convert_multipolygon (const GEOSGeometry* geom, feature_ptr feature)
{
/*
int num_geometries = geom->getNumGeometries ();
int capacity = 0;
for (int i=0;i<num_geometries;i++)
{
OGRPolygon* p = static_cast<OGRPolygon*>(geom->getGeometryRef (i));
OGRLinearRing* exterior = p->getExteriorRing ();
capacity += exterior->getNumPoints ();
for (int r=0;r<p->getNumInteriorRings ();r++)
{
OGRLinearRing* interior = p->getInteriorRing (r);
capacity += interior->getNumPoints ();
}
}
geometry_type* poly = new geometry_type(mapnik::Polygon);
poly->set_capacity (capacity);
for (int i=0;i<num_geometries;i++)
{
OGRPolygon* p = static_cast<OGRPolygon*>(geom->getGeometryRef (i));
OGRLinearRing* exterior = p->getExteriorRing ();
int num_points = exterior->getNumPoints ();
int num_interior = p->getNumInteriorRings ();
poly->move_to (exterior->getX (0), exterior->getY (0));
for (int i=1;i<num_points;++i)
{
poly->line_to (exterior->getX (i), exterior->getY (i));
}
for (int r=0;r<num_interior;r++)
{
OGRLinearRing* interior = p->getInteriorRing (r);
num_points = interior->getNumPoints ();
poly->move_to(interior->getX (0), interior->getY (0));
for (int i=1;i<num_points;++i)
{
poly->line_to(interior->getX (i), interior->getY (i));
}
}
}
feature->add_geometry (poly);
*/
}
void geos_converter::convert_multipolygon_2 (const GEOSGeometry* geom, feature_ptr feature)
{
unsigned int num_geometries = GEOSGetNumGeometries(geom);
for (unsigned int i = 0; i < num_geometries; ++i)
{
const GEOSGeometry* g = GEOSGetGeometryN(geom, i);
if (g != NULL && GEOSisValid(g))
{
convert_polygon (g, feature);
}
}
}
void geos_converter::convert_collection (const GEOSGeometry* geom, feature_ptr feature, bool multiple_geometries)
{
unsigned int num_geometries = GEOSGetNumGeometries(geom);
for (unsigned int i = 0; i < num_geometries; ++i)
{
const GEOSGeometry* g = GEOSGetGeometryN(geom, i);
if (g != NULL && GEOSisValid(g))
{
convert_geometry (g, feature, multiple_geometries);
}
}
}

View file

@ -0,0 +1,50 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2007 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
*
*****************************************************************************/
//$Id$
#ifndef GEOS_CONVERTER_HPP
#define GEOS_CONVERTER_HPP
// mapnik
#include <mapnik/datasource.hpp>
// geos
#include <geos_c.h>
class geos_converter
{
public:
static void convert_geometry (const GEOSGeometry* geom, mapnik::feature_ptr feature, bool multiple_geometries);
static void convert_collection (const GEOSGeometry* geom, mapnik::feature_ptr feature, bool multiple_geometries);
static void convert_point (const GEOSGeometry* geom, mapnik::feature_ptr feature);
static void convert_linestring (const GEOSGeometry* geom, mapnik::feature_ptr feature);
static void convert_polygon (const GEOSGeometry* geom, mapnik::feature_ptr feature);
static void convert_multipoint (const GEOSGeometry* geom, mapnik::feature_ptr feature);
static void convert_multipoint_2 (const GEOSGeometry* geom, mapnik::feature_ptr feature);
static void convert_multilinestring (const GEOSGeometry* geom, mapnik::feature_ptr feature);
static void convert_multilinestring_2 (const GEOSGeometry* geom, mapnik::feature_ptr feature);
static void convert_multipolygon (const GEOSGeometry* geom, mapnik::feature_ptr feature);
static void convert_multipolygon_2 (const GEOSGeometry* geom, mapnik::feature_ptr feature);
};
#endif // GEOS_FEATURESET_HPP

View file

@ -0,0 +1,180 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2007 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
*
*****************************************************************************/
// $Id$
#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>
// boost
#include <boost/algorithm/string.hpp>
// geos
#include <geos_c.h>
using std::clog;
using std::endl;
using mapnik::datasource;
using mapnik::parameters;
DATASOURCE_PLUGIN(geos_datasource)
using mapnik::box2d;
using mapnik::coord2d;
using mapnik::query;
using mapnik::featureset_ptr;
using mapnik::layer_descriptor;
using mapnik::attribute_descriptor;
using mapnik::datasource_exception;
using mapnik::filter_in_box;
using mapnik::filter_at_point;
void notice(const char* fmt, ...)
{
va_list ap;
fprintf( stdout, "NOTICE: ");
va_start (ap, fmt);
vfprintf( stdout, fmt, ap);
va_end(ap);
fprintf( stdout, "\n" );
}
void log_and_exit(const char* fmt, ...)
{
va_list ap;
fprintf( stdout, "ERROR: ");
va_start (ap, fmt);
vfprintf( stdout, fmt, ap);
va_end(ap);
fprintf( stdout, "\n" );
//exit(1);
}
geos_datasource::geos_datasource(parameters const& params, bool bind)
: datasource(params),
extent_(),
type_(datasource::Vector),
desc_(*params.get<std::string>("type"), *params.get<std::string>("encoding","utf-8"))
{
boost::optional<std::string> geometry = params.get<std::string>("geometry");
if (!geometry) throw datasource_exception("missing <geometry> parameter");
geometry_ = *geometry;
multiple_geometries_ = *params_.get<mapnik::boolean>("multiple_geometries",false);
// initialize envelope
//extent_.init (envelope.MinX, envelope.MinY, envelope.MaxX, envelope.MaxY);
if (bind)
{
this->bind();
}
}
geos_datasource::~geos_datasource()
{
if (is_bound_)
{
finishGEOS();
}
}
void geos_datasource::bind() const
{
if (is_bound_) return;
// open ogr driver
initGEOS(notice, log_and_exit);
is_bound_ = true;
}
std::string geos_datasource::name()
{
return "geos";
}
int geos_datasource::type() const
{
return type_;
}
box2d<double> geos_datasource::envelope() const
{
if (!is_bound_) bind();
return extent_;
}
layer_descriptor geos_datasource::get_descriptor() const
{
if (!is_bound_) bind();
return desc_;
}
featureset_ptr geos_datasource::features(query const& q) const
{
if (!is_bound_) bind();
const mapnik::box2d<double> extent = q.get_bbox();
std::ostringstream s;
s << "POLYGON("
<< extent.minx() << " " << extent.miny() << ","
<< extent.minx() << " " << extent.maxy() << ","
<< extent.maxx() << " " << extent.maxy() << ","
<< extent.maxx() << " " << extent.miny() << ","
<< extent.minx() << " " << extent.miny()
<< ")";
return featureset_ptr(new geos_featureset (geometry_,
s.str(),
desc_.get_encoding(),
multiple_geometries_));
}
featureset_ptr geos_datasource::features_at_point(coord2d const& pt) const
{
if (!is_bound_) bind();
std::ostringstream s;
s << "POINT(" << pt.x << " " << pt.y << ")";
return featureset_ptr(new geos_featureset (geometry_,
s.str(),
desc_.get_encoding(),
multiple_geometries_));
}

View file

@ -0,0 +1,56 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2007 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
*
*****************************************************************************/
//$Id$
#ifndef GEOS_DATASOURCE_HPP
#define GEOS_DATASOURCE_HPP
// mapnik
#include <mapnik/datasource.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/feature_layer_desc.hpp>
// boost
#include <boost/shared_ptr.hpp>
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_;
int type_;
mutable mapnik::layer_descriptor desc_;
mutable std::string geometry_;
bool multiple_geometries_;
};
#endif // GEOS_DATASOURCE_HPP

View file

@ -0,0 +1,54 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2007 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
*
*****************************************************************************/
//$Id$
#ifndef GEOS_FEATURE_PTR_HPP
#define GEOS_FEATURE_PTR_HPP
// geos
#include <geos_c.h>
class geos_feature_ptr
{
public:
explicit geos_feature_ptr (GEOSGeometry* const feat)
: feat_ (feat)
{
}
~geos_feature_ptr ()
{
if (feat_ != NULL)
GEOSGeom_destroy(feat_);
}
GEOSGeometry* operator*()
{
return feat_;
}
private:
GEOSGeometry* feat_;
};
#endif // GEOS_FEATURE_PTR_HPP

View file

@ -0,0 +1,87 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2007 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
*
*****************************************************************************/
//$Id$
#include <iostream>
#include <fstream>
// mapnik
#include <mapnik/global.hpp>
#include <mapnik/datasource.hpp>
#include <mapnik/box2d.hpp>
#include <mapnik/geometry.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/feature_layer_desc.hpp>
#include <mapnik/wkb.hpp>
#include <mapnik/unicode.hpp>
// ogr
#include "geos_featureset.hpp"
#include "geos_converter.hpp"
using std::clog;
using std::endl;
using mapnik::query;
using mapnik::box2d;
using mapnik::coord2d;
using mapnik::CoordTransform;
using mapnik::Feature;
using mapnik::feature_ptr;
using mapnik::geometry_utils;
using mapnik::transcoder;
geos_featureset::geos_featureset(const std::string& geometry,
const std::string& extent,
const std::string& encoding,
const bool multiple_geometries)
: geometry_(geometry),
tr_(new transcoder(encoding)),
multiple_geometries_(multiple_geometries),
extent_(GEOSGeomFromWKT(extent.c_str()))
{
}
geos_featureset::~geos_featureset() {}
feature_ptr geos_featureset::next()
{
geos_feature_ptr feat (GEOSGeomFromWKT(geometry_.c_str()));
if ((*feat) != NULL)
{
GEOSGeometry* geom = (*feat);
GEOSGeometry* extent = (*extent_);
if (GEOSisValid(geom) && GEOSisValid(extent) && GEOSWithin(geom, extent))
{
feature_ptr feature(new Feature(0));
geos_converter::convert_geometry (geom, feature, multiple_geometries_);
return feature;
}
}
return feature_ptr();
}

View file

@ -0,0 +1,61 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2007 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
*
*****************************************************************************/
//$Id$
#ifndef GEOS_FEATURESET_HPP
#define GEOS_FEATURESET_HPP
// mapnik
#include <mapnik/datasource.hpp>
#include <mapnik/unicode.hpp>
#include <mapnik/geom_util.hpp>
// boost
#include <boost/scoped_ptr.hpp>
// geos
#include <geos_c.h>
#include "geos_feature_ptr.hpp"
class geos_featureset : public mapnik::Featureset
{
public:
geos_featureset(const std::string& geometry,
const std::string& extent,
const std::string& encoding,
const bool multiple_geometries);
virtual ~geos_featureset();
mapnik::feature_ptr next();
private:
std::string geometry_;
boost::scoped_ptr<mapnik::transcoder> tr_;
bool multiple_geometries_;
geos_feature_ptr extent_;
geos_featureset(const geos_featureset&);
const geos_featureset& operator=(const geos_featureset&);
};
#endif // GEOS_FEATURESET_HPP