/
qgsgrass.h
176 lines (140 loc) · 6.54 KB
/
qgsgrass.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
/***************************************************************************
qgsgrass.h - Data provider for GRASS format
-------------------
begin : March, 2004
copyright : (C) 2004 by Radim Blazek
email : blazek@itc.it
***************************************************************************/
/***************************************************************************
* *
* 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 QGSGRASS_H
#define QGSGRASS_H
// GRASS header files
extern "C" {
#include <grass/gis.h>
#include <grass/form.h>
}
/*!
Methods for C library initialization and error handling.
*/
class QgsGrass {
public:
//! Get info about the mode
/*! QgsGrass may be running in active or passive mode.
* Active mode means that GISRC is set up and GISRC file is available,
* in that case default GISDBASE, LOCATION and MAPSET may be read by GetDefaul*() functions.
* Passive mode means, that GISRC is not available. */
static bool activeMode ( void );
//! Get default GISDBASE, returns GISDBASE name or empty string if not in active mode
static QString getDefaultGisdbase ( void );
//! Get default LOCATION_NAME, returns LOCATION_NAME name or empty string if not in active mode
static QString getDefaultLocation ( void );
//! Get default MAPSET, returns MAPSET name or empty string if not in active mode
static QString getDefaultMapset ( void );
//! Init or reset GRASS library
/*!
\param gisdbase full path to GRASS GISDBASE.
\param location location name (not path!).
*/
static void setLocation( QString gisdbase, QString location);
/*!
\param gisdbase full path to GRASS GISDBASE.
\param location location name (not path!).
\param mapset current mupset. Note that some variables depend on mapset and
may influence behaviour of some functions (e.g. search path etc.)
*/
static void setMapset( QString gisdbase, QString location, QString mapset);
//! Error codes returned by GetError()
enum GERROR { OK, /*!< OK. No error. */
WARNING, /*!< Warning, non fatal error. Should be printed by application. */
FATAL /*!< Fatal error. Function faild. */
};
//! Map type
enum MapType { Raster, Vector, Region };
//! Reset error code (to OK). Call this before a piece of code where an error is expected
static void resetError ( void ); // reset error status
//! Check if any error occured in lately called functions. Returns value from ERROR.
static int getError ( void );
//! Get last error message
static QString getErrorMessage ( void );
/** \brief Open existing GRASS mapset
* \return NULL string or error message
*/
static QString openMapset ( QString gisdbase,
QString location, QString mapset );
/** \brief Close mapset if it was opened from QGIS.
* Delete GISRC, lock and temporary directory
* \return NULL string or error message
*/
static QString closeMapset ();
//! Check if given directory contains a GRASS installation
static bool isValidGrassBaseDir(QString const gisBase);
//! Returns list of locations in given gisbase
static QStringList locations(QString gisbase);
//! Returns list of mapsets in location
static QStringList mapsets(QString gisbase, QString locationName);
static QStringList mapsets(QString locationPath);
//! List of vectors and rasters
static QStringList vectors(QString gisbase, QString locationName,
QString mapsetName);
static QStringList vectors(QString mapsetPath);
static QStringList rasters(QString gisbase, QString locationName,
QString mapsetName);
static QStringList rasters(QString mapsetPath);
//! List of elements
static QStringList elements(QString gisbase, QString locationName,
QString mapsetName, QString element);
static QStringList elements(QString mapsetPath, QString element);
// ! Get map region
static bool mapRegion( int type, QString gisbase,
QString location, QString mapset, QString map,
struct Cell_head *window );
// ! String representation of region
static QString regionString( struct Cell_head *window );
// ! Read current mapset region
static bool region( QString gisbase, QString location, QString mapset,
struct Cell_head *window );
// ! Write current mapset region
static bool writeRegion( QString gisbase, QString location, QString mapset,
struct Cell_head *window );
// ! Set (copy) region extent, resolution is not changed
static void copyRegionExtent( struct Cell_head *source,
struct Cell_head *target );
// ! Set (copy) region resolution, extent is not changed
static void copyRegionResolution( struct Cell_head *source,
struct Cell_head *target );
// ! Extend region in target to source
static void extendRegion( struct Cell_head *source,
struct Cell_head *target );
static void init (void);
// ! test if the directory is mapset
static bool isMapset ( QString path );
//! Library version
static int versionMajor();
static int versionMinor();
static int versionRelease();
static QString versionString();
private:
static int initialized; // Set to 1 after initialization
static bool active; // is active mode
static QString defaultGisdbase;
static QString defaultLocation;
static QString defaultMapset;
/* last error in GRASS libraries */
static GERROR error; // static, because used in constructor
static QString error_message;
static int error_routine ( char *msg, int fatal); // static because pointer to this function is set later
// Current mapset lock file path
static QString mMapsetLock;
// Current mapset GISRC file path
static QString mGisrc;
// Temporary directory where GISRC and sockets are stored
static QString mTmp;
};
#endif // QGSGRASS_H