UniqueCoordinateArrayFilter.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2001-2002 Vivid Solutions Inc.
* Copyright (C) 2006 Refractions Research Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <cassert>
#include <set>
#include <vector>
#include <geos/geom/CoordinateFilter.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/Coordinate.h>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
#endif
namespace geos {
namespace util { // geos::util
/*
* A CoordinateFilter that fills a vector of Coordinate const pointers.
* The set of coordinates contains no duplicate points.
*
* Last port: util/UniqueCoordinateArrayFilter.java rev. 1.17
*/
class GEOS_DLL UniqueCoordinateArrayFilter : public geom::CoordinateInspector<UniqueCoordinateArrayFilter> {
public:
UniqueCoordinateArrayFilter(std::vector<const geom::Coordinate*>& target)
: pts(target)
, maxUnique(NO_COORD_INDEX)
{}
UniqueCoordinateArrayFilter(std::vector<const geom::Coordinate*>& target, std::size_t p_maxUnique)
: pts(target)
, maxUnique(p_maxUnique)
{}
~UniqueCoordinateArrayFilter() override {}
template<typename CoordType>
void filter(const CoordType* coord)
{
if(uniqPts.insert(coord).second) {
// TODO make `pts` a CoordinateSequence rather than coercing the type
pts.push_back(coord);
}
if(maxUnique != NO_COORD_INDEX && uniqPts.size() > maxUnique) {
done = true;
}
}
void filter(const geom::CoordinateXY*) {
assert(0); // not supported
}
void filter(const geom::CoordinateXYM*) {
assert(0); // not supported
}
bool isDone() const override {
return done;
}
private:
std::vector<const geom::Coordinate*>& pts; // target set reference
std::set<const geom::CoordinateXY*, geom::CoordinateLessThan> uniqPts; // unique points set
std::size_t maxUnique; // stop visiting when we have this many unique coordinates
bool done = false;
// Declare type as noncopyable
UniqueCoordinateArrayFilter(const UniqueCoordinateArrayFilter& other) = delete;
UniqueCoordinateArrayFilter& operator=(const UniqueCoordinateArrayFilter& rhs) = delete;
};
} // namespace geos::util
} // namespace geos
#ifdef _MSC_VER
#pragma warning(pop)
#endif
geos::util
Utility classes for GEOS.
Definition namespaces.h:314
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38