/src/geos/include/geos/operation/sharedpaths/SharedPathsOp.h
Line | Count | Source (jump to first uncovered line) |
1 | | /********************************************************************** |
2 | | * |
3 | | * GEOS - Geometry Engine Open Source |
4 | | * http://geos.osgeo.org |
5 | | * |
6 | | * Copyright (C) 2010 Sandro Santilli <strk@kbt.io> |
7 | | * |
8 | | * This is free software; you can redistribute and/or modify it under |
9 | | * the terms of the GNU Lesser General Public Licence as published |
10 | | * by the Free Software Foundation. |
11 | | * See the COPYING file for more information. |
12 | | * |
13 | | ********************************************************************** |
14 | | * |
15 | | * Last port: original work |
16 | | * |
17 | | * Developed by Sandro Santilli (strk@kbt.io) |
18 | | * for Faunalia (http://www.faunalia.it) |
19 | | * with funding from Regione Toscana - Settore SISTEMA INFORMATIVO |
20 | | * TERRITORIALE ED AMBIENTALE - for the project: "Sviluppo strumenti |
21 | | * software per il trattamento di dati geografici basati su QuantumGIS |
22 | | * e Postgis (CIG 0494241492)" |
23 | | * |
24 | | **********************************************************************/ |
25 | | |
26 | | #pragma once |
27 | | |
28 | | #include <geos/export.h> // for GEOS_DLL |
29 | | |
30 | | #include <vector> |
31 | | |
32 | | // Forward declarations |
33 | | namespace geos { |
34 | | namespace geom { |
35 | | class LineString; |
36 | | class Geometry; |
37 | | class GeometryFactory; |
38 | | } |
39 | | } |
40 | | |
41 | | |
42 | | namespace geos { |
43 | | namespace operation { // geos.operation |
44 | | |
45 | | /// Find shared paths among two linear Geometry objects. |
46 | | namespace sharedpaths { // geos.operation.sharedpaths |
47 | | |
48 | | /** \brief |
49 | | * Find shared paths among two linear Geometry objects |
50 | | * |
51 | | * For each shared path report if it direction is the same |
52 | | * or opposite. |
53 | | * |
54 | | * Paths reported as shared are given in the direction they |
55 | | * appear in the first geometry. |
56 | | * |
57 | | * \remark Developed by Sandro Santilli (strk@kbt.io) |
58 | | * for Faunalia (http://www.faunalia.it) |
59 | | * with funding from Regione Toscana - Settore SISTEMA INFORMATIVO |
60 | | * TERRITORIALE ED AMBIENTALE - for the project: "Sviluppo strumenti |
61 | | * software per il trattamento di dati geografici basati su QuantumGIS |
62 | | * e Postgis (CIG 0494241492)" |
63 | | * |
64 | | */ |
65 | | class GEOS_DLL SharedPathsOp { |
66 | | public: |
67 | | |
68 | | /// LineString vector (list of edges) |
69 | | typedef std::vector<geom::LineString*> PathList; |
70 | | |
71 | | /// Find paths shared between two linear geometries |
72 | | /// |
73 | | /// @param g1 |
74 | | /// First geometry. Must be linear. |
75 | | /// |
76 | | /// @param g2 |
77 | | /// Second geometry. Must be linear. |
78 | | /// |
79 | | /// @param sameDirection |
80 | | /// Shared edges having the same direction are pushed |
81 | | /// onto this vector. They'll be of type LineString. |
82 | | /// Ownership of the edges is transferred. |
83 | | /// |
84 | | /// @param oppositeDirection |
85 | | /// Shared edges having the opposite direction are pushed |
86 | | /// onto this vector. They'll be of type geom::LineString. |
87 | | /// Ownership of the edges is transferred. |
88 | | /// |
89 | | static void sharedPathsOp(const geom::Geometry& g1, |
90 | | const geom::Geometry& g2, |
91 | | PathList& sameDirection, |
92 | | PathList& oppositeDirection); |
93 | | |
94 | | /// Constructor |
95 | | /// |
96 | | /// @param g1 |
97 | | /// First geometry. Must be linear. |
98 | | /// |
99 | | /// @param g2 |
100 | | /// Second geometry. Must be linear. |
101 | | /// |
102 | | SharedPathsOp(const geom::Geometry& g1, const geom::Geometry& g2); |
103 | | |
104 | | /// Get shared paths |
105 | | /// |
106 | | /// @param sameDirection |
107 | | /// Shared edges having the same direction are pushed |
108 | | /// onto this vector. They'll be of type geom::LineString. |
109 | | /// Ownership of the edges is transferred. |
110 | | /// |
111 | | /// @param oppositeDirection |
112 | | /// Shared edges having the opposite direction are pushed |
113 | | /// onto this vector. They'll be of type geom::LineString. |
114 | | /// Ownership of the edges is transferred. |
115 | | /// |
116 | | void getSharedPaths(PathList& sameDirection, PathList& oppositeDirection); |
117 | | |
118 | | /// Delete all edges in the list |
119 | | static void clearEdges(PathList& from); |
120 | | |
121 | | private: |
122 | | |
123 | | /// Get all the linear intersections |
124 | | /// |
125 | | /// Ownership of linestring pushed to the given container |
126 | | /// is transferred to caller. See clearEdges for a deep |
127 | | /// release if you need one. |
128 | | /// |
129 | | void findLinearIntersections(PathList& to); |
130 | | |
131 | | /// Check if the given edge goes forward or backward on the given line. |
132 | | /// |
133 | | /// PRECONDITION: It is assumed the edge fully lays on the geometry |
134 | | /// |
135 | | bool isForward(const geom::LineString& edge, |
136 | | const geom::Geometry& geom); |
137 | | |
138 | | /// Check if the given edge goes in the same direction over |
139 | | /// the two geometries. |
140 | | bool |
141 | | isSameDirection(const geom::LineString& edge) |
142 | 0 | { |
143 | 0 | return (isForward(edge, _g1) == isForward(edge, _g2)); |
144 | 0 | } |
145 | | |
146 | | /// Throw an IllegalArgumentException if the geom is not linear |
147 | | void checkLinealInput(const geom::Geometry& g); |
148 | | |
149 | | const geom::Geometry& _g1; |
150 | | const geom::Geometry& _g2; |
151 | | const geom::GeometryFactory& _gf; |
152 | | |
153 | | // Declare type as noncopyable |
154 | | SharedPathsOp(const SharedPathsOp& other) = delete; |
155 | | SharedPathsOp& operator=(const SharedPathsOp& rhs) = delete; |
156 | | |
157 | | }; |
158 | | |
159 | | } // namespace geos.operation.sharedpaths |
160 | | } // namespace geos.operation |
161 | | } // namespace geos |