00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.osgeo.org 00005 * 00006 * Copyright (C) 2012 Sandro Santilli <strk@keybit.net> 00007 * 00008 * This is free software; you can redistribute and/or modify it under 00009 * the terms of the GNU Lesser General Public Licence as published 00010 * by the Free Software Foundation. 00011 * See the COPYING file for more information. 00012 * 00013 *********************************************************************** 00014 * 00015 * Last port: precision/GeometryPrecisionReducer.cpp rev. 1.10 (JTS-1.7) 00016 * 00017 **********************************************************************/ 00018 00019 #ifndef GEOS_PRECISION_GEOMETRYPRECISIONREDUCER_H 00020 #define GEOS_PRECISION_GEOMETRYPRECISIONREDUCER_H 00021 00022 #include <geos/export.h> 00023 #include <geos/geom/GeometryFactory.h> // for GeometryFactory::unique_ptr 00024 #include <memory> // for auto_ptr 00025 00026 // Forward declarations 00027 namespace geos { 00028 namespace geom { 00029 class PrecisionModel; 00030 class GeometryFactory; 00031 class Geometry; 00032 } 00033 } 00034 00035 namespace geos { 00036 namespace precision { // geos.precision 00037 00043 class GEOS_DLL GeometryPrecisionReducer { 00044 00045 private: 00046 00047 // Externally owned 00048 const geom::GeometryFactory *newFactory; 00049 00050 const geom::PrecisionModel &targetPM; 00051 00052 bool removeCollapsed; 00053 00054 bool isPointwise; 00055 00056 std::auto_ptr<geom::Geometry> reducePointwise( const geom::Geometry& geom ); 00057 00058 std::auto_ptr<geom::Geometry> fixPolygonalTopology( 00059 const geom::Geometry& geom ); 00060 00061 geom::GeometryFactory::unique_ptr createFactory( 00062 const geom::GeometryFactory& oldGF, 00063 const geom::PrecisionModel& newPM ); 00064 00065 GeometryPrecisionReducer(GeometryPrecisionReducer const&); /*= delete*/ 00066 GeometryPrecisionReducer& operator=(GeometryPrecisionReducer const&); /*= delete*/ 00067 00068 public: 00069 00081 static std::auto_ptr<geom::Geometry> reduce( 00082 const geom::Geometry &g, 00083 const geom::PrecisionModel &precModel ) 00084 { 00085 GeometryPrecisionReducer reducer(precModel); 00086 return reducer.reduce(g); 00087 } 00088 00100 static std::auto_ptr<geom::Geometry> reducePointwise( 00101 const geom::Geometry &g, 00102 const geom::PrecisionModel &precModel ) 00103 { 00104 GeometryPrecisionReducer reducer(precModel); 00105 reducer.setPointwise(true); 00106 return reducer.reduce(g); 00107 } 00108 00109 GeometryPrecisionReducer(const geom::PrecisionModel &pm) 00110 : 00111 newFactory(0), 00112 targetPM(pm), 00113 removeCollapsed(true), 00114 isPointwise(false) 00115 {} 00116 00127 GeometryPrecisionReducer(const geom::GeometryFactory &gf); 00128 00136 void setRemoveCollapsedComponents(bool remove) { 00137 removeCollapsed = remove; 00138 } 00139 00151 void setPointwise(bool pointwise) 00152 { 00153 isPointwise = pointwise; 00154 } 00155 00156 std::auto_ptr<geom::Geometry> reduce(const geom::Geometry& geom); 00157 00158 }; 00159 00160 } // namespace geos.precision 00161 } // namespace geos 00162 00163 #endif // GEOS_PRECISION_GEOMETRYPRECISIONREDUCER_H