Skip to content

Commit

Permalink
various utilities
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@5021 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Mar 15, 2006
1 parent d0ee6c4 commit 6a5562e
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/plugins/grass/qgsgrassutils.cpp
@@ -0,0 +1,65 @@
/*******************************************************************
qgsgrassutils.cpp
-------------------
begin : March, 2006
copyright : (C) 2006 by Radim Blazek
email : radim.blazek@gmail.com
********************************************************************/
/********************************************************************
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
*******************************************************************/
#include <iostream>
#include <vector>

#include <QApplication>

//#include "qgis.h"
//#include "qgsapplication.h"

extern "C" {
#include <grass/gis.h>
#include <grass/Vect.h>
}

#include "../../src/providers/grass/qgsgrass.h"
#include "qgsgrassutils.h"
#include "qgsgrassselect.h"

QgsGrassUtils::QgsGrassUtils() {}
QgsGrassUtils::~QgsGrassUtils() {}

QString QgsGrassUtils::vectorLayerName( QString map, QString layer,
int nLayers )
{
QString name = map;
if ( nLayers > 1 ) name += " " + layer;
return name;
}

void QgsGrassUtils::addVectorLayers ( QgisIface *iface,
QString gisbase, QString location, QString mapset, QString map)
{
QStringList layers = QgsGrassSelect::vectorLayers(
gisbase, location, mapset, map );


for ( int i = 0; i < layers.count(); i++ )
{
QString name = QgsGrassUtils::vectorLayerName (
map, layers[i], layers.size() );

QString uri = gisbase + "/" + location + "/"
+ mapset + "/" + map + "/" + layers[i];

#ifdef QGISDEBUG
std::cerr << "layer = " << layers[i].local8Bit().data() << std::endl;
std::cerr << "uri = " << uri.local8Bit().data() << std::endl;
std::cerr << "name = " << name.local8Bit().data() << std::endl;
#endif

iface->addVectorLayer( uri, name, "grass");
}
}
43 changes: 43 additions & 0 deletions src/plugins/grass/qgsgrassutils.h
@@ -0,0 +1,43 @@
/***************************************************************************
qgsgrassutils.h
-------------------
begin : March, 2006
copyright : (C) 2006 by Radim Blazek
email : radim.blazek@gmail.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSGRASSUTILS_H
#define QGSGRASSUTILS_H

#include "qgisiface.h"

/*! \class QgsGrassUtils
* \brief Various utilities.
*/
class QgsGrassUtils
{

public:
//! Constructor
QgsGrassUtils();

//! Destructor
~QgsGrassUtils();

public:
// Create vector name from map name, layer name and number of layers
static QString vectorLayerName( QString map, QString layer, int nLayers );

// Add all vector layers to QGIS view
static void QgsGrassUtils::addVectorLayers ( QgisIface *iface,
QString gisbase, QString location, QString mapset, QString map);
};

#endif // QGSGRASSUTILS_H

0 comments on commit 6a5562e

Please sign in to comment.