// Slot called when the "Add GRASS raster layer" menu item is triggered void QgsGrassPlugin::addRaster() { // QgsDebugMsg("entered."); QString uri; QgsGrassSelect *sel = new QgsGrassSelect( QgsGrassSelect::RASTER ); if ( sel->exec() ) { QString element; if ( sel->selectedType == QgsGrassSelect::RASTER ) { element = "cellhd"; } else // GROUP { element = "group"; } uri = sel->gisdbase + "/" + sel->location + "/" + sel->mapset + "/" + element + "/" + sel->map; } // QgsDebugMsg(QString("plugin URI: %1").arg(uri)); if ( uri.length() == 0 ) { // QgsDebugMsg("Nothing was selected"); return; } else { // QgsDebugMsg("Add new raster layer"); // create raster name int pos = uri.lastIndexOf( '/' ); pos = uri.lastIndexOf( '/', pos - 1 ); QString name = uri.right( uri.length() - pos - 1 ); name.replace( '/', ' ' ); //qGisInterface->addRasterLayer( uri, sel->map ); qGisInterface->addRasterLayer( uri, sel->map, "grassraster", QStringList(), QStringList(), QString(), QString() ); } }
void QgsGrassPlugin::openMapset() { // QgsDebugMsg("entered."); QString element; QgsGrassSelect *sel = new QgsGrassSelect( QgsGrassSelect::MAPSET ); if ( !sel->exec() ) return; QString err = QgsGrass::openMapset( sel->gisdbase, sel->location, sel->mapset ); if ( !err.isNull() ) { QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open the mapset. %1" ).arg( err ) ); return; } saveMapset(); mapsetChanged(); }
// Slot called when the "Add GRASS vector layer" menu item is triggered void QgsGrassPlugin::addVector() { // QgsDebugMsg("entered."); QString uri; QgsGrassSelect *sel = new QgsGrassSelect( qGisInterface->mainWindow(), QgsGrassSelect::VECTOR ); if ( sel->exec() ) { uri = sel->gisdbase + "/" + sel->location + "/" + sel->mapset + "/" + sel->map + "/" + sel->layer; } // QgsDebugMsg(QString("plugin URI: %1").arg(uri)); if ( uri.length() == 0 ) { // QgsDebugMsg("Nothing was selected"); return; } else { // QgsDebugMsg("Add new vector layer"); // create vector name: vector layer QString name = sel->map; QString field; QString type; if ( !sel->layer.startsWith( "topo_" ) ) { QRegExp rx( "(\\d+)_(.+)" ); if ( rx.indexIn( sel->layer ) != -1 ) { field = rx.cap( 1 ); type = rx.cap( 2 ); } } // Set location QgsGrass::setLocation( sel->gisdbase, sel->location ); /* Open vector */ try { //Vect_set_open_level( 2 ); struct Map_info map; int level = Vect_open_old_head( &map, sel->map.toUtf8().data(), sel->mapset.toUtf8().data() ); if ( level == 1 ) { QgsDebugMsg( "Cannot open vector on level 2" ); QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open vector %1 in mapset %2 on level 2 (topology not available, try to rebuild topology using v.build module)." ).arg( sel->map ).arg( sel->mapset ) ); Vect_close( &map ); return; } else if ( level < 1 ) { QgsDebugMsg( "Cannot open vector" ); QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open vector %1 in mapset %2" ).arg( sel->map ).arg( sel->mapset ) ); return; } if ( level >= 2 ) { if ( !sel->layer.startsWith( "topo_" ) ) { // Count layers int cnt = 0; int ncidx = Vect_cidx_get_num_fields( &map ); for ( int i = 0; i < ncidx; i++ ) { int field = Vect_cidx_get_field_number( &map, i ); if ( Vect_cidx_get_type_count( &map, field, GV_POINT | GV_LINE | GV_AREA ) > 0 || ( field > 1 && Vect_cidx_get_type_count( &map, field, GV_BOUNDARY ) ) ) { cnt++; } } if ( cnt > 1 ) { name.append( " " + field ); // No need to ad type, the type is obvious from the legend } } else { name.append( " " + sel->layer ); } } Vect_close( &map ); } catch ( QgsGrass::Exception &e ) { QMessageBox::warning( 0, tr( "Warning" ), tr( "Cannot open GRASS vector:\n %1" ).arg( e.what() ) ); } qGisInterface->addVectorLayer( uri, name, "grass" ); } }