Skip to content

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
 

‎src/plugins/grass/qgsgrassutils.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*******************************************************************
2+
qgsgrassutils.cpp
3+
-------------------
4+
begin : March, 2006
5+
copyright : (C) 2006 by Radim Blazek
6+
email : radim.blazek@gmail.com
7+
********************************************************************/
8+
/********************************************************************
9+
This program is free software; you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation; either version 2 of the License, or
12+
(at your option) any later version.
13+
*******************************************************************/
14+
#include <iostream>
15+
#include <vector>
16+
17+
#include <QApplication>
18+
19+
//#include "qgis.h"
20+
//#include "qgsapplication.h"
21+
22+
extern "C" {
23+
#include <grass/gis.h>
24+
#include <grass/Vect.h>
25+
}
26+
27+
#include "../../src/providers/grass/qgsgrass.h"
28+
#include "qgsgrassutils.h"
29+
#include "qgsgrassselect.h"
30+
31+
QgsGrassUtils::QgsGrassUtils() {}
32+
QgsGrassUtils::~QgsGrassUtils() {}
33+
34+
QString QgsGrassUtils::vectorLayerName( QString map, QString layer,
35+
int nLayers )
36+
{
37+
QString name = map;
38+
if ( nLayers > 1 ) name += " " + layer;
39+
return name;
40+
}
41+
42+
void QgsGrassUtils::addVectorLayers ( QgisIface *iface,
43+
QString gisbase, QString location, QString mapset, QString map)
44+
{
45+
QStringList layers = QgsGrassSelect::vectorLayers(
46+
gisbase, location, mapset, map );
47+
48+
49+
for ( int i = 0; i < layers.count(); i++ )
50+
{
51+
QString name = QgsGrassUtils::vectorLayerName (
52+
map, layers[i], layers.size() );
53+
54+
QString uri = gisbase + "/" + location + "/"
55+
+ mapset + "/" + map + "/" + layers[i];
56+
57+
#ifdef QGISDEBUG
58+
std::cerr << "layer = " << layers[i].local8Bit().data() << std::endl;
59+
std::cerr << "uri = " << uri.local8Bit().data() << std::endl;
60+
std::cerr << "name = " << name.local8Bit().data() << std::endl;
61+
#endif
62+
63+
iface->addVectorLayer( uri, name, "grass");
64+
}
65+
}

‎src/plugins/grass/qgsgrassutils.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/***************************************************************************
2+
qgsgrassutils.h
3+
-------------------
4+
begin : March, 2006
5+
copyright : (C) 2006 by Radim Blazek
6+
email : radim.blazek@gmail.com
7+
***************************************************************************/
8+
/***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
#ifndef QGSGRASSUTILS_H
17+
#define QGSGRASSUTILS_H
18+
19+
#include "qgisiface.h"
20+
21+
/*! \class QgsGrassUtils
22+
* \brief Various utilities.
23+
*/
24+
class QgsGrassUtils
25+
{
26+
27+
public:
28+
//! Constructor
29+
QgsGrassUtils();
30+
31+
//! Destructor
32+
~QgsGrassUtils();
33+
34+
public:
35+
// Create vector name from map name, layer name and number of layers
36+
static QString vectorLayerName( QString map, QString layer, int nLayers );
37+
38+
// Add all vector layers to QGIS view
39+
static void QgsGrassUtils::addVectorLayers ( QgisIface *iface,
40+
QString gisbase, QString location, QString mapset, QString map);
41+
};
42+
43+
#endif // QGSGRASSUTILS_H

0 commit comments

Comments
 (0)
Please sign in to comment.