• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List

OverlayOp.h

00001 /**********************************************************************
00002  * $Id: OverlayOp.h 2557 2009-06-08 09:30:55Z 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 // Forward declarations
00033 namespace geos {
00034         namespace geom {
00035                 class Geometry;
00036                 class Coordinate;
00037                 class GeometryFactory;
00038                 class Polygon;
00039                 class LineString;
00040                 class Point;
00041         }
00042         namespace geomgraph {
00043                 class Label;
00044                 class Edge;
00045                 class Node;
00046         }
00047         namespace operation {
00048                 namespace overlay {
00049                         class ElevationMatrix;
00050                 }
00051         }
00052 }
00053 
00054 namespace geos {
00055 namespace operation { // geos::operation
00056 namespace overlay { // geos::operation::overlay
00057 
00059 //
00063 class GEOS_DLL OverlayOp: public GeometryGraphOperation {
00064 
00065 public:
00066 
00068         //
00072         enum OpCode {
00073                 opINTERSECTION=1,
00074                 opUNION,
00075                 opDIFFERENCE,
00076                 opSYMDIFFERENCE
00077         };
00078 
00079         static geom::Geometry* overlayOp(const geom::Geometry *geom0,
00080                         const geom::Geometry *geom1,
00081                         OpCode opCode);
00082                 //throw(TopologyException *);
00083 
00084         static bool isResultOfOp(geomgraph::Label *label, OpCode opCode);
00085 
00087         //
00090         static bool isResultOfOp(int loc0, int loc1, OpCode opCode);
00091 
00093         // 
00097         OverlayOp(const geom::Geometry *g0, const geom::Geometry *g1);
00098 
00099         virtual ~OverlayOp(); // FIXME: virtual ?
00100 
00101         geom::Geometry* getResultGeometry(OpCode funcCode);
00102                 // throw(TopologyException *);
00103 
00104         geomgraph::PlanarGraph& getGraph() { return graph; }
00105 
00113         bool isCoveredByLA(const geom::Coordinate& coord);
00114 
00121         bool isCoveredByA(const geom::Coordinate& coord);
00122 
00123         /*
00124          * @return true if the coord is located in the interior or boundary of
00125          * a geometry in the list.
00126          */
00127 
00128 protected:
00129 
00138         void insertUniqueEdge(geomgraph::Edge *e);
00139 
00140 private:
00141 
00142         algorithm::PointLocator ptLocator;
00143 
00144         const geom::GeometryFactory *geomFact;
00145 
00146         geom::Geometry *resultGeom;
00147 
00148         geomgraph::PlanarGraph graph;
00149 
00150         geomgraph::EdgeList edgeList;
00151 
00152         std::vector<geom::Polygon*> *resultPolyList;
00153 
00154         std::vector<geom::LineString*> *resultLineList;
00155 
00156         std::vector<geom::Point*> *resultPointList;
00157 
00158         void computeOverlay(OpCode opCode); // throw(TopologyException *);
00159 
00160         void insertUniqueEdges(std::vector<geomgraph::Edge*> *edges);
00161 
00162         /*
00163          * If either of the GeometryLocations for the existing label is
00164          * exactly opposite to the one in the labelToMerge,
00165          * this indicates a dimensional collapse has happened.
00166          * In this case, convert the label for that Geometry to a Line label
00167          */
00168         //Not needed
00169         //void checkDimensionalCollapse(geomgraph::Label labelToMerge, geomgraph::Label existingLabel);
00170 
00182         void computeLabelsFromDepths();
00183 
00188         void replaceCollapsedEdges();
00189 
00200         void copyPoints(int argIndex);
00201 
00210         void computeLabelling(); // throw(TopologyException *);
00211 
00219         void mergeSymLabels();
00220 
00221         void updateNodeLabelling();
00222 
00240         void labelIncompleteNodes();
00241 
00245         void labelIncompleteNode(geomgraph::Node *n, int targetIndex);
00246 
00258         void findResultAreaEdges(OpCode opCode);
00259 
00264         void cancelDuplicateResultEdges();
00265 
00270         bool isCovered(const geom::Coordinate& coord,
00271                         std::vector<geom::Geometry*> *geomList);
00272 
00277         bool isCovered(const geom::Coordinate& coord,
00278                         std::vector<geom::Polygon*> *geomList);
00279 
00284         bool isCovered(const geom::Coordinate& coord,
00285                         std::vector<geom::LineString*> *geomList);
00286 
00291         geom::Geometry* computeGeometry(
00292                         std::vector<geom::Point*> *nResultPointList,
00293                         std::vector<geom::LineString*> *nResultLineList,
00294                         std::vector<geom::Polygon*> *nResultPolyList);
00295 
00297         std::vector<geomgraph::Edge *>dupEdges;
00298 
00303         int mergeZ(geomgraph::Node *n, const geom::Polygon *poly) const;
00304 
00310         int mergeZ(geomgraph::Node *n, const geom::LineString *line) const;
00311 
00315         double avgz[2];
00316         bool avgzcomputed[2];
00317 
00318         double getAverageZ(int targetIndex);
00319         static double getAverageZ(const geom::Polygon *poly);
00320 
00321         ElevationMatrix *elevationMatrix;
00322 
00325         void checkObviouslyWrongResult(OpCode opCode);
00326 
00327 };
00328 
00332 struct overlayOp {
00333 
00334         OverlayOp::OpCode opCode;
00335 
00336         overlayOp(OverlayOp::OpCode code)
00337                 :
00338                 opCode(code)
00339         {}
00340 
00341         geom::Geometry* operator() (const geom::Geometry* g0,
00342                         const geom::Geometry* g1)
00343         {
00344                 return OverlayOp::overlayOp(g0, g1, opCode);
00345         }
00346 
00347 };
00348 
00349 } // namespace geos::operation::overlay
00350 } // namespace geos::operation
00351 } // namespace geos
00352 
00353 #endif // ndef GEOS_OP_OVERLAY_OVERLAYOP_H
00354 
00355 /**********************************************************************
00356  * $Log$
00357  * Revision 1.6  2006/07/05 20:19:29  strk
00358  * added checks for obviously wrong result of difference and intersection ops
00359  *
00360  * Revision 1.5  2006/06/05 15:36:34  strk
00361  * Given OverlayOp funx code enum a name and renamed values to have a lowercase prefix. Drop all of noding headers from installed header set.
00362  *
00363  * Revision 1.4  2006/05/24 15:17:44  strk
00364  * Reduced number of installed headers in geos/operation/ subdir
00365  *
00366  * Revision 1.3  2006/04/14 15:04:36  strk
00367  * fixed missing namespace qualification in overlay::overlayOp
00368  *
00369  * Revision 1.2  2006/04/14 14:35:47  strk
00370  * Added overlayOp() adapter for use in templates expecting binary ops
00371  *
00372  * Revision 1.1  2006/03/17 13:24:59  strk
00373  * 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).
00374  *
00375  **********************************************************************/
00376 

Generated on Thu Jul 22 2010 for GEOS by  doxygen 1.7.1