-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsgrassrasterprovider.h
266 lines (205 loc) · 8.25 KB
/
qgsgrassrasterprovider.h
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
/***************************************************************************
qgsgrassrasterprovider.h - QGIS Data provider for
GRASS rasters
-------------------
begin : 16 Jan, 2010
copyright : (C) 2010 by Radim Blazek
email : radim dot blazek at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSGRASSRASTERPROVIDER_H
#define QGSGRASSRASTERPROVIDER_H
extern "C"
{
#include <grass/gis.h>
}
#include "qgscoordinatereferencesystem.h"
#include "qgsrasterdataprovider.h"
#include "qgsrectangle.h"
#include "qgscolorrampshader.h"
#include <QString>
#include <QStringList>
#include <QDomElement>
#include <QMap>
#include <QVector>
#include <QTemporaryFile>
#include <QProcess>
#include <QHash>
class QgsCoordinateTransform;
/**
\brief Read raster value for given coordinates
Executes qgis.g.info and keeps it open comunicating through pipe. Restarts the command if raster was updated.
*/
class QgsGrassRasterValue
{
public:
QgsGrassRasterValue( );
~QgsGrassRasterValue();
void start( QString gisdbase, QString location, QString mapset, QString map );
// returns raster value as string or "null" or "error"
QString value( double x, double y );
private:
QString mGisdbase; // map gisdabase
QString mLocation; // map location name (not path!)
QString mMapset; // map mapset
QString mMapName; // map name
QTemporaryFile mGisrcFile;
QProcess *mProcess;
};
/**
\brief Data provider for GRASS raster layers.
This provider implements the
interface defined in the QgsDataProvider class to provide access to spatial
data residing in a OGC Web Map Service.
*/
class QgsGrassRasterProvider : public QgsRasterDataProvider
{
Q_OBJECT
public:
/**
* Constructor for the provider.
*
* \param uri HTTP URL of the Web Server. If needed a proxy will be used
* otherwise we contact the host directly.
*
*/
QgsGrassRasterProvider( QString const & uri = 0 );
//! Destructor
~QgsGrassRasterProvider();
QgsRasterInterface * clone() const;
/** \brief Renders the layer as an image
*/
QImage* draw( QgsRectangle const & viewExtent, int pixelWidth, int pixelHeight );
/** return a provider name
Essentially just returns the provider key. Should be used to build file
dialogs so that providers can be shown with their supported types. Thus
if more than one provider supports a given format, the user is able to
select a specific provider to open that file.
@note
Instead of being pure virtual, might be better to generalize this
behavior and presume that none of the sub-classes are going to do
anything strange with regards to their name or description?
*/
QString name() const;
/** return description
Return a terse string describing what the provider is.
@note
Instead of being pure virtual, might be better to generalize this
behavior and presume that none of the sub-classes are going to do
anything strange with regards to their name or description?
*/
QString description() const;
/*! Get the QgsCoordinateReferenceSystem for this layer
* @note Must be reimplemented by each provider.
* If the provider isn't capable of returning
* its projection an empty srs will be return, ti will return 0
*/
virtual QgsCoordinateReferenceSystem crs();
/** Return the extent for this data layer
*/
virtual QgsRectangle extent();
/**Returns true if layer is valid
*/
bool isValid();
/** \brief Identify raster value(s) found on the point position */
//bool identify( const QgsPoint & point, QMap<QString, QString>& results );
QMap<int, void *> identify( const QgsPoint & thePoint );
/**
* \brief Identify details from a GRASS layer from the last screen update
*
* \param point[in] The pixel coordinate (as it was displayed locally on screen)
*
* \return A text document containing the return from the GRASS layer
*/
QString identifyAsText( const QgsPoint& point );
/**
* \brief Identify details from a GRASS layer from the last screen update
*
* \param point[in] The pixel coordinate (as it was displayed locally on screen)
*
* \return A text document containing the return from the GRASS layer
*
* \note added in 1.5
*/
QString identifyAsHtml( const QgsPoint& point );
/**
* \brief Returns the caption error text for the last error in this provider
*
* If an operation returns 0 (e.g. draw()), this function
* returns the text of the error associated with the failure.
* Interactive users of this provider can then, for example,
* call a QMessageBox to display the contents.
*/
QString lastErrorTitle();
/**
* \brief Returns the verbose error text for the last error in this provider
*
* If an operation returns 0 (e.g. draw()), this function
* returns the text of the error associated with the failure.
* Interactive users of this provider can then, for example,
* call a QMessageBox to display the contents.
*/
QString lastError();
/** Returns a bitmask containing the supported capabilities
Note, some capabilities may change depending on which
sublayers are visible on this provider, so it may
be prudent to check this value per intended operation.
*/
int capabilities() const;
QgsRasterInterface::DataType dataType( int bandNo ) const;
QgsRasterInterface::DataType srcDataType( int bandNo ) const;
int bandCount() const;
int colorInterpretation( int bandNo ) const;
int xBlockSize() const;
int yBlockSize() const;
int xSize() const;
int ySize() const;
void readBlock( int bandNo, int xBlock, int yBlock, void *data );
void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data );
double noDataValue() const;
double minimumValue( int bandNo )const;
double maximumValue( int bandNo )const;
QgsRasterBandStats bandStatistics( int theBandNo );
QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo )const;
// void buildSupportedRasterFileFilter( QString & theFileFiltersString );
/**
* Get metadata in a format suitable for feeding directly
* into a subset of the GUI raster properties "Metadata" tab.
*/
QString metadata();
// Following methods specific for are not used at all in this provider and should be removed IMO from qgsdataprovider.h
void addLayers( QStringList const &layers, QStringList const &styles = QStringList() )
{ Q_UNUSED( layers ); Q_UNUSED( styles ); }
QStringList supportedImageEncodings() { return QStringList();}
QString imageEncoding() const { return QString(); }
void setImageEncoding( QString const &mimeType )
{ Q_UNUSED( mimeType ); }
void setImageCrs( QString const &crs )
{ Q_UNUSED( crs ); }
virtual QDateTime dataTimestamp() const;
private:
/**
* Flag indicating if the layer data source is a valid layer
*/
bool mValid;
QString mGisdbase; // map gisdabase
QString mLocation; // map location name (not path!)
QString mMapset; // map mapset
QString mMapName; // map name
RASTER_MAP_TYPE mGrassDataType; // CELL_TYPE, DCELL_TYPE, FCELL_TYPE
int mCols;
int mRows;
int mYBlockSize;
QHash<QString, QString> mInfo;
QgsCoordinateReferenceSystem mCrs;
QgsGrassRasterValue mRasterValue;
double mNoDataValue;
};
#endif