Skip to content
Permalink
Browse files

get map region moved to grass lib

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5077 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek
rblazek committed Mar 22, 2006
1 parent 2e252d2 commit da87abf128118a45c67ef26032bfe7c7a3bf4823
Showing with 72 additions and 2 deletions.
  1. +65 −2 src/providers/grass/qgsgrass.cpp
  2. +7 −0 src/providers/grass/qgsgrass.h
@@ -25,13 +25,14 @@
#include "qdir.h"
#include "qtextstream.h"
#include "qsettings.h"

//#include "qgsapplication.h"
#include <QMessageBox>
#include <QCoreApplication>
#include "qgsgrass.h"

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

void QgsGrass::init( void )
@@ -641,3 +642,65 @@ QStringList QgsGrass::elements ( QString mapsetPath, QString element )
}
return list;
}


bool QgsGrass::mapRegion( int type, QString gisbase,
QString location, QString mapset, QString map,
struct Cell_head *window )
{
#ifdef QGISDEBUG
std::cerr << "QgsGrass::mapRegion()" << std::endl;
#endif

QgsGrass::setLocation( gisbase, location );

if ( type == Raster )
{

if ( G_get_cellhd ( map.toLocal8Bit().data(),
mapset.toLocal8Bit().data(), window) < 0 )
{
QMessageBox::warning( 0, "Warning",
"Cannot read raster map region" );
return false;
}
}
else if ( type == Vector )
{
G_get_window ( window ); // get current resolution

struct Map_info Map;

int level = Vect_open_old_head ( &Map,
map.toLocal8Bit().data(), mapset.toLocal8Bit().data());

if ( level < 2 )
{
QMessageBox::warning( 0, "Warning",
"Cannot read vector map region" );
return false;
}

BOUND_BOX box;
Vect_get_map_box (&Map, &box );
window->north = box.N;
window->south = box.S;
window->west = box.W;
window->east = box.E;

Vect_close (&Map);
}
else if ( type == Region )
{
if ( G__get_window (window, "windows",
map.toLocal8Bit().data(),
mapset.toLocal8Bit().data() ) != NULL )
{
QMessageBox::warning( 0, "Warning",
"Cannot read region" );
return false;
}
}
return true;
}

@@ -65,6 +65,9 @@ class QgsGrass {
FATAL /*!< Fatal error. Function faild. */
};

//! Map type
enum MapType { Raster, Vector, Region };

//! Reset error code (to OK). Call this before a piece of code where an error is expected
static void resetError ( void ); // reset error status

@@ -110,6 +113,10 @@ class QgsGrass {
QString mapsetName, QString element);
static QStringList elements(QString mapsetPath, QString element);

// ! Get map region
static bool QgsGrass::mapRegion( int type, QString gisbase,
QString location, QString mapset, QString map,
struct Cell_head *window );

static void init (void);

0 comments on commit da87abf

Please sign in to comment.
You can’t perform that action at this time.