landr/LandRTools.hpp
Go to the documentation of this file.
00001 /*
00002 
00003   This file is part of OpenFLUID software
00004   Copyright(c) 2007, INRA - Montpellier SupAgro
00005 
00006 
00007  == GNU General Public License Usage ==
00008 
00009   OpenFLUID is free software: you can redistribute it and/or modify
00010   it under the terms of the GNU General Public License as published by
00011   the Free Software Foundation, either version 3 of the License, or
00012   (at your option) any later version.
00013 
00014   OpenFLUID is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017   GNU General Public License for more details.
00018 
00019   You should have received a copy of the GNU General Public License
00020   along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
00021 
00022 
00023  == Other Usage ==
00024 
00025   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00026   license, and requires a written agreement between You and INRA.
00027   Licensees for Other Usage of OpenFLUID may use this file in accordance
00028   with the terms contained in the written agreement between You and INRA.
00029   
00030 */
00031 
00032 /**
00033  \file LandRTools.hpp
00034  \brief Header of ...
00035 
00036  \author Aline LIBRES <aline.libres@gmail.com>
00037  */
00038 
00039 #ifndef LANDRTOOLS_HPP_
00040 #define LANDRTOOLS_HPP_
00041 
00042 #include <vector>
00043 #include <list>
00044 #include <openfluid/landr/LineStringGraph.hpp>
00045 #include <openfluid/dllexport.hpp>
00046 #include <geos/geom/CoordinateArraySequenceFactory.h>
00047 
00048 namespace geos {
00049 namespace geom {
00050 class Geometry;
00051 class LineString;
00052 class Polygon;
00053 }
00054 }
00055 
00056 namespace openfluid {
00057 namespace landr {
00058 
00059 class VectorDataset;
00060 
00061 /**
00062  * @brief Set of tools to manage LandR elements.
00063  */
00064 class DLLEXPORT LandRTools
00065 {
00066   public:
00067 
00068     enum Relationship
00069     {
00070       NONE, INTERSECTS, CONTAINS, EQUALS, TOUCHES
00071     };
00072 
00073     /**
00074      * @brief Returns a geos::geom::LineString representing the linearized input geos::geom::Geometry.
00075      *
00076      * @param Geom The geos::geom::Geometry to linearize.
00077      * @return A new allocated geos::geom::LineString representing the linearized input geos::geom::Geometry,
00078      * or 0 if the geos::geom::Geometry cannot be linearized into a single geos::geom::LineString.
00079      */
00080     static geos::geom::LineString* getMergedLineStringFromGeometry(
00081         geos::geom::Geometry* Geom);
00082 
00083     /**
00084      * @brief Returns a vector of geos::geom::LineString representing the linearized input geos::geom::Geometry.
00085      *
00086      * @param Geom The geos::geom::Geometry to linearize.
00087      * @return A new allocated vector of geos::geom::LineString representing the maximal linearized input geos::geom::Geometry,
00088      * or 0 if the geos::geom::Geometry is not \"Line\" typed.
00089      */
00090     static std::vector<geos::geom::LineString*>* getMergedLineStringsFromGeometry(
00091         geos::geom::Geometry* Geom);
00092 
00093     /**
00094      * @brief Returns all exterior rings of the polygon-typed VectorDataset.
00095      *
00096      * @param Val A VectorDataset of polygons.
00097      * @return A vector of new allocated geos::geom::LineString representing exterior rings.
00098      * @throw base::OFException if the VectorDataset is not polygon-typed.
00099      */
00100     static std::vector<geos::geom::LineString*> getVectorOfExteriorRings(
00101         openfluid::landr::VectorDataset& Val);
00102 
00103     /**
00104      * @brief Returns all geos::geom::LineString composing of the linestring-typed VectorDataset.
00105      *
00106      * @param Val A VectorDataset of linestrings.
00107      * @return A vector of new allocated geos::geom::Geometry representing lines.
00108      * @throw base::OFException if the VectorDataset is not linestring-typed.
00109      */
00110     static std::vector<geos::geom::LineString*> getVectorOfLines(
00111         openfluid::landr::VectorDataset& Val);
00112 
00113     /**
00114      * @brief Gets all full noded geos::geom::LineString from intersection between geom1 and geom2, with snap tolerance.
00115      *
00116      * @param Geom1 The geos::geom::Geometry to node with Geom2.
00117      * @param Geom2 The other geos::geom::Geometry.
00118      * @param SnapTolerance The tolerance to use while computing intersections and equality of lines.
00119      * @param PrecisionReducer The PrecisionModel value for reducing coordinates precision, default is 10000000 (7 digits).
00120      * @return A vector of geos::geom::LineString, representing all input lines, cut at each node.
00121      */
00122     static std::vector<geos::geom::LineString*>* getNodedLines(
00123         geos::geom::Geometry* Geom1, geos::geom::Geometry* Geom2,
00124         double SnapTolerance = 0,double PrecisionReducer=10000000);
00125 
00126     /**
00127      * @brief Same as from geos::operation::overlay::snap::SnapOverlayOp::Union(),
00128      * but with ability to use the wished snap tolerance value.
00129      *
00130      * @param Geom1 The geos::geom::Geometry to join with Geom2.
00131      * @param Geom2 The other geos::geom::Geometry.
00132      * @param SnapTolerance The tolerance to use, default is 0.
00133      * @return A new geos::geom::Geometry representing the union of Geom1 and Geom2 according to SnapTolerance value.
00134      */
00135     static geos::geom::Geometry* computeSnapOverlayUnion(
00136         geos::geom::Geometry& Geom1, geos::geom::Geometry& Geom2,
00137         double SnapTolerance = 0);
00138 
00139 
00140     /**
00141      * @brief Returns true if a geos::geom::LineString is exactly equals of an element of a list of geos::geom::LineString, up to a specified tolerance.
00142      * @param Line The geos::geom::LineString to compare.
00143      * @param RefLines The list of geos::geom::LineString to compare to.
00144      * @param Tolerance The tolerance to use.
00145      */
00146     static bool exists(geos::geom::LineString* Line,
00147                        std::list<geos::geom::LineString*> RefLines, double Tolerance = 0);
00148 
00149     /**
00150      * @brief Creates all possible geos::geom::Polygon from a geos::geom::Geometry.
00151      *
00152      * @param Lines The input vector of geos::geom::Geometry to polygonize.
00153      * @param Polygons The output vector of newly created geos::geom::Polygon.
00154      * @param Dangles The output vector of dangle geos::geom::LineString.
00155      */
00156     static void polygonizeGeometry(
00157         std::vector<geos::geom::Geometry*>& Lines,
00158         std::vector<geos::geom::Polygon*>& Polygons,
00159         std::vector<const geos::geom::LineString*>& Dangles);
00160 
00161     /**
00162      * @brief Recursive depth first search algorithm in a LineStringGraph and mark visited Nodes
00163      *
00164      * @param Node the begin geos::planargraph::Node of LineStringGraph
00165      */
00166     static void markVisitedNodesUsingDFS(geos::planargraph::Node* Node);
00167 
00168     /**
00169      * @brief Intersection of two geos::geom::Geometry of Polygons.
00170      *
00171      * @param Geom1 The geos::geom::Geometry to join with Geom2.
00172      * @param Geom2 The other geos::geom::Geometry.
00173      * @return A vector of geos::geom::Polygon representing the intersection of Geom1 and Geom2.
00174      */
00175     static std::vector<geos::geom::Polygon*> computeIntersectPolygons(
00176         geos::geom::Geometry* Geom1, geos::geom::Geometry* Geom2);
00177 
00178 
00179     /**
00180      * @brief Splits a geos::geom::LineString by a geos::geom::Point.
00181      *
00182      * @param Entity An existent geos::geom::LineString.
00183      * @param Point A geos::geom::Point.
00184      * @param SnapTolerance The threshold distance used to find Point on Line.
00185      * @return a vector of geos::geom::LineString,
00186      *  or empty vector if splitting operation is null.
00187      */
00188     static std::vector<geos::geom::LineString*> splitLineStringByPoint(geos::geom::LineString& Entity, geos::geom::Point& Point,double SnapTolerance);
00189 
00190 
00191     /**
00192      * @brief Recursively split operation on a geos::geom::LineString by a vector of geos::geom::Point.
00193      *
00194      * @param Entity An existent geos::geom::LineString.
00195      * @param Point A vector of geos::geom::Point.
00196      * @param SnapTolerance The threshold distance used to find Point on Line.
00197      * @param vLines the resulting vector of geos::geom::LineString splitted.
00198      * @param step iterator of the vector of Point; default is 0.
00199      */
00200     static void splitLineStringByPoints(geos::geom::LineString& Entity,std::vector<geos::geom::Point*>&Points,
00201                                              double SnapTolerance,std::vector<geos::geom::LineString*>&vLines,unsigned int step=0);
00202 
00203     /**
00204      * @brief Clean a vector of geos::geom::LineString (break at each intersection and remove duplicate geometry)
00205      *
00206      * @param vLines An existent vector of geos::geom::LineString.
00207      * @param SnapTolerance The tolerance to use.
00208      * @return a vector of geos::geom::LineString.
00209      */
00210     static std::vector<geos::geom::LineString*>* cleanLineStrings(
00211         std::vector<geos::geom::LineString*> vLines,double SnapTolerance);
00212 
00213 };
00214 
00215 }
00216 } /* namespace openfluid */
00217 #endif /* LANDRTOOLS_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines