2010-11-10 10:46:09 +00:00
|
|
|
/*****************************************************************************
|
2011-11-14 03:37:50 +00:00
|
|
|
*
|
2010-11-10 10:46:09 +00:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2011-10-23 19:19:56 +00:00
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
2010-11-10 10:46:09 +00: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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2011-10-23 19:19:56 +00:00
|
|
|
// stl
|
2010-11-10 10:46:09 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
// mapnik
|
|
|
|
#include <mapnik/global.hpp>
|
2012-04-08 00:20:56 +00:00
|
|
|
#include <mapnik/debug.hpp>
|
2010-11-10 10:46:09 +00:00
|
|
|
#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>
|
2011-05-16 23:41:34 +00:00
|
|
|
#include <mapnik/feature_factory.hpp>
|
2010-11-10 10:46:09 +00:00
|
|
|
|
|
|
|
#include "geos_featureset.hpp"
|
|
|
|
|
|
|
|
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;
|
2011-05-16 23:41:34 +00:00
|
|
|
using mapnik::feature_factory;
|
2010-11-10 10:46:09 +00:00
|
|
|
|
|
|
|
|
2010-11-12 21:18:53 +00:00
|
|
|
geos_featureset::geos_featureset(GEOSGeometry* geometry,
|
|
|
|
GEOSGeometry* extent,
|
2010-11-14 15:02:01 +00:00
|
|
|
int identifier,
|
|
|
|
const std::string& field,
|
|
|
|
const std::string& field_name,
|
2011-12-06 12:53:16 +00:00
|
|
|
const std::string& encoding)
|
2011-11-14 03:37:50 +00:00
|
|
|
: geometry_(geometry),
|
|
|
|
tr_(new transcoder(encoding)),
|
|
|
|
extent_(extent),
|
|
|
|
identifier_(identifier),
|
|
|
|
field_(field),
|
|
|
|
field_name_(field_name),
|
2012-01-17 19:22:21 +00:00
|
|
|
already_rendered_(false),
|
2012-01-19 22:36:27 +00:00
|
|
|
ctx_(boost::make_shared<mapnik::context_type>())
|
2010-11-10 10:46:09 +00:00
|
|
|
{
|
2012-01-17 19:22:21 +00:00
|
|
|
ctx_->push(field_name);
|
2010-11-10 10:46:09 +00:00
|
|
|
}
|
|
|
|
|
2011-11-14 03:37:50 +00:00
|
|
|
geos_featureset::~geos_featureset()
|
2010-11-14 15:02:01 +00:00
|
|
|
{
|
|
|
|
}
|
2010-11-10 10:46:09 +00:00
|
|
|
|
|
|
|
feature_ptr geos_featureset::next()
|
|
|
|
{
|
2010-11-12 21:18:53 +00:00
|
|
|
if (! already_rendered_)
|
|
|
|
{
|
|
|
|
already_rendered_ = true;
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2010-11-12 21:18:53 +00:00
|
|
|
if (GEOSisValid(geometry_) && ! GEOSisEmpty(geometry_))
|
|
|
|
{
|
2010-11-14 15:02:01 +00:00
|
|
|
bool render_geometry = true;
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2011-10-23 19:19:56 +00:00
|
|
|
if (*extent_ != NULL && GEOSisValid(*extent_) && ! GEOSisEmpty(*extent_))
|
2010-11-12 21:18:53 +00:00
|
|
|
{
|
2010-11-14 15:02:01 +00:00
|
|
|
const int type = GEOSGeomTypeId(*extent_);
|
|
|
|
render_geometry = false;
|
|
|
|
|
2011-10-23 19:19:56 +00:00
|
|
|
switch (type)
|
2010-11-14 15:02:01 +00:00
|
|
|
{
|
|
|
|
case GEOS_POINT:
|
|
|
|
if (GEOSIntersects(*extent_, geometry_))
|
|
|
|
{
|
|
|
|
render_geometry = true;
|
|
|
|
}
|
|
|
|
break;
|
2011-10-23 19:19:56 +00:00
|
|
|
|
2010-11-14 15:02:01 +00:00
|
|
|
case GEOS_POLYGON:
|
|
|
|
if (GEOSContains(*extent_, geometry_)
|
|
|
|
|| GEOSWithin(geometry_, *extent_)
|
|
|
|
|| GEOSEquals(geometry_, *extent_))
|
|
|
|
{
|
|
|
|
render_geometry = true;
|
|
|
|
}
|
|
|
|
break;
|
2011-10-23 19:19:56 +00:00
|
|
|
|
|
|
|
default:
|
2012-04-09 01:00:51 +00:00
|
|
|
MAPNIK_LOG_DEBUG(geos) << "geos_featureset: Unknown extent geometry_type=" << type;
|
2010-11-14 15:02:01 +00:00
|
|
|
break;
|
2011-11-14 03:37:50 +00:00
|
|
|
}
|
2010-11-14 15:02:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (render_geometry)
|
|
|
|
{
|
2010-11-18 22:12:39 +00:00
|
|
|
geos_wkb_ptr wkb(geometry_);
|
|
|
|
if (wkb.is_valid())
|
|
|
|
{
|
2012-01-17 19:22:21 +00:00
|
|
|
feature_ptr feature(feature_factory::create(ctx_,identifier_));
|
2010-11-10 10:46:09 +00:00
|
|
|
|
2012-07-20 22:09:01 +00:00
|
|
|
if (geometry_utils::from_wkb(feature->paths(),
|
2010-11-18 22:12:39 +00:00
|
|
|
wkb.data(),
|
2012-07-20 22:09:01 +00:00
|
|
|
wkb.size())
|
|
|
|
&& field_ != "")
|
2010-11-18 22:12:39 +00:00
|
|
|
{
|
2012-01-17 19:22:21 +00:00
|
|
|
feature->put(field_name_, tr_->transcode(field_.c_str()));
|
2010-11-18 22:12:39 +00:00
|
|
|
}
|
2012-02-02 01:37:35 +00:00
|
|
|
|
2010-11-18 22:12:39 +00:00
|
|
|
return feature;
|
2010-11-14 15:02:01 +00:00
|
|
|
}
|
2010-11-12 21:18:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-10 10:46:09 +00:00
|
|
|
|
2010-11-12 21:18:53 +00:00
|
|
|
return feature_ptr();
|
2010-11-10 10:46:09 +00:00
|
|
|
}
|