1 /********************************************************************** 2 * 3 * GEOS - Geometry Engine Open Source 4 * http://geos.osgeo.org 5 * 6 * Copyright (C) 2006 Refractions Research Inc. 7 * 8 * This is free software; you can redistribute and/or modify it under 9 * the terms of the GNU Lesser General Licence as published 10 * by the Free Software Foundation. 11 * See the COPYING file for more information. 12 * 13 ********************************************************************** 14 * 15 * Last port: simplify/DouglasPeuckerSimplifier.java rev. 1.5 (JTS-1.7) 16 * 17 **********************************************************************/ 18 19 #ifndef GEOS_SIMPLIFY_DOUBGLASPEUCKERSIMPLIFIER_H 20 #define GEOS_SIMPLIFY_DOUBGLASPEUCKERSIMPLIFIER_H 21 22 #include <geos/export.h> 23 #include <memory> // for unique_ptr 24 25 // Forward declarations 26 namespace geos { 27 namespace geom { 28 class Geometry; 29 } 30 } 31 32 namespace geos { 33 namespace simplify { // geos::simplify 34 35 36 /** \brief 37 * Simplifies a Geometry using the standard Douglas-Peucker algorithm. 38 * 39 * Ensures that any polygonal geometries returned are valid. 40 * Simple lines are not guaranteed to remain simple after simplification. 41 * 42 * Note that in general D-P does not preserve topology - 43 * e.g. polygons can be split, collapse to lines or disappear 44 * holes can be created or disappear, 45 * and lines can cross. 46 * To simplify geometry while preserving topology use TopologyPreservingSimplifier. 47 * (However, using D-P is significantly faster). 48 * 49 */ 50 class GEOS_DLL DouglasPeuckerSimplifier { 51 52 public: 53 54 static std::unique_ptr<geom::Geometry> simplify( 55 const geom::Geometry* geom, 56 double tolerance); 57 58 DouglasPeuckerSimplifier(const geom::Geometry* geom); 59 60 /** \brief 61 * Sets the distance tolerance for the simplification. 62 * 63 * All vertices in the simplified geometry will be within this 64 * distance of the original geometry. 65 * The tolerance value must be non-negative. A tolerance value 66 * of zero is effectively a no-op. 67 * 68 * @param tolerance the approximation tolerance to use 69 */ 70 void setDistanceTolerance(double tolerance); 71 72 std::unique_ptr<geom::Geometry> getResultGeometry(); 73 74 75 private: 76 77 const geom::Geometry* inputGeom; 78 79 double distanceTolerance; 80 }; 81 82 83 } // namespace geos::simplify 84 } // namespace geos 85 86 #endif // GEOS_SIMPLIFY_DOUBGLASPEUCKERSIMPLIFIER_H 87