/
qgsrasterlayer.sip.in
420 lines (293 loc) · 14.9 KB
/
qgsrasterlayer.sip.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/raster/qgsrasterlayer.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
typedef QList < QPair< QString, QColor > > QgsLegendColorList;
class QgsRasterLayer : QgsMapLayer
{
%Docstring
This class provides qgis with the ability to render raster datasets
onto the mapcanvas.
The qgsrasterlayer class makes use of gdal for data io, and thus supports
any gdal supported format. The constructor attempts to infer what type of
file (LayerType) is being opened - not in terms of the file format (tif, ascii grid etc.)
but rather in terms of whether the image is a GRAYSCALE, PaletteD or Multiband,
Within the three allowable raster layer types, there are 8 permutations of
how a layer can actually be rendered. These are defined in the DrawingStyle enum
and consist of:
SingleBandGray -> a GRAYSCALE layer drawn as a range of gray colors (0-255)
SingleBandPseudoColor -> a GRAYSCALE layer drawn using a pseudocolor algorithm
PalettedSingleBandGray -> a PaletteD layer drawn in gray scale (using only one of the color components)
PalettedSingleBandPseudoColor -> a PaletteD layer having only one of its color components rendered as pseudo color
PalettedMultiBandColor -> a PaletteD image where the bands contains 24bit color info and 8 bits is pulled out per color
MultiBandSingleBandGray -> a layer containing 2 or more bands, but using only one band to produce a grayscale image
MultiBandSingleBandPseudoColor -> a layer containing 2 or more bands, but using only one band to produce a pseudocolor image
MultiBandColor -> a layer containing 2 or more bands, mapped to the three RGBcolors. In the case of a multiband with only two bands, one band will have to be mapped to more than one color
Each of the above mentioned drawing styles is implemented in its own draw* function.
Some of the drawing styles listed above require statistics about the layer such
as the min / max / mean / stddev etc. statistics for a band can be gathered using the
bandStatistics function. Note that statistics gathering is a slow process and
every effort should be made to call this function as few times as possible. For this
reason, qgsraster has a vector class member to store stats for each band. The
constructor initializes this vector on startup, but only populates the band name and
number fields.
Note that where bands are of gdal 'undefined' type, their values may exceed the
renderable range of 0-255. Because of this a linear scaling histogram enhanceContrast is
applied to undefined layers to normalise the data into the 0-255 range.
A qgsrasterlayer band can be referred to either by name or by number (base=1). It
should be noted that band names as stored in datafiles may not be unique, and
so the rasterlayer class appends the band number in brackets behind each band name.
Sample usage of the QgsRasterLayer class:
In order to automate redrawing of a raster layer, you should link it to a map canvas like this :
Once a layer has been created you can find out what type of layer it is (GrayOrUndefined, Palette or Multiband):
Raster layers can also have an arbitrary level of transparency defined, and have their
color palettes inverted using the setTransparency and setInvertHistogram methods.
Pseudocolor images can have their output adjusted to a given number of standard
deviations using the setStandardDeviations method.
The final area of functionality you may be interested in is band mapping. Band mapping
allows you to choose arbitrary band -> color mappings and is applicable only to Palette
and Multiband rasters, There are four mappings that can be made: red, green, blue and gray.
Mappings are non-exclusive. That is a given band can be assigned to no, some or all
color mappings. The constructor sets sensible defaults for band mappings but these can be
overridden at run time using the setRedBandName, setGreenBandName, setBlueBandName and setGrayBandName
methods.
%End
%TypeHeaderCode
#include "qgsrasterlayer.h"
%End
public:
static const double SAMPLE_SIZE;
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm SINGLE_BAND_ENHANCEMENT_ALGORITHM;
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_SINGLE_BYTE_ENHANCEMENT_ALGORITHM;
static const QgsContrastEnhancement::ContrastEnhancementAlgorithm MULTIPLE_BAND_MULTI_BYTE_ENHANCEMENT_ALGORITHM;
static const QgsRasterMinMaxOrigin::Limits SINGLE_BAND_MIN_MAX_LIMITS;
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_SINGLE_BYTE_MIN_MAX_LIMITS;
static const QgsRasterMinMaxOrigin::Limits MULTIPLE_BAND_MULTI_BYTE_MIN_MAX_LIMITS;
QgsRasterLayer();
%Docstring
Constructor. Provider is not set.
%End
struct LayerOptions
{
explicit LayerOptions( bool loadDefaultStyle = true,
const QgsCoordinateTransformContext &transformContext = QgsCoordinateTransformContext() );
%Docstring
Constructor for LayerOptions.
%End
bool loadDefaultStyle;
QgsCoordinateTransformContext transformContext;
};
explicit QgsRasterLayer( const QString &uri,
const QString &baseName = QString(),
const QString &providerType = "gdal",
const QgsRasterLayer::LayerOptions &options = QgsRasterLayer::LayerOptions() );
%Docstring
This is the constructor for the RasterLayer class.
The main tasks carried out by the constructor are:
-Load the rasters default style (.qml) file if it exists
-Populate the RasterStatsVector with initial values for each band.
-Calculate the layer extents
-Determine whether the layer is gray, paletted or multiband.
-Assign sensible defaults for the red, green, blue and gray bands.
%End
~QgsRasterLayer();
virtual QgsRasterLayer *clone() const /Factory/;
%Docstring
Returns a new instance equivalent to this one. A new provider is
created for the same data source and renderer is cloned too.
:return: a new layer instance
.. versionadded:: 3.0
%End
enum ColorShadingAlgorithm
{
UndefinedShader,
PseudoColorShader,
FreakOutShader,
ColorRampShader,
UserDefinedShader
};
enum LayerType
{
GrayOrUndefined,
Palette,
Multiband,
ColorLayer
};
static bool isValidRasterFileName( const QString &fileNameQString, QString &retError );
%Docstring
This helper checks to see whether the file name appears to be a valid
raster file name. If the file name looks like it could be valid,
but some sort of error occurs in processing the file, the error is
returned in ``retError``.
%End
static bool isValidRasterFileName( const QString &fileNameQString );
static QDateTime lastModified( const QString &name );
%Docstring
Returns time stamp for given file name
%End
void setDataProvider( const QString &provider ) /Deprecated/;
%Docstring
Set the data provider.
.. deprecated:: Use the version with ProviderOptions instead.
%End
void setDataProvider( const QString &provider, const QgsDataProvider::ProviderOptions &options );
%Docstring
Set the data provider.
:param provider: provider key string, must match a valid QgsRasterDataProvider key. E.g. "gdal", "wms", etc.
:param options: provider options
.. versionadded:: 3.2
%End
virtual void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
%Docstring
Updates the data source of the layer. The layer's renderer and legend will be preserved only
if the geometry type of the new data source matches the current geometry type of the layer.
:param dataSource: new layer data source
:param baseName: base name of the layer
:param provider: provider string
:param options: provider options
:param loadDefaultStyleFlag: set to ``True`` to reset the layer's style to the default for the
data source
.. seealso:: :py:func:`dataSourceChanged`
.. versionadded:: 3.6
%End
LayerType rasterType();
%Docstring
Returns the raster layer type (which is a read only property).
%End
void setRenderer( QgsRasterRenderer *renderer /Transfer/ );
%Docstring
Sets raster renderer. Takes ownership of the renderer object
%End
QgsRasterRenderer *renderer() const;
QgsRasterResampleFilter *resampleFilter() const;
%Docstring
Sets raster resample filter. Takes ownership of the resample filter object
%End
QgsBrightnessContrastFilter *brightnessFilter() const;
QgsHueSaturationFilter *hueSaturationFilter() const;
QgsRasterPipe *pipe();
%Docstring
Returns the raster pipe.
%End
int width() const;
%Docstring
Returns the width of the (unclipped) raster.
.. seealso:: :py:func:`height`
%End
int height() const;
%Docstring
Returns the height of the (unclipped) raster.
.. seealso:: :py:func:`width`
%End
int bandCount() const;
%Docstring
Returns the number of bands in this layer.
%End
QString bandName( int bandNoInt ) const;
%Docstring
Returns the name of a band given its number.
%End
virtual QgsRasterDataProvider *dataProvider();
virtual const QgsRasterDataProvider *dataProvider() const /PyName=constDataProvider/;
virtual void reload();
virtual QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) /Factory/;
void draw( QPainter *theQPainter,
QgsRasterViewPort *myRasterViewPort,
const QgsMapToPixel *qgsMapToPixel = 0 );
%Docstring
This is an overloaded version of the draw() function that is called by both draw() and thumbnailAsPixmap
%End
QgsLegendColorList legendSymbologyItems() const;
%Docstring
Returns a list with classification items (Text and color)
%End
virtual bool isSpatial() const;
virtual QString htmlMetadata() const;
QPixmap paletteAsPixmap( int bandNumber = 1 );
%Docstring
Returns a 100x100 pixmap of the color palette. If the layer has no palette a white pixmap will be returned
:param bandNumber: the number of the band to use for generating a pixmap of the associated palette
%End
QString providerType() const;
%Docstring
[ data provider interface ] Which provider is being used for this Raster Layer?
%End
double rasterUnitsPerPixelX() const;
%Docstring
Returns the number of raster units per each raster pixel in X axis.
In a world file, this is normally the first row (without the sign). (E.g.
the value reported by the GDAL geotransform[1]).
.. seealso:: :py:func:`rasterUnitsPerPixelY`
%End
double rasterUnitsPerPixelY() const;
%Docstring
Returns the number of raster units per each raster pixel in Y axis.
In a world file, this is normally the first row (without the sign).
.. seealso:: :py:func:`rasterUnitsPerPixelX`
%End
void setContrastEnhancement( QgsContrastEnhancement::ContrastEnhancementAlgorithm algorithm,
QgsRasterMinMaxOrigin::Limits limits = QgsRasterMinMaxOrigin::MinMax,
const QgsRectangle &extent = QgsRectangle(),
int sampleSize = QgsRasterLayer::SAMPLE_SIZE,
bool generateLookupTableFlag = true );
%Docstring
Set contrast enhancement algorithm
:param algorithm: Contrast enhancement algorithm
:param limits: Limits
:param extent: Extent used to calculate limits, if empty, use full layer extent
:param sampleSize: Size of data sample to calculate limits, if 0, use full resolution
:param generateLookupTableFlag: Generate lookup table. *
%End
void setDefaultContrastEnhancement();
%Docstring
Sets the default contrast enhancement
%End
virtual QStringList subLayers() const;
QImage previewAsImage( QSize size, const QColor &bgColor = Qt::white,
QImage::Format format = QImage::Format_ARGB32_Premultiplied );
%Docstring
Draws a preview of the rasterlayer into a QImage
.. versionadded:: 2.4
%End
virtual void setLayerOrder( const QStringList &layers );
virtual void setSubLayerVisibility( const QString &name, bool vis );
virtual QDateTime timestamp() const;
bool writeSld( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsStringMap &props = QgsStringMap() ) const;
%Docstring
Writes the symbology of the layer into the document provided in SLD 1.0.0 format
:param node: the node that will have the style element added to it.
:param doc: the document that will have the QDomNode added.
:param errorMessage: reference to string that will be updated with any error messages
:param props: a open ended set of properties that can drive/inform the SLD encoding
:return: ``True`` in case of success
.. versionadded:: 3.6
%End
public slots:
void showStatusMessage( const QString &message );
virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext );
%Docstring
Triggered when the coordinate transform context has changed ``transformContext``
.. versionadded:: 3.10
%End
protected:
virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
virtual bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
virtual bool writeSymbology( QDomNode &, QDomDocument &doc, QString &errorMessage,
const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const;
virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const;
virtual bool writeXml( QDomNode &layer_node, QDomDocument &doc, const QgsReadWriteContext &context ) const;
virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
virtual QString decodedSource( const QString &source, const QString &provider, const QgsReadWriteContext &context ) const;
};
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/raster/qgsrasterlayer.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/