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

# OverlayOp.h

    00001 /**********************************************************************
    00002  * $Id: OverlayOp.h 1820 2006-09-06 16:54:23Z mloskot $
    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 #ifndef GEOS_OP_OVERLAY_OVERLAYOP_H
    00017 #define GEOS_OP_OVERLAY_OVERLAYOP_H
    00018
    00019 #include <geos/operation/GeometryGraphOperation.h> // for inheritance
    00020 #include <geos/geomgraph/EdgeList.h> // for composition
    00021 #include <geos/algorithm/PointLocator.h> // for composition
    00022 #include <geos/geomgraph/PlanarGraph.h> // for inline (GeometryGraph->PlanarGraph)
    00023
    00024 #include <vector>
    00025
    00026 // Forward declarations
    00027 namespace geos {
    00028         namespace geom {
    00029                 class Geometry;
    00030                 class Coordinate;
    00031                 class GeometryFactory;
    00032                 class Polygon;
    00033                 class LineString;
    00034                 class Point;
    00035         }
    00036         namespace geomgraph {
    00037                 class Label;
    00038                 class Edge;
    00039                 class Node;
    00040         }
    00041         namespace operation {
    00042                 namespace overlay {
    00043                         class ElevationMatrix;
    00044                 }
    00045         }
    00046 }
    00047
    00048 namespace geos {
    00049 namespace operation { // geos::operation
    00050 namespace overlay { // geos::operation::overlay
    00051
    00053 //
    00057 class OverlayOp: public GeometryGraphOperation {
    00058
    00059 public:
    00060
    00062         //
    00066         enum OpCode {
    00067                 opINTERSECTION=1,
    00068                 opUNION,
    00069                 opDIFFERENCE,
    00070                 opSYMDIFFERENCE
    00071         };
    00072
    00073         static geom::Geometry* overlayOp(const geom::Geometry *geom0,
    00074                         const geom::Geometry *geom1,
    00075                         OpCode opCode);
    00076                 //throw(TopologyException *);
    00077
    00078         static bool isResultOfOp(geomgraph::Label *label, OpCode opCode);
    00079
    00081         //
    00084         static bool isResultOfOp(int loc0, int loc1, OpCode opCode);
    00085
    00087         //
    00091         OverlayOp(const geom::Geometry *g0, const geom::Geometry *g1);
    00092
    00093         virtual ~OverlayOp(); // FIXME: virtual ?
    00094
    00095         geom::Geometry* getResultGeometry(OpCode funcCode);
    00096                 // throw(TopologyException *);
    00097
    00098         geomgraph::PlanarGraph& getGraph() { return graph; }
    00099
    00107         bool isCoveredByLA(const geom::Coordinate& coord);
    00108
    00115         bool isCoveredByA(const geom::Coordinate& coord);
    00116
    00117         /*
    00118          * @return true if the coord is located in the interior or boundary of
    00119          * a geometry in the list.
    00120          */
    00121
    00122 protected:
    00123
    00132         void insertUniqueEdge(geomgraph::Edge *e);
    00133
    00134 private:
    00135
    00136         algorithm::PointLocator ptLocator;
    00137
    00138         const geom::GeometryFactory *geomFact;
    00139
    00140         geom::Geometry *resultGeom;
    00141
    00142         geomgraph::PlanarGraph graph;
    00143
    00144         geomgraph::EdgeList edgeList;
    00145
    00146         std::vector<geom::Polygon*> *resultPolyList;
    00147
    00148         std::vector<geom::LineString*> *resultLineList;
    00149
    00150         std::vector<geom::Point*> *resultPointList;
    00151
    00152         void computeOverlay(OpCode opCode); // throw(TopologyException *);
    00153
    00154         void insertUniqueEdges(std::vector<geomgraph::Edge*> *edges);
    00155
    00156         /*
    00157          * If either of the GeometryLocations for the existing label is
    00158          * exactly opposite to the one in the labelToMerge,
    00159          * this indicates a dimensional collapse has happened.
    00160          * In this case, convert the label for that Geometry to a Line label
    00161          */
    00162         //Not needed
    00163         //void checkDimensionalCollapse(geomgraph::Label labelToMerge, geomgraph::Label existingLabel);
    00164
    00176         void computeLabelsFromDepths();
    00177
    00182         void replaceCollapsedEdges();
    00183
    00194         void copyPoints(int argIndex);
    00195
    00204         void computeLabelling(); // throw(TopologyException *);
    00205
    00213         void mergeSymLabels();
    00214
    00215         void updateNodeLabelling();
    00216
    00234         void labelIncompleteNodes();
    00235
    00239         void labelIncompleteNode(geomgraph::Node *n, int targetIndex);
    00240
    00252         void findResultAreaEdges(OpCode opCode);
    00253
    00258         void cancelDuplicateResultEdges();
    00259
    00264         bool isCovered(const geom::Coordinate& coord,
    00265                         std::vector<geom::Geometry*> *geomList);
    00266
    00271         bool isCovered(const geom::Coordinate& coord,
    00272                         std::vector<geom::Polygon*> *geomList);
    00273
    00278         bool isCovered(const geom::Coordinate& coord,
    00279                         std::vector<geom::LineString*> *geomList);
    00280
    00285         geom::Geometry* computeGeometry(
    00286                         std::vector<geom::Point*> *nResultPointList,
    00287                         std::vector<geom::LineString*> *nResultLineList,
    00288                         std::vector<geom::Polygon*> *nResultPolyList);
    00289
    00291         std::vector<geomgraph::Edge *>dupEdges;
    00292
    00297         int mergeZ(geomgraph::Node *n, const geom::Polygon *poly) const;
    00298
    00304         int mergeZ(geomgraph::Node *n, const geom::LineString *line) const;
    00305
    00309         double avgz[2];
    00310         bool avgzcomputed[2];
    00311
    00312         double getAverageZ(int targetIndex);
    00313         static double getAverageZ(const geom::Polygon *poly);
    00314
    00315         ElevationMatrix *elevationMatrix;
    00316
    00319         void checkObviouslyWrongResult(OpCode opCode);
    00320
    00321 };
    00322
    00326 struct overlayOp {
    00327
    00328         OverlayOp::OpCode opCode;
    00329
    00330         overlayOp(OverlayOp::OpCode code)
    00331                 :
    00332                 opCode(code)
    00333         {}
    00334
    00335         geom::Geometry* operator() (const geom::Geometry* g0,
    00336                         const geom::Geometry* g1)
    00337         {
    00338                 return OverlayOp::overlayOp(g0, g1, opCode);
    00339         }
    00340
    00341 };
    00342
    00343 } // namespace geos::operation::overlay
    00344 } // namespace geos::operation
    00345 } // namespace geos
    00346
    00347 #endif // ndef GEOS_OP_OVERLAY_OVERLAYOP_H
    00348
    00349 /**********************************************************************
    00350  * $Log$
    00351  * Revision 1.6  2006/07/05 20:19:29  strk
    00352  * added checks for obviously wrong result of difference and intersection ops
    00353  *
    00354  * Revision 1.5  2006/06/05 15:36:34  strk
    00355  * Given OverlayOp funx code enum a name and renamed values to have a lowercase prefix. Drop all of noding headers from installed header set.
    00356  *
    00357  * Revision 1.4  2006/05/24 15:17:44  strk
    00358  * Reduced number of installed headers in geos/operation/ subdir
    00359  *
    00360  * Revision 1.3  2006/04/14 15:04:36  strk
    00361  * fixed missing namespace qualification in overlay::overlayOp
    00362  *
    00363  * Revision 1.2  2006/04/14 14:35:47  strk
    00364  * Added overlayOp() adapter for use in templates expecting binary ops
    00365  *
    00366  * Revision 1.1  2006/03/17 13:24:59  strk
    00367  * 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).
    00368  *
    00369  **********************************************************************/
    00370