@@ -85,12 +85,34 @@ QgsGrassGisLib GRASS_LIB_EXPORT *QgsGrassGisLib::instance( )
8585QgsGrassGisLib::QgsGrassGisLib ()
8686{
8787 // 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
88104 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
89111 QgsDebugMsg ( " libPath = " + libPath );
90112 mLibrary .setFileName ( libPath );
91113 if ( !mLibrary .load () )
92114 {
93- QgsDebugMsg ( " Cannot load original GRASS library" );
115+ fatal ( " Cannot load true GRASS library, path: " + libPath );
94116 return ;
95117 }
96118}
@@ -116,11 +138,11 @@ void QgsGrassGisLib::warning( QString msg )
116138
117139void * QgsGrassGisLib::resolve ( const char * symbol )
118140{
119- // QgsDebugMsg( QString("symbol = %1").arg(symbol) );
141+ QgsDebugMsg ( QString ( " symbol = %1" ).arg ( symbol ) );
120142 void * fn = mLibrary .resolve ( symbol );
121143 if ( !fn )
122144 {
123- QgsDebugMsg ( " Cannot resolve symbol" );
145+ fatal ( " Cannot resolve symbol " + QString ( symbol ) );
124146 }
125147 return fn;
126148}
@@ -178,6 +200,9 @@ int GRASS_LIB_EXPORT QgsGrassGisLib::G__gisinit( const char * version, const cha
178200 // Read projection if set
179201 // mCrs.createFromOgcWmsCrs( "EPSG:900913" );
180202 QString crsStr = getenv ( " QGIS_GRASS_CRS" );
203+
204+ QgsDebugMsg ( " Setting CRS to " + crsStr );
205+
181206 if ( !crsStr.isEmpty () )
182207 {
183208 if ( !mCrs .createFromProj4 ( crsStr ) )
@@ -228,6 +253,13 @@ int GRASS_LIB_EXPORT QgsGrassGisLib::G__gisinit( const char * version, const cha
228253 G_set_window( &window );
229254#endif
230255
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 );
231263 // GRASS true lib reads GRASS_REGION environment variable
232264 G_get_window ( &mWindow );
233265
@@ -237,6 +269,7 @@ int GRASS_LIB_EXPORT QgsGrassGisLib::G__gisinit( const char * version, const cha
237269 mXRes = mExtent .width () / mColumns ;
238270 mYRes = mExtent .height () / mColumns ;
239271
272+ QgsDebugMsg ( " End" );
240273 return 0 ;
241274}
242275
@@ -569,6 +602,11 @@ int GRASS_LIB_EXPORT G_open_cell_new( const char *name )
569602 return QgsGrassGisLib::instance ()->G_open_raster_new ( name, CELL_TYPE );
570603}
571604
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+
572610RASTER_MAP_TYPE QgsGrassGisLib::G_raster_map_type ( const char *name, const char *mapset )
573611{
574612 Q_UNUSED ( mapset );
@@ -1043,6 +1081,44 @@ int GRASS_LIB_EXPORT G_legal_filename( const char *s )
10431081 return 1 ;
10441082}
10451083
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+
10461122QgsRasterBlock::DataType QgsGrassGisLib::qgisRasterType ( RASTER_MAP_TYPE grassType )
10471123{
10481124 switch ( grassType )
@@ -1149,6 +1225,14 @@ int GRASS_LIB_EXPORT G_quantize_fp_map_range( const char *name, const char *maps
11491225 return 1 ;
11501226}
11511227
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+
11521236int GRASS_LIB_EXPORT G_read_raster_cats ( const char *name, const char *mapset, struct Categories *pcats )
11531237{
11541238 Q_UNUSED ( name );
@@ -1221,15 +1305,36 @@ int GRASS_LIB_EXPORT G_make_aspect_fp_colors( struct Colors *colors, DCELL min,
12211305 return 1 ; // OK
12221306}
12231307
1224- int G_check_overwrite ( int argc, char **argv )
1308+ int GRASS_LIB_EXPORT G_check_overwrite ( int argc, char **argv )
12251309{
12261310 Q_UNUSED ( argc );
12271311 Q_UNUSED ( argv );
12281312 return 1 ; // overwrite
12291313}
12301314
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 )
12321316{
12331317 Q_UNUSED ( mapset );
12341318 return G_store ( name );
12351319}
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