2010-11-10 11:46:09 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2010-11-12 22:18:53 +01:00
|
|
|
* Copyright (C) 2010 Artem Pavlenko
|
2010-11-10 11:46:09 +01:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
2010-11-12 22:18:53 +01:00
|
|
|
geos_featureset::geos_featureset(GEOSGeometry* geometry,
|
|
|
|
GEOSGeometry* extent,
|
2010-11-14 16:02:01 +01:00
|
|
|
int identifier,
|
|
|
|
const std::string& field,
|
|
|
|
const std::string& field_name,
|
2010-11-10 11:46:09 +01:00
|
|
|
const std::string& encoding,
|
2010-11-14 16:02:01 +01:00
|
|
|
bool multiple_geometries)
|
2010-11-10 11:46:09 +01:00
|
|
|
: geometry_(geometry),
|
|
|
|
tr_(new transcoder(encoding)),
|
2010-11-12 22:18:53 +01:00
|
|
|
extent_(extent),
|
2010-11-14 16:02:01 +01:00
|
|
|
identifier_(identifier),
|
|
|
|
field_(field),
|
|
|
|
field_name_(field_name),
|
2010-11-10 11:46:09 +01:00
|
|
|
multiple_geometries_(multiple_geometries),
|
2010-11-12 22:18:53 +01:00
|
|
|
already_rendered_(false)
|
2010-11-10 11:46:09 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-14 16:02:01 +01:00
|
|
|
geos_featureset::~geos_featureset()
|
|
|
|
{
|
|
|
|
}
|
2010-11-10 11:46:09 +01:00
|
|
|
|
|
|
|
feature_ptr geos_featureset::next()
|
|
|
|
{
|
2010-11-12 22:18:53 +01:00
|
|
|
if (! already_rendered_)
|
|
|
|
{
|
|
|
|
already_rendered_ = true;
|
|
|
|
|
|
|
|
if (GEOSisValid(geometry_) && ! GEOSisEmpty(geometry_))
|
|
|
|
{
|
2010-11-14 16:02:01 +01:00
|
|
|
bool render_geometry = true;
|
|
|
|
|
|
|
|
if (*extent_ != NULL && GEOSisValid(*extent_) && !GEOSisEmpty(*extent_))
|
2010-11-12 22:18:53 +01:00
|
|
|
{
|
2010-11-14 16:02:01 +01:00
|
|
|
const int type = GEOSGeomTypeId(*extent_);
|
|
|
|
render_geometry = false;
|
|
|
|
|
|
|
|
switch ( type )
|
|
|
|
{
|
|
|
|
case GEOS_POINT:
|
|
|
|
if (GEOSIntersects(*extent_, geometry_))
|
|
|
|
{
|
|
|
|
render_geometry = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GEOS_POLYGON:
|
|
|
|
if (GEOSContains(*extent_, geometry_)
|
|
|
|
|| GEOSWithin(geometry_, *extent_)
|
|
|
|
|| GEOSEquals(geometry_, *extent_))
|
|
|
|
{
|
|
|
|
render_geometry = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifdef MAPNIK_DEBUG
|
2010-11-18 23:12:39 +01:00
|
|
|
clog << "GEOS Plugin: unknown extent geometry_type=" << type << endl;
|
2010-11-14 16:02:01 +01:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (render_geometry)
|
|
|
|
{
|
2010-11-18 23:12:39 +01:00
|
|
|
geos_wkb_ptr wkb(geometry_);
|
|
|
|
if (wkb.is_valid())
|
|
|
|
{
|
|
|
|
feature_ptr feature(new Feature(identifier_));
|
2010-11-10 11:46:09 +01:00
|
|
|
|
2010-11-18 23:12:39 +01:00
|
|
|
geometry_utils::from_wkb(*feature,
|
|
|
|
wkb.data(),
|
|
|
|
wkb.size(),
|
|
|
|
multiple_geometries_);
|
2010-11-14 16:02:01 +01:00
|
|
|
|
2010-11-18 23:12:39 +01:00
|
|
|
if (field_ != "")
|
|
|
|
{
|
|
|
|
boost::put(*feature, field_name_, tr_->transcode(field_.c_str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return feature;
|
2010-11-14 16:02:01 +01:00
|
|
|
}
|
2010-11-12 22:18:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-10 11:46:09 +01:00
|
|
|
|
2010-11-12 22:18:53 +01:00
|
|
|
return feature_ptr();
|
2010-11-10 11:46:09 +01:00
|
|
|
}
|
|
|
|
|