QGIS API Documentation
2.2.0-Valmiera
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
src
core
qgsfeatureiterator.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsfeatureiterator.cpp
3
---------------------
4
begin : Juli 2012
5
copyright : (C) 2012 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
#include "
qgsfeatureiterator.h
"
16
#include "
qgslogger.h
"
17
18
#include "
qgsgeometrysimplifier.h
"
19
#include "
qgssimplifymethod.h
"
20
21
QgsAbstractFeatureIterator::QgsAbstractFeatureIterator
(
const
QgsFeatureRequest
& request )
22
: mRequest( request )
23
, mClosed( false )
24
, refs( 0 )
25
, mGeometrySimplifier( NULL )
26
, mLocalSimplification( false )
27
{
28
}
29
30
QgsAbstractFeatureIterator::~QgsAbstractFeatureIterator
()
31
{
32
delete
mGeometrySimplifier
;
33
mGeometrySimplifier
= NULL;
34
}
35
36
bool
QgsAbstractFeatureIterator::nextFeature
(
QgsFeature
& f )
37
{
38
bool
dataOk =
false
;
39
40
switch
(
mRequest
.
filterType
() )
41
{
42
case
QgsFeatureRequest::FilterExpression
:
43
dataOk =
nextFeatureFilterExpression
( f );
44
break
;
45
46
case
QgsFeatureRequest::FilterFids
:
47
dataOk =
nextFeatureFilterFids
( f );
48
break
;
49
50
default
:
51
dataOk =
fetchFeature
( f );
52
break
;
53
}
54
55
// simplify the geometry using the simplifier configured
56
if
( dataOk &&
mLocalSimplification
)
57
{
58
QgsGeometry
* geometry = f.
geometry
();
59
if
( geometry )
simplify
( f );
60
}
61
return
dataOk;
62
}
63
64
bool
QgsAbstractFeatureIterator::nextFeatureFilterExpression
(
QgsFeature
& f )
65
{
66
while
(
fetchFeature
( f ) )
67
{
68
if
(
mRequest
.
filterExpression
()->
evaluate
( f ).toBool() )
69
return
true
;
70
}
71
return
false
;
72
}
73
74
bool
QgsAbstractFeatureIterator::nextFeatureFilterFids
(
QgsFeature
& f )
75
{
76
while
(
fetchFeature
( f ) )
77
{
78
if
(
mRequest
.
filterFids
().contains( f.
id
() ) )
79
return
true
;
80
}
81
return
false
;
82
}
83
84
void
QgsAbstractFeatureIterator::ref
()
85
{
86
// Prepare if required the simplification of geometries to fetch:
87
// This code runs here because of 'prepareSimplification()' is virtual and it can be overrided
88
// in inherited iterators who change the default behavior.
89
// It would be better to call this method in the constructor enabling virtual-calls as it is described by example at:
90
// http://www.parashift.com/c%2B%2B-faq-lite/calling-virtuals-from-ctor-idiom.html
91
if
(
refs
== 0 )
92
{
93
prepareSimplification
(
mRequest
.
simplifyMethod
() );
94
}
95
refs
++;
96
}
97
98
void
QgsAbstractFeatureIterator::deref
()
99
{
100
refs
--;
101
if
( !
refs
)
102
delete
this
;
103
}
104
105
bool
QgsAbstractFeatureIterator::prepareSimplification
(
const
QgsSimplifyMethod
& simplifyMethod )
106
{
107
mLocalSimplification
=
false
;
108
109
delete
mGeometrySimplifier
;
110
mGeometrySimplifier
= NULL;
111
112
// setup the simplification of geometries to fetch
113
if
( !(
mRequest
.
flags
() &
QgsFeatureRequest::NoGeometry
) && simplifyMethod.
methodType
() !=
QgsSimplifyMethod::NoSimplification
&& ( simplifyMethod.
forceLocalOptimization
() || !
providerCanSimplify
( simplifyMethod.
methodType
() ) ) )
114
{
115
mGeometrySimplifier
=
QgsSimplifyMethod::createGeometrySimplifier
( simplifyMethod );
116
mLocalSimplification
=
mGeometrySimplifier
!= NULL;
117
return
mLocalSimplification
;
118
}
119
return
false
;
120
}
121
122
bool
QgsAbstractFeatureIterator::providerCanSimplify
(
QgsSimplifyMethod::MethodType
methodType )
const
123
{
124
Q_UNUSED( methodType )
125
return
false
;
126
}
127
128
bool
QgsAbstractFeatureIterator::simplify
(
QgsFeature
& feature )
129
{
130
// simplify locally the geometry using the configured simplifier
131
if
(
mGeometrySimplifier
)
132
{
133
QgsGeometry
* geometry = feature.
geometry
();
134
135
QGis::GeometryType
geometryType = geometry->
type
();
136
if
( geometryType ==
QGis::Line
|| geometryType ==
QGis::Polygon
)
return
mGeometrySimplifier
->
simplifyGeometry
( geometry );
137
}
138
return
false
;
139
}
140
142
143
QgsFeatureIterator
&
QgsFeatureIterator::operator=
(
const
QgsFeatureIterator
& other )
144
{
145
if
(
this
!= &other )
146
{
147
if
(
mIter
)
148
mIter
->
deref
();
149
mIter
= other.
mIter
;
150
if
(
mIter
)
151
mIter
->
ref
();
152
}
153
return
*
this
;
154
}
Generated on Sun Feb 23 2014 14:27:19 for QGIS API Documentation by
1.8.1.2