1 /***************************************************************************
2   qgsoverlayutils.h
3   ---------------------
4   Date                 : April 2018
5   Copyright            : (C) 2018 by Martin Dobias
6   Email                : wonder dot sk at gmail dot com
7  ***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 
16 #ifndef QGSOVERLAYUTILS_H
17 #define QGSOVERLAYUTILS_H
18 
19 #include <QList>
20 #include "qgswkbtypes.h"
21 
22 #define SIP_NO_FILE
23 
24 ///@cond PRIVATE
25 
26 class QgsFeatureSource;
27 class QgsFeatureSink;
28 class QgsFields;
29 class QgsProcessingContext;
30 class QgsProcessingFeedback;
31 class QgsGeometry;
32 
33 namespace QgsOverlayUtils
34 {
35 
36   //! how to write out attributes of features after overlay operation
37   enum DifferenceOutput
38   {
39     OutputA,   //!< Write only attributes of the first layer
40     OutputAB,  //!< Write attributes of both layers
41     OutputBA,  //!< Write attributes of both layers, inverted (first attributes of B, then attributes of A)
42   };
43 
44   void difference( const QgsFeatureSource &sourceA, const QgsFeatureSource &sourceB, QgsFeatureSink &sink, QgsProcessingContext &context, QgsProcessingFeedback *feedback, long &count, long totalCount, DifferenceOutput outputAttrs );
45 
46   void intersection( const QgsFeatureSource &sourceA, const QgsFeatureSource &sourceB, QgsFeatureSink &sink, QgsProcessingContext &context, QgsProcessingFeedback *feedback, long &count, long totalCount, const QList<int> &fieldIndicesA, const QList<int> &fieldIndicesB );
47 
48   //! Makes sure that what came out from intersection of two geometries is good to be used in the output
49   bool sanitizeIntersectionResult( QgsGeometry &geom, QgsWkbTypes::GeometryType geometryType );
50 
51   /**
52    * Copies features from the source to the sink and resolves overlaps: for each pair of overlapping features A and B
53    * it will produce:
54    *
55    * # a feature with geometry A - B with A's attributes
56    * # a feature with geometry B - A with B's attributes
57    * # two features with geometry intersection(A, B) - one with A's attributes, one with B's attributes.
58    *
59    * As a result, for all pairs of features in the output, a pair either has no common interior or their interior is the same.
60    */
61   void resolveOverlaps( const QgsFeatureSource &source, QgsFeatureSink &sink, QgsProcessingFeedback *feedback );
62 }
63 
64 ///@endcond PRIVATE
65 
66 #endif // QGSOVERLAYUTILS_H
67