Skip to content

Commit

Permalink
get map region moved to grass lib
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@5077 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Mar 22, 2006
1 parent a4b8dfa commit 9be967c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
67 changes: 65 additions & 2 deletions src/providers/grass/qgsgrass.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
}

7 changes: 7 additions & 0 deletions src/providers/grass/qgsgrass.h
Expand Up @@ -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

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 9be967c

Please sign in to comment.