Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
More GRASS direct functions
  • Loading branch information
blazek committed Dec 16, 2012
1 parent d4aa0ed commit cdaebd1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
17 changes: 17 additions & 0 deletions src/providers/grass/CMakeLists.txt
Expand Up @@ -82,6 +82,7 @@ SET ( FUNCTIONS
"G_colors_count"
"G_col_to_easting"
"G_convert_dirseps_to_host"
"G_copy"
"G_create_key_value"
"G_database_projection_name"
"G_date"
Expand All @@ -99,11 +100,15 @@ SET ( FUNCTIONS
"G_free"
"G_free_cats"
"G_free_cell_stats"
"G_free_colors"
"G_free_histogram"
"G_free_key_value"
"G_free_raster_cats"
"G_free_reclass"
"G_fseek"
"G_ftell"
"G_get_cat"
"G_get_cats_title"
"G_get_c_raster_cat"
"G_get_d_raster_cat"
"G_get_fp_range_min_max"
Expand All @@ -118,6 +123,7 @@ SET ( FUNCTIONS
"G_get_window"
"G_incr_void_ptr"
"G_index"
"G_init_cats"
"G_init_cell_stats"
"G_init_colors"
"G_init_fp_range"
Expand All @@ -127,13 +133,15 @@ SET ( FUNCTIONS
"G_is_c_null_value"
"G_is_d_null_value"
"G_is_f_null_value"
"G_is_null_value"
"G_lat_scan"
"G_llres_scan"
"G_lon_scan"
"G__ls"
"G_ls"
"G_ls_format"
"G__malloc"
"G_make_gyr_fp_colors"
"G_make_random_colors"
"G_northing_to_row"
"G__projection_name"
Expand All @@ -144,6 +152,7 @@ SET ( FUNCTIONS
"G_quant_free"
"G_quant_get_limits"
"G_quant_init"
"G_quant_round"
"G_putenv"
"G_raster_size"
"G_read_key_value_file"
Expand All @@ -165,6 +174,7 @@ SET ( FUNCTIONS
"G_set_raster_cats_title"
"G_set_raster_value_d"
"G_set_window"
"G_sleep"
"G_store"
"G_strcasecmp"
"G_strcat"
Expand All @@ -189,6 +199,8 @@ SET ( FUNCTIONS
"G_window_rows"
"G_write_key_value_file"
"G_zero"
"G_zero_cell_buf"
"G_zero_raster_buf"
)

# If a function, say G_1 called in true GRASS gis lib (loaded by QLibrary)
Expand Down Expand Up @@ -223,6 +235,7 @@ SET ( FUNCTION_PROTOTYPES
"G_begin_geodesic_distance"
"G_check_input_output_name"
"G_check_overwrite"
"G_clear_screen"
"G_close_cell"
"G_command_history"
"G_database_units_to_meters_factor"
Expand All @@ -238,6 +251,7 @@ SET ( FUNCTION_PROTOTYPES
"G_find_file2"
"G_find_file_misc"
"G_find_file2_misc"
"G_find_vector"
"G_fully_qualified_name"
"G_geodesic_distance_lon_to_lon"
"G_get_cellhd"
Expand Down Expand Up @@ -265,6 +279,7 @@ SET ( FUNCTION_PROTOTYPES
"G_open_fp_cell_new"
"G_open_raster_new"
"G_parser"
"G_put_cell_title"
"G_put_raster_row"
"G_quantize_fp_map_range"
"G_raster_map_is_fp"
Expand All @@ -281,6 +296,8 @@ SET ( FUNCTION_PROTOTYPES
"G_set_geodesic_distance_lat2"
"G_set_quant_rules"
"G_short_history"
"G_spawn"
"G_spawn_ex"
"G__temp_element"
"G_tempfile"
"G_vasprintf"
Expand Down
55 changes: 48 additions & 7 deletions src/providers/grass/qgsgrassgislib.cpp
Expand Up @@ -91,15 +91,15 @@ QgsGrassGisLib::QgsGrassGisLib()
// on Linux and Mac but on Windows with OSGEO4W the GRASS may be installed
// in a different directory. qgis.env however calls GRASS etc/env.bat
// which sets GISBASE and GRASS_LIBRARY_GIS on Windows is path to .lib, e.g
// grass_gis.lib. Name of the DLL on Windows is e.g.: libgrass_gis6.4.3RC1.dll
// grass_gis.lib. Name of the DLL on Windows is e.g.: libgrass_gis.6.4.3RC1.dll

QString gisBase = getenv( "GISBASE" );
#ifdef Q_OS_WIN
if ( gisBase.isEmpty() )
{
fatal( "GISBASE environment variable not set" );
}
QString libPath = gisBase + "/lib/libgrass_gis" + QString( GRASS_VERSION ) + ".dll";
QString libPath = gisBase + "\\lib\\libgrass_gis." + QString( GRASS_VERSION ) + ".dll";
#else
QString libPath = QString( GRASS_LIBRARY_GIS );
// Prefere GISBASE if set
Expand Down Expand Up @@ -138,7 +138,7 @@ void QgsGrassGisLib::warning( QString msg )

void * QgsGrassGisLib::resolve( const char * symbol )
{
QgsDebugMsg( QString( "symbol = %1" ).arg( symbol ) );
QgsDebugMsgLevel( QString( "symbol = %1" ).arg( symbol ), 5 );
void * fn = mLibrary.resolve( symbol );
if ( !fn )
{
Expand Down Expand Up @@ -396,7 +396,7 @@ char GRASS_LIB_EXPORT *G_find_file( const char *element, char *name, const char
return NULL;
}

char GRASS_LIB_EXPORT *G_find_file2( const char *element, char *name, const char *mapset )
char GRASS_LIB_EXPORT *G_find_file2( const char *element, const char *name, const char *mapset )
{
Q_UNUSED( element );
Q_UNUSED( name );
Expand All @@ -413,7 +413,7 @@ char GRASS_LIB_EXPORT *G_find_file_misc( const char *dir, const char *element, c
return NULL;
}

char GRASS_LIB_EXPORT *G_find_file_misc2( const char *dir, const char *element, char *name, const char *mapset )
char GRASS_LIB_EXPORT *G_find_file2_misc( const char *dir, const char *element, char *name, const char *mapset )
{
Q_UNUSED( dir );
Q_UNUSED( element );
Expand Down Expand Up @@ -709,6 +709,28 @@ void GRASS_LIB_EXPORT G_verbose_message( const char *msg, ... )
QgsDebugMsg( message );
}

typedef int G_spawn_type( const char *command, ... );
int GRASS_LIB_EXPORT G_spawn( const char *command, ... )
{
va_list ap;
G_spawn_type* fn = ( G_spawn_type* ) cast_to_fptr( QgsGrassGisLib::instance()->resolve( "G_spawn" ) );
va_start( ap, command );
int ret = fn( command, ap );
va_end( ap );
return ret;
}

typedef int G_spawn_ex_type( const char *command, ... );
int GRASS_LIB_EXPORT G_spawn_ex( const char *command, ... )
{
va_list ap;
G_spawn_ex_type* fn = ( G_spawn_ex_type* ) cast_to_fptr( QgsGrassGisLib::instance()->resolve( "G_spawn_ex" ) );
va_start( ap, command );
int ret = fn( command, ap );
va_end( ap );
return ret;
}

int GRASS_LIB_EXPORT G_set_quant_rules( int fd, struct Quant *q )
{
Q_UNUSED( fd );
Expand Down Expand Up @@ -1167,14 +1189,14 @@ RASTER_MAP_TYPE QgsGrassGisLib::grassRasterType( QgsRasterBlock::DataType qgisTy
typedef int G_vasprintf_type( char **, const char *, va_list );
int G_vasprintf( char **out, const char *fmt, va_list ap )
{
G_vasprintf_type* fn = ( G_vasprintf_type* ) cast_to_fptr( QgsGrassGisLib::instance()->resolve( "G_vasprintf_type" ) );
G_vasprintf_type* fn = ( G_vasprintf_type* ) cast_to_fptr( QgsGrassGisLib::instance()->resolve( "G_vasprintf" ) );
return fn( out, fmt, ap );
}

typedef int G_asprintf_type( char **, const char *, ... );
int G_asprintf( char **out, const char *fmt, ... )
{
G_asprintf_type* fn = ( G_asprintf_type* ) cast_to_fptr( QgsGrassGisLib::instance()->resolve( "G_asprintf_type" ) );
G_asprintf_type* fn = ( G_asprintf_type* ) cast_to_fptr( QgsGrassGisLib::instance()->resolve( "G_asprintf" ) );
va_list ap;
va_start( ap, fmt );
int ret = fn( out, fmt, ap );
Expand Down Expand Up @@ -1338,3 +1360,22 @@ int GRASS_LIB_EXPORT G_remove( const char *element, const char *name )
Q_UNUSED( name );
return 1;
}

int G_put_cell_title( const char *name, const char *title )
{
Q_UNUSED( name );
Q_UNUSED( title );
return 1; // OK
}

int G_clear_screen( void )
{
return 0; // OK
}

char *G_find_vector( char *name, const char *mapset )
{
Q_UNUSED( name );
Q_UNUSED( mapset );
return NULL;
}

0 comments on commit cdaebd1

Please sign in to comment.