Skip to content

Commit

Permalink
[GRASS] create imagery group if there are rgb color interpretations, …
Browse files Browse the repository at this point in the history
…list groups in browser
  • Loading branch information
blazek committed May 26, 2015
1 parent 75fb718 commit 9e5b2ba
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cmake/FindGRASS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ MACRO (CHECK_GRASS G_PREFIX)
IF(GRASS_MAJOR_VERSION${GRASS_FIND_VERSION} LESS 7 )
LIST(APPEND GRASS_LIB_NAMES${GRASS_FIND_VERSION} vect)
LIST(APPEND GRASS_LIB_NAMES${GRASS_FIND_VERSION} form)
LIST(APPEND GRASS_LIB_NAMES${GRASS_FIND_VERSION} I)
ELSE(GRASS_MAJOR_VERSION${GRASS_FIND_VERSION} LESS 7 )
LIST(APPEND GRASS_LIB_NAMES${GRASS_FIND_VERSION} vector)
LIST(APPEND GRASS_LIB_NAMES${GRASS_FIND_VERSION} raster)
LIST(APPEND GRASS_LIB_NAMES${GRASS_FIND_VERSION} imagery)
ENDIF(GRASS_MAJOR_VERSION${GRASS_FIND_VERSION} LESS 7 )

FOREACH(LIB ${GRASS_LIB_NAMES${GRASS_FIND_VERSION}})
Expand Down
1 change: 1 addition & 0 deletions images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
<file>themes/default/mIconProperties.svg</file>
<file>themes/default/mIconPyramid.png</file>
<file>themes/default/mIconRaster.svg</file>
<file>themes/default/mIconRasterGroup.svg</file>
<file>themes/default/mIconRasterLink.svg</file>
<file>themes/default/mIconRasterLayer.svg</file>
<file>themes/default/mIconRenderingDisabled.png</file>
Expand Down
33 changes: 33 additions & 0 deletions images/themes/default/mIconRasterGroup.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/providers/grass/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ MACRO(ADD_GRASSLIB GRASS_BUILD_VERSION)
qgis_gui
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_vect}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_I}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_dbmibase}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_dbmiclient}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gproj}
Expand All @@ -87,6 +88,7 @@ MACRO(ADD_GRASSLIB GRASS_BUILD_VERSION)
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_vector}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_raster}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_imagery}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_dbmibase}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_dbmiclient}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gproj}
Expand Down
19 changes: 18 additions & 1 deletion src/providers/grass/qgsgrass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ QString QgsGrassObject::elementShort() const
{
if ( mType == Raster )
return "rast";
else if ( mType == Group )
return "group";
else if ( mType == Vector )
return "vect";
else if ( mType == Region )
Expand All @@ -148,6 +150,8 @@ QString GRASS_LIB_EXPORT QgsGrassObject::elementName( Type type )
{
if ( type == Raster )
return "raster";
else if ( type == Group )
return "group";
else if ( type == Vector )
return "vector";
else if ( type == Region )
Expand All @@ -165,6 +169,8 @@ QString GRASS_LIB_EXPORT QgsGrassObject::dirName( Type type )
{
if ( type == Raster )
return "cellhd";
else if ( type == Group )
return "group";
else if ( type == Vector )
return "vector";
else if ( type == Region )
Expand Down Expand Up @@ -1176,6 +1182,17 @@ QStringList GRASS_LIB_EXPORT QgsGrass::rasters( const QString& mapsetPath )
return list;
}

QStringList GRASS_LIB_EXPORT QgsGrass::groups( const QString& gisdbase, const QString& locationName,
const QString& mapsetName )
{
return elements( gisdbase, locationName, mapsetName, "group" );
}

QStringList GRASS_LIB_EXPORT QgsGrass::groups( const QString& mapsetPath )
{
return elements( mapsetPath, "group" );
}

QStringList GRASS_LIB_EXPORT QgsGrass::elements( const QString& gisdbase, const QString& locationName,
const QString& mapsetName, const QString& element )
{
Expand All @@ -1197,7 +1214,7 @@ QStringList GRASS_LIB_EXPORT QgsGrass::elements( const QString& mapsetPath, con
return list;

QDir d = QDir( mapsetPath + "/" + element );
if ( element == "vector" )
if ( element == "vector" || element == "group" )
{
d.setFilter( QDir::Dirs | QDir::NoDotAndDotDot );
}
Expand Down
9 changes: 7 additions & 2 deletions src/providers/grass/qgsgrass.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class GRASS_LIB_EXPORT QgsGrassObject
{
public:
//! Element type
enum Type { None, Raster, Vector, Region };
enum Type { None, Raster, Group, Vector, Region };

QgsGrassObject() : mType( None ) {}
QgsGrassObject( const QString& gisdbase, const QString& location = QString::null,
Expand Down Expand Up @@ -220,9 +220,14 @@ class QgsGrass
static GRASS_LIB_EXPORT QStringList vectors( const QString& mapsetPath );

static GRASS_LIB_EXPORT QStringList rasters( const QString& gisdbase, const QString& locationName,
const QString& mapsetNamee );
const QString& mapsetName );
static GRASS_LIB_EXPORT QStringList rasters( const QString& mapsetPath );

// imagery groups
static GRASS_LIB_EXPORT QStringList groups( const QString& gisdbase, const QString& locationName,
const QString& mapsetName );
static GRASS_LIB_EXPORT QStringList groups( const QString& mapsetPath );

//! Get list of vector layers
static GRASS_LIB_EXPORT QStringList vectorLayers( const QString& gisdbase, const QString& location,
const QString& mapset, const QString& mapName );
Expand Down
43 changes: 43 additions & 0 deletions src/providers/grass/qgsgrassimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern "C"
#include <grass/version.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/imagery.h>
}

QgsGrassImport::QgsGrassImport( QgsGrassObject grassObject )
Expand Down Expand Up @@ -133,9 +134,26 @@ bool QgsGrassRasterImport::import()
return false;
}

int redBand = 0;
int greenBand = 0;
int blueBand = 0;
for ( int band = 1; band <= provider->bandCount(); band++ )
{
QgsDebugMsg( QString( "band = %1" ).arg( band ) );
int colorInterpretation = provider->colorInterpretation( band );
if ( colorInterpretation == QgsRaster::RedBand )
{
redBand = band;
}
else if ( colorInterpretation == QgsRaster::GreenBand )
{
greenBand = band;
}
else if ( colorInterpretation == QgsRaster::BlueBand )
{
blueBand = band;
}

QGis::DataType qgis_out_type = QGis::UnknownDataType;
RASTER_MAP_TYPE data_type = -1;
switch ( provider->dataType( band ) )
Expand Down Expand Up @@ -268,6 +286,31 @@ bool QgsGrassRasterImport::import()

delete process;
}
QgsDebugMsg( QString( "redBand = %1 greenBand = %2 blueBand = %3" ).arg( redBand ).arg( greenBand ).arg( blueBand ) );
if ( redBand > 0 && greenBand > 0 && blueBand > 0 )
{
// TODO: check if the group exists
// I_find_group()
QString name = mGrassObject.name();

G_TRY
{
QgsGrass::setMapset( mGrassObject.gisdbase(), mGrassObject.location(), mGrassObject.mapset() );
struct Ref ref;
I_get_group_ref( name.toUtf8().data(), &ref );
QString redName = name + QString( "_%1" ).arg( redBand );
QString greenName = name + QString( "_%1" ).arg( greenBand );
QString blueName = name + QString( "_%1" ).arg( blueBand );
I_add_file_to_group_ref( redName.toUtf8().data(), mGrassObject.mapset().toUtf8().data(), &ref );
I_add_file_to_group_ref( greenName.toUtf8().data(), mGrassObject.mapset().toUtf8().data(), &ref );
I_add_file_to_group_ref( blueName.toUtf8().data(), mGrassObject.mapset().toUtf8().data(), &ref );
I_put_group_ref( name.toUtf8().data(), &ref );
}
G_CATCH( QgsGrass::Exception &e )
{
QgsDebugMsg( QString( "Cannot create group: %1" ).arg( e.what() ) );
}
}
return true;
}

Expand Down
30 changes: 30 additions & 0 deletions src/providers/grass/qgsgrassprovidermodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ QVector<QgsDataItem*> QgsGrassMapsetItem::createChildren()
items.append( layer );
}

QStringList groupNames = QgsGrass::groups( mDirPath );
foreach ( QString name, groupNames )
{
QString path = mPath + "/" + "group" + "/" + name;
QString uri = mDirPath + "/" + "group" + "/" + name;
QgsDebugMsg( "uri = " + uri );

QgsGrassObject rasterObject( mGisdbase, mLocation, mName, name, QgsGrassObject::Group );
QgsGrassGroupItem *layer = new QgsGrassGroupItem( this, rasterObject, path, uri );
items.append( layer );
}

QgsGrassObject mapsetObject( mGisdbase, mLocation, mName );
foreach ( QgsGrassImport* import, mImports )
{
Expand Down Expand Up @@ -678,6 +690,24 @@ QIcon QgsGrassRasterItem::icon()
return QgsDataItem::icon();
}

//----------------------- QgsGrassGroupItem ------------------------------

QgsGrassGroupItem::QgsGrassGroupItem( QgsDataItem* parent, QgsGrassObject grassObject,
QString path, QString uri )
: QgsGrassObjectItem( parent, grassObject, grassObject.name(), path, uri, QgsLayerItem::Raster, "grassraster" )
{
}

QIcon QgsGrassGroupItem::icon()
{
static QIcon linkIcon;

if ( linkIcon.isNull() )
{
linkIcon = QgsApplication::getThemeIcon( "/mIconRasterGroup.svg" );
}
return linkIcon;
}

//----------------------- QgsGrassImportItem ------------------------------
QgsGrassImportItemIcon::QgsGrassImportItemIcon()
Expand Down
12 changes: 12 additions & 0 deletions src/providers/grass/qgsgrassprovidermodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ class QgsGrassRasterItem : public QgsGrassObjectItem
bool mExternal;
};

// Imagery group
class QgsGrassGroupItem : public QgsGrassObjectItem
{
Q_OBJECT
public:
QgsGrassGroupItem( QgsDataItem* parent, QgsGrassObject grassObject,
QString path, QString uril );

virtual QIcon icon() override;

};

// icon movie
class QgsGrassImportItemIcon : public QObject
{
Expand Down

0 comments on commit 9e5b2ba

Please sign in to comment.