@@ -85,12 +85,34 @@ QgsGrassGisLib GRASS_LIB_EXPORT *QgsGrassGisLib::instance( )
85
85
QgsGrassGisLib::QgsGrassGisLib ()
86
86
{
87
87
// Load original GRASS library
88
+
89
+ // GRASS_LIBRARY_GIS (cmake GRASS_LIBRARY_gis) is a path to the GRASS library
90
+ // in the time of compilation, it may be used on runtime (it is the same)
91
+ // on Linux and Mac but on Windows with OSGEO4W the GRASS may be installed
92
+ // in a different directory. qgis.env however calls GRASS etc/env.bat
93
+ // which sets GISBASE and GRASS_LIBRARY_GIS on Windows is path to .lib, e.g
94
+ // grass_gis.lib. Name of the DLL on Windows is e.g.: libgrass_gis6.4.3RC1.dll
95
+
96
+ QString gisBase = getenv ( " GISBASE" );
97
+ #ifdef Q_OS_WIN
98
+ if ( gisBase.isEmpty () )
99
+ {
100
+ fatal ( " GISBASE environment variable not set" );
101
+ }
102
+ QString libPath = gisBase + " /lib/libgrass_gis" + QString ( GRASS_VERSION ) + " .dll" ;
103
+ #else
88
104
QString libPath = QString ( GRASS_LIBRARY_GIS );
105
+ // Prefere GISBASE if set
106
+ if ( !gisBase.isEmpty () )
107
+ {
108
+ libPath = gisBase + " /lib/" + QFileInfo ( libPath ).fileName ();
109
+ }
110
+ #endif
89
111
QgsDebugMsg ( " libPath = " + libPath );
90
112
mLibrary .setFileName ( libPath );
91
113
if ( !mLibrary .load () )
92
114
{
93
- QgsDebugMsg ( " Cannot load original GRASS library" );
115
+ fatal ( " Cannot load true GRASS library, path: " + libPath );
94
116
return ;
95
117
}
96
118
}
@@ -116,11 +138,11 @@ void QgsGrassGisLib::warning( QString msg )
116
138
117
139
void * QgsGrassGisLib::resolve ( const char * symbol )
118
140
{
119
- // QgsDebugMsg( QString("symbol = %1").arg(symbol) );
141
+ QgsDebugMsg ( QString ( " symbol = %1" ).arg ( symbol ) );
120
142
void * fn = mLibrary .resolve ( symbol );
121
143
if ( !fn )
122
144
{
123
- QgsDebugMsg ( " Cannot resolve symbol" );
145
+ fatal ( " Cannot resolve symbol " + QString ( symbol ) );
124
146
}
125
147
return fn;
126
148
}
@@ -178,6 +200,9 @@ int GRASS_LIB_EXPORT QgsGrassGisLib::G__gisinit( const char * version, const cha
178
200
// Read projection if set
179
201
// mCrs.createFromOgcWmsCrs( "EPSG:900913" );
180
202
QString crsStr = getenv ( " QGIS_GRASS_CRS" );
203
+
204
+ QgsDebugMsg ( " Setting CRS to " + crsStr );
205
+
181
206
if ( !crsStr.isEmpty () )
182
207
{
183
208
if ( !mCrs .createFromProj4 ( crsStr ) )
@@ -228,6 +253,13 @@ int GRASS_LIB_EXPORT QgsGrassGisLib::G__gisinit( const char * version, const cha
228
253
G_set_window( &window );
229
254
#endif
230
255
256
+ QString regionStr = getenv ( " GRASS_REGION" );
257
+ if ( regionStr.isEmpty () )
258
+ {
259
+ fatal ( " GRASS_REGION environment variable not set" );
260
+ }
261
+
262
+ QgsDebugMsg ( " Getting region via true lib from GRASS_REGION: " + regionStr );
231
263
// GRASS true lib reads GRASS_REGION environment variable
232
264
G_get_window ( &mWindow );
233
265
@@ -237,6 +269,7 @@ int GRASS_LIB_EXPORT QgsGrassGisLib::G__gisinit( const char * version, const cha
237
269
mXRes = mExtent .width () / mColumns ;
238
270
mYRes = mExtent .height () / mColumns ;
239
271
272
+ QgsDebugMsg ( " End" );
240
273
return 0 ;
241
274
}
242
275
@@ -569,6 +602,11 @@ int GRASS_LIB_EXPORT G_open_cell_new( const char *name )
569
602
return QgsGrassGisLib::instance ()->G_open_raster_new ( name, CELL_TYPE );
570
603
}
571
604
605
+ int GRASS_LIB_EXPORT G_open_fp_cell_new ( const char *name )
606
+ {
607
+ return QgsGrassGisLib::instance ()->G_open_raster_new ( name, FCELL_TYPE );
608
+ }
609
+
572
610
RASTER_MAP_TYPE QgsGrassGisLib::G_raster_map_type ( const char *name, const char *mapset )
573
611
{
574
612
Q_UNUSED ( mapset );
@@ -1043,6 +1081,44 @@ int GRASS_LIB_EXPORT G_legal_filename( const char *s )
1043
1081
return 1 ;
1044
1082
}
1045
1083
1084
+ int QgsGrassGisLib::G_set_geodesic_distance_lat1 ( double lat1 )
1085
+ {
1086
+ mLat1 = lat1;
1087
+ return 0 ;
1088
+ }
1089
+
1090
+ int QgsGrassGisLib::G_set_geodesic_distance_lat2 ( double lat2 )
1091
+ {
1092
+ mLat2 = lat2;
1093
+ return 0 ;
1094
+ }
1095
+
1096
+ int GRASS_LIB_EXPORT G_set_geodesic_distance_lat1 ( double lat1 )
1097
+ {
1098
+ return QgsGrassGisLib::instance ()->G_set_geodesic_distance_lat1 ( lat1 );
1099
+ }
1100
+
1101
+ int GRASS_LIB_EXPORT G_set_geodesic_distance_lat2 ( double lat2 )
1102
+ {
1103
+ return QgsGrassGisLib::instance ()->G_set_geodesic_distance_lat2 ( lat2 );
1104
+ }
1105
+
1106
+ double QgsGrassGisLib::G_geodesic_distance_lon_to_lon ( double lon1, double lon2 )
1107
+ {
1108
+ double dist = mDistanceArea .measureLine ( QgsPoint ( lon1, mLat1 ), QgsPoint ( lon2, mLat2 ) );
1109
+ // TODO: not sure about this
1110
+ if ( !mCrs .geographicFlag () )
1111
+ {
1112
+ dist *= G_database_units_to_meters_factor ();
1113
+ }
1114
+ return dist;
1115
+ }
1116
+
1117
+ double GRASS_LIB_EXPORT G_geodesic_distance_lon_to_lon ( double lon1, double lon2 )
1118
+ {
1119
+ return QgsGrassGisLib::instance ()->G_geodesic_distance_lon_to_lon ( lon1, lon2 );
1120
+ }
1121
+
1046
1122
QgsRasterBlock::DataType QgsGrassGisLib::qgisRasterType ( RASTER_MAP_TYPE grassType )
1047
1123
{
1048
1124
switch ( grassType )
@@ -1149,6 +1225,14 @@ int GRASS_LIB_EXPORT G_quantize_fp_map_range( const char *name, const char *maps
1149
1225
return 1 ;
1150
1226
}
1151
1227
1228
+ int GRASS_LIB_EXPORT G_read_cats ( const char *name, const char *mapset, struct Categories *pcats )
1229
+ {
1230
+ Q_UNUSED ( name );
1231
+ Q_UNUSED ( mapset );
1232
+ G_init_raster_cats ( " Cats" , pcats );
1233
+ return 0 ;
1234
+ }
1235
+
1152
1236
int GRASS_LIB_EXPORT G_read_raster_cats ( const char *name, const char *mapset, struct Categories *pcats )
1153
1237
{
1154
1238
Q_UNUSED ( name );
@@ -1221,15 +1305,36 @@ int GRASS_LIB_EXPORT G_make_aspect_fp_colors( struct Colors *colors, DCELL min,
1221
1305
return 1 ; // OK
1222
1306
}
1223
1307
1224
- int G_check_overwrite ( int argc, char **argv )
1308
+ int GRASS_LIB_EXPORT G_check_overwrite ( int argc, char **argv )
1225
1309
{
1226
1310
Q_UNUSED ( argc );
1227
1311
Q_UNUSED ( argv );
1228
1312
return 1 ; // overwrite
1229
1313
}
1230
1314
1231
- char *G_fully_qualified_name ( const char *name, const char *mapset )
1315
+ char GRASS_LIB_EXPORT *G_fully_qualified_name ( const char *name, const char *mapset )
1232
1316
{
1233
1317
Q_UNUSED ( mapset );
1234
1318
return G_store ( name );
1235
1319
}
1320
+
1321
+ char GRASS_LIB_EXPORT *G_ask_cell_new ( const char *prompt, char *name )
1322
+ {
1323
+ Q_UNUSED ( prompt );
1324
+ Q_UNUSED ( name );
1325
+ return NULL ;
1326
+ }
1327
+
1328
+ char GRASS_LIB_EXPORT *G_ask_cell_old ( const char *prompt, char *name )
1329
+ {
1330
+ Q_UNUSED ( prompt );
1331
+ Q_UNUSED ( name );
1332
+ return NULL ;
1333
+ }
1334
+
1335
+ int GRASS_LIB_EXPORT G_remove ( const char *element, const char *name )
1336
+ {
1337
+ Q_UNUSED ( element );
1338
+ Q_UNUSED ( name );
1339
+ return 1 ;
1340
+ }
0 commit comments