QGIS API Documentation
4.3.0-Master (4ecdf0f3f59)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
raster
qgsrasternuller.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsrasternuller.cpp
3
---------------------
4
begin : August 2012
5
copyright : (C) 2012 by Radim Blazek
6
email : radim dot blazek at gmail dot com
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
15
* *
16
***************************************************************************/
17
18
#include "
qgsrasternuller.h
"
19
20
#include "
qgsrasterdataprovider.h
"
21
22
#include <QString>
23
24
using namespace
Qt::StringLiterals;
25
26
QgsRasterNuller::QgsRasterNuller
(
QgsRasterInterface
*
input
)
27
:
QgsRasterInterface
(
input
)
28
{}
29
30
QgsRasterNuller
*
QgsRasterNuller::clone
()
const
31
{
32
QgsDebugMsgLevel
( u
"Entered"
_s, 4 );
33
QgsRasterNuller
*nuller =
new
QgsRasterNuller
(
nullptr
);
34
nuller->mNoData = mNoData;
35
nuller->mOutputNoData = mOutputNoData;
36
nuller->mHasOutputNoData = mHasOutputNoData;
37
return
nuller;
38
}
39
40
void
QgsRasterNuller::setOutputNoDataValue
(
int
bandNo,
double
noData
)
41
{
42
if
( bandNo > mOutputNoData.size() )
43
{
44
mOutputNoData.resize( bandNo );
45
mHasOutputNoData.resize( bandNo );
46
}
47
mOutputNoData[bandNo - 1] =
noData
;
48
mHasOutputNoData[bandNo - 1] =
true
;
49
}
50
51
void
QgsRasterNuller::setNoData
(
int
bandNo,
const
QgsRasterRangeList
&
noData
)
52
{
53
if
( bandNo > mNoData.size() )
54
{
55
mNoData.resize( bandNo );
56
}
57
mNoData[bandNo - 1] =
noData
;
58
}
59
60
int
QgsRasterNuller::bandCount
()
const
61
{
62
if
(
mInput
)
63
return
mInput
->bandCount();
64
return
0;
65
}
66
67
Qgis::DataType
QgsRasterNuller::dataType
(
int
bandNo )
const
68
{
69
if
(
mInput
)
70
return
mInput
->dataType( bandNo );
71
return
Qgis::DataType::UnknownDataType
;
72
}
73
74
QgsRasterBlock
*
QgsRasterNuller::block
(
int
bandNo,
QgsRectangle
const
&
extent
,
int
width,
int
height,
QgsRasterBlockFeedback
*feedback )
75
{
76
QgsDebugMsgLevel
( u
"Entered"
_s, 4 );
77
if
( !
mInput
)
78
{
79
return
new
QgsRasterBlock
();
80
}
81
82
std::unique_ptr< QgsRasterBlock > inputBlock(
mInput
->block( bandNo,
extent
, width, height, feedback ) );
83
if
( !inputBlock )
84
{
85
return
new
QgsRasterBlock
();
86
}
87
88
// We don't support nuller for color types
89
if
(
QgsRasterBlock::typeIsColor
( inputBlock->dataType() ) )
90
{
91
return
inputBlock.release();
92
}
93
94
auto
outputBlock = std::make_unique<QgsRasterBlock>( inputBlock->dataType(), width, height );
95
if
( mHasOutputNoData.value( bandNo - 1 ) || inputBlock->hasNoDataValue() )
96
{
97
double
noDataValue;
98
if
( mHasOutputNoData.value( bandNo - 1 ) )
99
{
100
noDataValue = mOutputNoData.value( bandNo - 1 );
101
}
102
else
103
{
104
noDataValue = inputBlock->noDataValue();
105
}
106
outputBlock->setNoDataValue( noDataValue );
107
}
108
109
bool
isNoData =
false
;
110
for
(
int
i = 0; i < height; i++ )
111
{
112
for
(
int
j = 0; j < width; j++ )
113
{
114
const
double
value = inputBlock->valueAndNoData( i, j, isNoData );
115
116
if
(
QgsRasterRange::contains
( value, mNoData.value( bandNo - 1 ) ) )
117
{
118
isNoData =
true
;
119
}
120
if
( isNoData )
121
{
122
outputBlock->setIsNoData( i, j );
123
}
124
else
125
{
126
outputBlock->setValue( i, j, value );
127
}
128
}
129
}
130
return
outputBlock.release();
131
}
Qgis::DataType
DataType
Raster data types.
Definition
qgis.h:413
Qgis::DataType::UnknownDataType
@ UnknownDataType
Unknown or unspecified type.
Definition
qgis.h:414
QgsRasterBlockFeedback
Feedback object tailored for raster block reading.
Definition
qgsrasterinterface.h:45
QgsRasterBlock
Raster data container.
Definition
qgsrasterblock.h:42
QgsRasterBlock::typeIsColor
static bool typeIsColor(Qgis::DataType type)
Returns true if a data type is a color type.
Definition
qgsrasterblock.cpp:209
QgsRasterInterface::QgsRasterInterface
QgsRasterInterface(QgsRasterInterface *input=nullptr)
Definition
qgsrasterinterface.cpp:37
QgsRasterInterface::mInput
QgsRasterInterface * mInput
Definition
qgsrasterinterface.h:530
QgsRasterInterface::extent
virtual QgsRectangle extent() const
Gets the extent of the interface.
Definition
qgsrasterinterface.h:249
QgsRasterInterface::input
virtual QgsRasterInterface * input() const
Current input.
Definition
qgsrasterinterface.h:308
QgsRasterNuller::clone
QgsRasterNuller * clone() const override
Clone itself, create deep copy.
Definition
qgsrasternuller.cpp:30
QgsRasterNuller::setNoData
void setNoData(int bandNo, const QgsRasterRangeList &noData)
Definition
qgsrasternuller.cpp:51
QgsRasterNuller::dataType
Qgis::DataType dataType(int bandNo) const override
Returns data type for the band specified by number.
Definition
qgsrasternuller.cpp:67
QgsRasterNuller::block
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
Definition
qgsrasternuller.cpp:74
QgsRasterNuller::setOutputNoDataValue
void setOutputNoDataValue(int bandNo, double noData)
Sets the output no data value.
Definition
qgsrasternuller.cpp:40
QgsRasterNuller::QgsRasterNuller
QgsRasterNuller(QgsRasterInterface *input=nullptr)
Definition
qgsrasternuller.cpp:26
QgsRasterNuller::bandCount
int bandCount() const override
Gets number of bands.
Definition
qgsrasternuller.cpp:60
QgsRasterNuller::noData
QgsRasterRangeList noData(int bandNo) const
Definition
qgsrasternuller.h:53
QgsRasterRange::contains
bool contains(double value) const
Returns true if this range contains the specified value.
Definition
qgsrasterrange.h:114
QgsRectangle
A rectangle specified with double values.
Definition
qgsrectangle.h:47
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition
qgslogger.h:80
qgsrasterdataprovider.h
qgsrasternuller.h
QgsRasterRangeList
QList< QgsRasterRange > QgsRasterRangeList
Definition
qgsrasterrange.h:29
Generated on
for QGIS API Documentation by
1.17.0