- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

# OverlayOp.h

    00001 /**********************************************************************
    00002  * $Id: OverlayOp.h 3551 2011-12-15 11:35:28Z strk $
    00003  *
    00004  * GEOS - Geometry Engine Open Source
    00005  * http://geos.refractions.net
    00006  *
    00007  * Copyright (C) 2006 Refractions Research Inc.
    00008  *
    00009  * This is free software; you can redistribute and/or modify it under
    00010  * the terms of the GNU Lesser General Public Licence as published
    00011  * by the Free Software Foundation.
    00012  * See the COPYING file for more information.
    00013  *
    00014  ***********************************************************************
    00015  *
    00016  * Last port: operation/overlay/OverlayOp.java rev. 1.31 (JTS-1.10)
    00017  *
    00018  **********************************************************************/
    00019
    00020 #ifndef GEOS_OP_OVERLAY_OVERLAYOP_H
    00021 #define GEOS_OP_OVERLAY_OVERLAYOP_H
    00022
    00023 #include <geos/export.h>
    00024
    00025 #include <geos/operation/GeometryGraphOperation.h> // for inheritance
    00026 #include <geos/geomgraph/EdgeList.h> // for composition
    00027 #include <geos/algorithm/PointLocator.h> // for composition
    00028 #include <geos/geomgraph/PlanarGraph.h> // for inline (GeometryGraph->PlanarGraph)
    00029
    00030 #include <vector>
    00031
    00032 #ifdef _MSC_VER
    00033 #pragma warning(push)
    00034 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
    00035 #endif
    00036
    00037 // Forward declarations
    00038 namespace geos {
    00039         namespace geom {
    00040                 class Geometry;
    00041                 class Coordinate;
    00042                 class GeometryFactory;
    00043                 class Polygon;
    00044                 class LineString;
    00045                 class Point;
    00046         }
    00047         namespace geomgraph {
    00048                 class Label;
    00049                 class Edge;
    00050                 class Node;
    00051         }
    00052         namespace operation {
    00053                 namespace overlay {
    00054                         class ElevationMatrix;
    00055                 }
    00056         }
    00057 }
    00058
    00059 namespace geos {
    00060 namespace operation { // geos::operation
    00061 namespace overlay { // geos::operation::overlay
    00062
    00064 //
    00068 class GEOS_DLL OverlayOp: public GeometryGraphOperation {
    00069
    00070 public:
    00071
    00073         //
    00077         enum OpCode {
    00078                 opINTERSECTION=1,
    00079                 opUNION,
    00080                 opDIFFERENCE,
    00081                 opSYMDIFFERENCE
    00082         };
    00083
    00084         static geom::Geometry* overlayOp(const geom::Geometry *geom0,
    00085                         const geom::Geometry *geom1,
    00086                         OpCode opCode);
    00087                 //throw(TopologyException *);
    00088
    00089         static bool isResultOfOp(geomgraph::Label *label, OpCode opCode);
    00090
    00092         //
    00095         static bool isResultOfOp(int loc0, int loc1, OpCode opCode);
    00096
    00098         //
    00102         OverlayOp(const geom::Geometry *g0, const geom::Geometry *g1);
    00103
    00104         virtual ~OverlayOp(); // FIXME: virtual ?
    00105
    00106         geom::Geometry* getResultGeometry(OpCode funcCode);
    00107                 // throw(TopologyException *);
    00108
    00109         geomgraph::PlanarGraph& getGraph() { return graph; }
    00110
    00118         bool isCoveredByLA(const geom::Coordinate& coord);
    00119
    00126         bool isCoveredByA(const geom::Coordinate& coord);
    00127
    00128         /*
    00129          * @return true if the coord is located in the interior or boundary of
    00130          * a geometry in the list.
    00131          */
    00132
    00133 protected:
    00134
    00143         void insertUniqueEdge(geomgraph::Edge *e);
    00144
    00145 private:
    00146
    00147         algorithm::PointLocator ptLocator;
    00148
    00149         const geom::GeometryFactory *geomFact;
    00150
    00151         geom::Geometry *resultGeom;
    00152
    00153         geomgraph::PlanarGraph graph;
    00154
    00155         geomgraph::EdgeList edgeList;
    00156
    00157         std::vector<geom::Polygon*> *resultPolyList;
    00158
    00159         std::vector<geom::LineString*> *resultLineList;
    00160
    00161         std::vector<geom::Point*> *resultPointList;
    00162
    00163         void computeOverlay(OpCode opCode); // throw(TopologyException *);
    00164
    00165         void insertUniqueEdges(std::vector<geomgraph::Edge*> *edges);
    00166
    00167         /*
    00168          * If either of the GeometryLocations for the existing label is
    00169          * exactly opposite to the one in the labelToMerge,
    00170          * this indicates a dimensional collapse has happened.
    00171          * In this case, convert the label for that Geometry to a Line label
    00172          */
    00173         //Not needed
    00174         //void checkDimensionalCollapse(geomgraph::Label labelToMerge, geomgraph::Label existingLabel);
    00175
    00187         void computeLabelsFromDepths();
    00188
    00193         void replaceCollapsedEdges();
    00194
    00205         void copyPoints(int argIndex);
    00206
    00215         void computeLabelling(); // throw(TopologyException *);
    00216
    00224         void mergeSymLabels();
    00225
    00226         void updateNodeLabelling();
    00227
    00245         void labelIncompleteNodes();
    00246
    00250         void labelIncompleteNode(geomgraph::Node *n, int targetIndex);
    00251
    00263         void findResultAreaEdges(OpCode opCode);
    00264
    00269         void cancelDuplicateResultEdges();
    00270
    00275         bool isCovered(const geom::Coordinate& coord,
    00276                         std::vector<geom::Geometry*> *geomList);
    00277
    00282         bool isCovered(const geom::Coordinate& coord,
    00283                         std::vector<geom::Polygon*> *geomList);
    00284
    00289         bool isCovered(const geom::Coordinate& coord,
    00290                         std::vector<geom::LineString*> *geomList);
    00291
    00296         geom::Geometry* computeGeometry(
    00297                         std::vector<geom::Point*> *nResultPointList,
    00298                         std::vector<geom::LineString*> *nResultLineList,
    00299                         std::vector<geom::Polygon*> *nResultPolyList);
    00300
    00302         std::vector<geomgraph::Edge *>dupEdges;
    00303
    00308         int mergeZ(geomgraph::Node *n, const geom::Polygon *poly) const;
    00309
    00315         int mergeZ(geomgraph::Node *n, const geom::LineString *line) const;
    00316
    00320         double avgz[2];
    00321         bool avgzcomputed[2];
    00322
    00323         double getAverageZ(int targetIndex);
    00324         static double getAverageZ(const geom::Polygon *poly);
    00325
    00326         ElevationMatrix *elevationMatrix;
    00327
    00330         void checkObviouslyWrongResult(OpCode opCode);
    00331
    00332 };
    00333
    00337 struct overlayOp {
    00338
    00339         OverlayOp::OpCode opCode;
    00340
    00341         overlayOp(OverlayOp::OpCode code)
    00342                 :
    00343                 opCode(code)
    00344         {}
    00345
    00346         geom::Geometry* operator() (const geom::Geometry* g0,
    00347                                     const geom::Geometry* g1)
    00348         {
    00349                 return OverlayOp::overlayOp(g0, g1, opCode);
    00350         }
    00351
    00352 };
    00353
    00354 } // namespace geos::operation::overlay
    00355 } // namespace geos::operation
    00356 } // namespace geos
    00357
    00358 #ifdef _MSC_VER
    00359 #pragma warning(pop)
    00360 #endif
    00361
    00362 #endif // ndef GEOS_OP_OVERLAY_OVERLAYOP_H
    00363
    00364 /**********************************************************************
    00365  * $Log$
    00366  * Revision 1.6  2006/07/05 20:19:29  strk
    00367  * added checks for obviously wrong result of difference and intersection ops
    00368  *
    00369  * Revision 1.5  2006/06/05 15:36:34  strk
    00370  * Given OverlayOp funx code enum a name and renamed values to have a lowercase prefix. Drop all of noding headers from installed header set.
    00371  *
    00372  * Revision 1.4  2006/05/24 15:17:44  strk
    00373  * Reduced number of installed headers in geos/operation/ subdir
    00374  *
    00375  * Revision 1.3  2006/04/14 15:04:36  strk
    00376  * fixed missing namespace qualification in overlay::overlayOp
    00377  *
    00378  * Revision 1.2  2006/04/14 14:35:47  strk
    00379  * Added overlayOp() adapter for use in templates expecting binary ops
    00380  *
    00381  * Revision 1.1  2006/03/17 13:24:59  strk
    00382  * opOverlay.h header splitted. Reduced header inclusions in operation/overlay implementation files. ElevationMatrixFilter code moved from own file to ElevationMatrix.cpp (ideally a class-private).
    00383  *
    00384  **********************************************************************/
    00385