@@ -56,7 +56,7 @@ QString GRASS_EXPORT QgsGrass::shortPath( const QString &path )
56
56
57
57
QString res = QString::fromUtf8 ( buf );
58
58
// GRASS wxpyton GUI fails on paths with backslash, Windows do support forward slashesin paths
59
- res.replace ( " \\ " , " /" );
59
+ res.replace ( " \\ " , " /" );
60
60
return res;
61
61
}
62
62
#endif
@@ -188,7 +188,7 @@ void GRASS_EXPORT QgsGrass::init( void )
188
188
}
189
189
190
190
QgsDebugMsg ( QString ( " Valid GRASS gisBase is: %1" ).arg ( gisBase ) );
191
- putEnv ( " GISBASE" , gisBase );
191
+ putEnv ( " GISBASE" , gisBase );
192
192
193
193
// Add path to GRASS modules
194
194
#ifdef WIN32
@@ -219,14 +219,14 @@ void GRASS_EXPORT QgsGrass::init( void )
219
219
path.append ( sep + p );
220
220
221
221
QgsDebugMsg ( QString ( " set PATH: %1" ).arg ( path ) );
222
- putEnv ( " PATH" , path );
222
+ putEnv ( " PATH" , path );
223
223
224
224
// Set PYTHONPATH
225
225
QString pythonpath = gisBase + " /etc/python" ;
226
- QString pp = getenv ( " PATH " );
226
+ QString pp = getenv ( " PYTHONPATH " );
227
227
pythonpath.append ( sep + pp );
228
228
QgsDebugMsg ( QString ( " set PYTHONPATH: %1" ).arg ( pythonpath ) );
229
- putEnv ( " PYTHONPATH" , pythonpath );
229
+ putEnv ( " PYTHONPATH" , pythonpath );
230
230
231
231
// Set GRASS_PAGER if not set, it is necessary for some
232
232
// modules printing to terminal, e.g. g.list
@@ -265,7 +265,7 @@ void GRASS_EXPORT QgsGrass::init( void )
265
265
266
266
if ( pager.length () > 0 )
267
267
{
268
- putEnv ( " GRASS_PAGER" , pager );
268
+ putEnv ( " GRASS_PAGER" , pager );
269
269
}
270
270
}
271
271
@@ -385,7 +385,7 @@ int QgsGrass::error_routine( char *msg, int fatal )
385
385
386
386
int QgsGrass::error_routine ( const char *msg, int fatal )
387
387
{
388
- // Unfortunately the exceptions thrown here can only be caught if GRASS libraries are compiled
388
+ // Unfortunately the exceptions thrown here can only be caught if GRASS libraries are compiled
389
389
// with -fexception option on Linux (works on Windows)
390
390
// GRASS developers are reluctant to add -fexception by default
391
391
// https://trac.osgeo.org/grass/ticket/869
@@ -543,7 +543,8 @@ QString GRASS_EXPORT QgsGrass::openMapset( QString gisdbase, QString location, Q
543
543
stream << line;
544
544
line = " MAPSET: " + mapset + " \n " ;
545
545
stream << line;
546
- if ( !guiSet ) {
546
+ if ( !guiSet )
547
+ {
547
548
stream << " GRASS_GUI: wxpython\n " ;
548
549
}
549
550
@@ -552,7 +553,7 @@ QString GRASS_EXPORT QgsGrass::openMapset( QString gisdbase, QString location, Q
552
553
// Set GISRC environment variable
553
554
554
555
/* _Correct_ putenv() implementation is not making copy! */
555
- putEnv ( " GISRC" , mGisrc );
556
+ putEnv ( " GISRC" , mGisrc );
556
557
557
558
// Reinitialize GRASS
558
559
G__setenv (( char * ) " GISRC" , mGisrc .toUtf8 ().data () );
@@ -1025,8 +1026,8 @@ bool GRASS_EXPORT QgsGrass::mapRegion( int type, QString gisbase,
1025
1026
return true ;
1026
1027
}
1027
1028
1028
- QByteArray GRASS_EXPORT QgsGrass::runModule ( QString gisdbase, QString location,
1029
- QString module, QStringList arguments )
1029
+ QByteArray GRASS_EXPORT QgsGrass::runModule ( QString gisdbase, QString location,
1030
+ QString module, QStringList arguments )
1030
1031
{
1031
1032
QgsDebugMsg ( QString ( " gisdbase = %1 location = %2" ).arg ( gisdbase ).arg ( location ) );
1032
1033
@@ -1036,142 +1037,147 @@ QByteArray GRASS_EXPORT QgsGrass::runModule( QString gisdbase, QString location
1036
1037
1037
1038
// We have to set GISRC file, uff
1038
1039
QTemporaryFile gisrcFile;
1039
- if ( !gisrcFile.open () )
1040
+ if ( !gisrcFile.open () )
1040
1041
{
1041
1042
// TODO Exception
1042
1043
return QByteArray ();
1043
1044
}
1044
-
1045
- QTextStream out (&gisrcFile);
1045
+
1046
+ QTextStream out ( &gisrcFile );
1046
1047
out << " GISDBASE: " << gisdbase << " \n " ;
1047
1048
out << " LOCATION_NAME: " << location << " \n " ;
1048
1049
out << " MAPSET: PERMANENT\n " ;
1049
- out.flush ();
1050
+ out.flush ();
1050
1051
QgsDebugMsg ( gisrcFile.fileName () );
1051
1052
1052
1053
QStringList environment = QProcess::systemEnvironment ();
1053
- environment.append (" GISRC=" + gisrcFile.fileName () );
1054
+ environment.append ( " GISRC=" + gisrcFile.fileName () );
1054
1055
1055
1056
QProcess process;
1056
1057
process.setEnvironment ( environment );
1057
1058
1058
- QgsDebugMsg ( module + " " + arguments.join ( " " ) );
1059
+ QgsDebugMsg ( module + " " + arguments.join ( " " ) );
1059
1060
process.start ( module, arguments );
1060
1061
if ( !process.waitForFinished ()
1061
1062
|| ( process.exitCode () != 0 && process.exitCode () != 255 ) )
1062
1063
{
1063
1064
QgsDebugMsg ( " process.exitCode() = " + QString::number ( process.exitCode () ) );
1064
- /*
1065
- QMessageBox::warning( 0, QObject::tr( "Warning" ),
1066
- QObject::tr( "Cannot start module" )
1067
- + QObject::tr( "<br>command: %1 %2<br>%3<br>%4" )
1068
- .arg( module ).arg( arguments.join( " " ) )
1069
- .arg( process.readAllStandardOutput().constData() )
1070
- .arg( process.readAllStandardError().constData() ) );
1071
- */
1065
+ /*
1066
+ QMessageBox::warning( 0, QObject::tr( "Warning" ),
1067
+ QObject::tr( "Cannot start module" )
1068
+ + QObject::tr( "<br>command: %1 %2<br>%3<br>%4" )
1069
+ .arg( module ).arg( arguments.join( " " ) )
1070
+ .arg( process.readAllStandardOutput().constData() )
1071
+ .arg( process.readAllStandardError().constData() ) );
1072
+ */
1072
1073
throw QgsGrass::Exception ( QObject::tr ( " Cannot start module" ) + " \n "
1073
- + QObject::tr ( " command: %1 %2<br>%3<br>%4" )
1074
- .arg ( module ).arg ( arguments.join ( " " ) )
1075
- .arg ( process.readAllStandardOutput ().constData () )
1076
- .arg ( process.readAllStandardError ().constData () ) );
1074
+ + QObject::tr ( " command: %1 %2<br>%3<br>%4" )
1075
+ .arg ( module ).arg ( arguments.join ( " " ) )
1076
+ .arg ( process.readAllStandardOutput ().constData () )
1077
+ .arg ( process.readAllStandardError ().constData () ) );
1077
1078
}
1078
1079
QByteArray data = process.readAllStandardOutput ();
1079
1080
1080
1081
return data;
1081
1082
}
1082
1083
1083
- QString GRASS_EXPORT QgsGrass::getInfo ( QString info, QString gisdbase, QString location,
1084
- QString mapset, QString map, MapType type, double x, double y)
1084
+ QString GRASS_EXPORT QgsGrass::getInfo ( QString info, QString gisdbase, QString location,
1085
+ QString mapset, QString map, MapType type, double x, double y )
1085
1086
{
1086
1087
QgsDebugMsg ( QString ( " gisdbase = %1 location = %2" ).arg ( gisdbase ).arg ( location ) );
1087
1088
1088
- QStringList arguments;
1089
+ QStringList arguments;
1089
1090
1090
1091
QString cmd = QgsApplication::pkgDataPath () + " /grass/modules/qgis.g.info" ;
1091
-
1092
+
1092
1093
arguments.append ( " info=" + info );
1093
- if ( !map.isNull () )
1094
- {
1095
- QString opt;
1096
- switch (type)
1097
- {
1098
- case Raster:
1099
- opt = " rast" ;
1100
- break ;
1101
- case Vector:
1102
- opt = " vect" ;
1103
- break ;
1104
- }
1105
- arguments.append ( opt + " =" + map + " @" + mapset );
1094
+ if ( !map.isNull () )
1095
+ {
1096
+ QString opt;
1097
+ switch ( type )
1098
+ {
1099
+ case Raster:
1100
+ opt = " rast" ;
1101
+ break ;
1102
+ case Vector:
1103
+ opt = " vect" ;
1104
+ break ;
1105
+ default :
1106
+ QgsDebugMsg ( " unexpected type:" + type );
1107
+ return " " ;
1108
+ }
1109
+ arguments.append ( opt + " =" + map + " @" + mapset );
1106
1110
}
1107
- if ( info == " query" )
1111
+ if ( info == " query" )
1108
1112
{
1109
- arguments.append ( QString (" coor=%1,%2" ).arg (x ).arg (y ) );
1113
+ arguments.append ( QString ( " coor=%1,%2" ).arg ( x ).arg ( y ) );
1110
1114
}
1111
-
1112
- QByteArray data = QgsGrass::runModule ( gisdbase, location, cmd, arguments );
1115
+
1116
+ QByteArray data = QgsGrass::runModule ( gisdbase, location, cmd, arguments );
1113
1117
QgsDebugMsg ( data );
1114
1118
return QString ( data );
1115
1119
}
1116
1120
1117
- QgsCoordinateReferenceSystem GRASS_EXPORT QgsGrass::crs ( QString gisdbase, QString location )
1121
+ QgsCoordinateReferenceSystem GRASS_EXPORT QgsGrass::crs ( QString gisdbase, QString location )
1118
1122
{
1119
1123
QgsDebugMsg ( QString ( " gisdbase = %1 location = %2" ).arg ( gisdbase ).arg ( location ) );
1120
1124
QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem ();
1121
- try
1125
+ try
1122
1126
{
1123
- QString wkt = QgsGrass::getInfo ( " proj" , gisdbase, location );
1127
+ QString wkt = QgsGrass::getInfo ( " proj" , gisdbase, location );
1124
1128
crs.createFromWkt ( wkt );
1125
1129
1126
- }
1130
+ }
1127
1131
catch ( QgsException &e )
1128
1132
{
1129
- QMessageBox::warning ( 0 , QObject::tr ( " Warning" ),
1130
- QObject::tr ( " Cannot get projection " ) + " \n " + e.what () );
1133
+ QMessageBox::warning ( 0 , QObject::tr ( " Warning" ),
1134
+ QObject::tr ( " Cannot get projection " ) + " \n " + e.what () );
1131
1135
}
1132
1136
1133
1137
return crs;
1134
1138
}
1135
1139
1136
- QgsRectangle GRASS_EXPORT QgsGrass::extent ( QString gisdbase, QString location, QString mapset, QString map, MapType type )
1140
+ QgsRectangle GRASS_EXPORT QgsGrass::extent ( QString gisdbase, QString location, QString mapset, QString map, MapType type )
1137
1141
{
1138
1142
QgsDebugMsg ( QString ( " gisdbase = %1 location = %2" ).arg ( gisdbase ).arg ( location ) );
1139
1143
1140
- try
1144
+ try
1141
1145
{
1142
- QString str = QgsGrass::getInfo ( " window" , gisdbase, location, mapset, map, type );
1143
- QStringList list = str.split (" ," );
1144
- if ( list.size () != 4 ) {
1146
+ QString str = QgsGrass::getInfo ( " window" , gisdbase, location, mapset, map, type );
1147
+ QStringList list = str.split ( " ," );
1148
+ if ( list.size () != 4 )
1149
+ {
1145
1150
throw QgsGrass::Exception ( " Cannot parse GRASS map extent: " + str );
1146
1151
}
1147
- return QgsRectangle ( list[0 ].toDouble (), list[1 ].toDouble (), list[2 ].toDouble (), list[3 ].toDouble () ) ;
1152
+ return QgsRectangle ( list[0 ].toDouble (), list[1 ].toDouble (), list[2 ].toDouble (), list[3 ].toDouble () ) ;
1148
1153
}
1149
1154
catch ( QgsException &e )
1150
1155
{
1151
- QMessageBox::warning ( 0 , QObject::tr ( " Warning" ),
1152
- QObject::tr ( " Cannot get raster extent" ) + " \n " + e.what () );
1156
+ QMessageBox::warning ( 0 , QObject::tr ( " Warning" ),
1157
+ QObject::tr ( " Cannot get raster extent" ) + " \n " + e.what () );
1153
1158
}
1154
1159
return QgsRectangle ( 0 , 0 , 0 , 0 );
1155
1160
}
1156
1161
1157
- QMap<QString, QString> GRASS_EXPORT QgsGrass::query ( QString gisdbase, QString location, QString mapset, QString map, MapType type, double x, double y )
1162
+ QMap<QString, QString> GRASS_EXPORT QgsGrass::query ( QString gisdbase, QString location, QString mapset, QString map, MapType type, double x, double y )
1158
1163
{
1159
1164
QgsDebugMsg ( QString ( " gisdbase = %1 location = %2" ).arg ( gisdbase ).arg ( location ) );
1160
1165
1161
1166
QMap<QString, QString> result;
1162
1167
// TODO: multiple values (more rows)
1163
- try
1168
+ try
1164
1169
{
1165
- QString str = QgsGrass::getInfo ( " query" , gisdbase, location, mapset, map, type, x, y );
1166
- QStringList list = str.trimmed ().split (" :" );
1167
- if ( list.size () == 2 ) {
1170
+ QString str = QgsGrass::getInfo ( " query" , gisdbase, location, mapset, map, type, x, y );
1171
+ QStringList list = str.trimmed ().split ( " :" );
1172
+ if ( list.size () == 2 )
1173
+ {
1168
1174
result[list[0 ]] = list[1 ];
1169
1175
}
1170
1176
}
1171
1177
catch ( QgsException &e )
1172
1178
{
1173
- QMessageBox::warning ( 0 , QObject::tr ( " Warning" ),
1174
- QObject::tr ( " Cannot query raster " ) + " \n " + e.what () );
1179
+ QMessageBox::warning ( 0 , QObject::tr ( " Warning" ),
1180
+ QObject::tr ( " Cannot query raster " ) + " \n " + e.what () );
1175
1181
}
1176
1182
return result;
1177
1183
}
@@ -1243,7 +1249,7 @@ QString GRASS_EXPORT QgsGrass::gisrcFilePath()
1243
1249
// Started from GRASS shell
1244
1250
if ( getenv ( " GISRC" ) )
1245
1251
{
1246
- return QString ( getenv ( " GISRC" ) );
1252
+ return QString ( getenv ( " GISRC" ) );
1247
1253
}
1248
1254
}
1249
1255
return mGisrc ;
0 commit comments