Skip to content
Permalink
Browse files
[GRASS] create imagery group if there are rgb color interpretations, …
…list groups in browser
  • Loading branch information
blazek committed May 26, 2015
1 parent 75fb718 commit 9e5b2ba51144511ab8ee46a2c2c804e35515d79d
@@ -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}})
@@ -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>
@@ -0,0 +1,33 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<!-- Created using Karbon, part of Calligra: http://www.calligra.org/karbon -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="19.2pt" height="19.2pt">
<defs/>
<g id="layer2">
<g id="group0" transform="translate(3.40276, 0.767879)" fill="none">
<rect id="rect6419" transform="translate(6.23337, 1.0389)" fill="#6e97c4" width="4.98669925886pt" height="4.90238315391pt"/>
<rect id="rect6419-6" transform="translate(12.4668, 1.0389)" fill="#2b3b4d" width="4.98669925886pt" height="4.90238315391pt"/>
<rect id="rect6419-6-9" transform="translate(6.23337, 7.16688)" fill="#2b3b4d" width="4.98669925886pt" height="4.90238315391pt"/>
<rect id="rect6419-0" transform="translate(12.4668, 7.16688)" fill="#6d97c4" width="4.98669925886pt" height="4.90238315391pt"/>
<rect id="rect6419-6-7" transform="translate(1.11022e-15, 1.0389)" fill="#2d3e4d" width="4.98669925886pt" height="4.90238315391pt"/>
<rect id="rect6419-3" transform="translate(0, 7.16688)" fill="#6d97c4" width="4.98669925886pt" height="4.90238315391pt"/>
<rect id="rect6419-5" transform="translate(6.23337, 13.2949)" fill="#6d97c4" width="4.98669925886pt" height="4.90238315391pt"/>
<rect id="rect6419-6-6" transform="translate(0, 13.2949)" fill="#2b3b4d" width="4.98669925886pt" height="4.90238315391pt"/>
<rect id="rect6419-61" transform="translate(12.4628, 13.291)" fill="#2b3b4d" width="4.98669925886pt" height="4.90238315391pt"/>
<rect id="rect6554" transform="translate(1.11022e-15, 1.0389)" fill="none" stroke="#ffffff" stroke-width="1.26248250207" stroke-linecap="butt" stroke-linejoin="round" width="14.96009839991pt" height="14.70715007453pt"/>
</g>
<g id="group1" transform="translate(1.11531, 2.38005)" fill="none">
<rect id="rect64191" transform="translate(6.29247, 2.73915)" fill="#6e97c4" width="4.52898297118pt" height="4.61731433191pt"/>
<rect id="rect6419-62" transform="translate(11.9537, 2.73915)" fill="#2b3b4d" width="4.52898297118pt" height="4.61731433191pt"/>
<rect id="rect6419-6-91" transform="translate(6.29247, 8.51079)" fill="#2b3b4d" width="4.52898297118pt" height="4.61731433191pt"/>
<rect id="rect6419-01" transform="translate(11.9537, 8.51079)" fill="#6d97c4" width="4.52898297118pt" height="4.61731433191pt"/>
<rect id="rect6419-6-71" transform="translate(0.631241, 2.73915)" fill="#2d3e4d" width="4.52898297118pt" height="4.61731433191pt"/>
<rect id="rect6419-31" transform="translate(0.631241, 8.51079)" fill="#6d97c4" width="4.52898297118pt" height="4.61731433191pt"/>
<rect id="rect6419-51" transform="translate(6.29247, 14.2824)" fill="#6d97c4" width="4.52898297118pt" height="4.61731433191pt"/>
<rect id="rect6419-6-61" transform="translate(0.631241, 14.2824)" fill="#2b3b4d" width="4.52898297118pt" height="4.61731433191pt"/>
<rect id="rect6419-63" transform="translate(11.9501, 14.2788)" fill="#2b3b4d" width="4.52898297118pt" height="4.61731433191pt"/>
<rect id="rect65541" transform="translate(0.631241, 2.73915)" fill="none" stroke="#ffffff" stroke-width="1.26248250207" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="0.00000000000" width="13.58694947965pt" height="13.85194357290pt"/>
</g>
<path id="shape0" transform="translate(9.15433, 1.50565)" fill="none" stroke="#ff7f50" stroke-width="2.53807526307" stroke-linecap="round" stroke-linejoin="round" d="M0 1.38778e-15C3.7918 0.0171509 5.56841 0.0171509 5.32981 0C5.3702 10.3588 5.3702 15.5383 5.32981 15.5383C5.28943 15.5383 3.5532 15.5376 0.121132 15.5362L0.121132 8.60389"/>
</g>
</svg>
@@ -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}
@@ -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}
@@ -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 )
@@ -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 )
@@ -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 )
@@ -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 )
{
@@ -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 );
}
@@ -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,
@@ -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 );
@@ -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 )
@@ -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 ) )
@@ -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;
}

@@ -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 )
{
@@ -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()
@@ -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
{

0 comments on commit 9e5b2ba

Please sign in to comment.