Skip to content

Commit 9be967c

Browse files
author
rblazek
committed
get map region moved to grass lib
git-svn-id: http://svn.osgeo.org/qgis/trunk@5077 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a4b8dfa commit 9be967c

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

src/providers/grass/qgsgrass.cpp

+65-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@
2525
#include "qdir.h"
2626
#include "qtextstream.h"
2727
#include "qsettings.h"
28-
29-
//#include "qgsapplication.h"
28+
#include <QMessageBox>
3029
#include <QCoreApplication>
3130
#include "qgsgrass.h"
3231

3332
extern "C" {
3433
#include <unistd.h>
34+
#include <grass/gis.h>
35+
#include <grass/Vect.h>
3536
}
3637

3738
void QgsGrass::init( void )
@@ -641,3 +642,65 @@ QStringList QgsGrass::elements ( QString mapsetPath, QString element )
641642
}
642643
return list;
643644
}
645+
646+
647+
bool QgsGrass::mapRegion( int type, QString gisbase,
648+
QString location, QString mapset, QString map,
649+
struct Cell_head *window )
650+
{
651+
#ifdef QGISDEBUG
652+
std::cerr << "QgsGrass::mapRegion()" << std::endl;
653+
#endif
654+
655+
QgsGrass::setLocation( gisbase, location );
656+
657+
if ( type == Raster )
658+
{
659+
660+
if ( G_get_cellhd ( map.toLocal8Bit().data(),
661+
mapset.toLocal8Bit().data(), window) < 0 )
662+
{
663+
QMessageBox::warning( 0, "Warning",
664+
"Cannot read raster map region" );
665+
return false;
666+
}
667+
}
668+
else if ( type == Vector )
669+
{
670+
G_get_window ( window ); // get current resolution
671+
672+
struct Map_info Map;
673+
674+
int level = Vect_open_old_head ( &Map,
675+
map.toLocal8Bit().data(), mapset.toLocal8Bit().data());
676+
677+
if ( level < 2 )
678+
{
679+
QMessageBox::warning( 0, "Warning",
680+
"Cannot read vector map region" );
681+
return false;
682+
}
683+
684+
BOUND_BOX box;
685+
Vect_get_map_box (&Map, &box );
686+
window->north = box.N;
687+
window->south = box.S;
688+
window->west = box.W;
689+
window->east = box.E;
690+
691+
Vect_close (&Map);
692+
}
693+
else if ( type == Region )
694+
{
695+
if ( G__get_window (window, "windows",
696+
map.toLocal8Bit().data(),
697+
mapset.toLocal8Bit().data() ) != NULL )
698+
{
699+
QMessageBox::warning( 0, "Warning",
700+
"Cannot read region" );
701+
return false;
702+
}
703+
}
704+
return true;
705+
}
706+

src/providers/grass/qgsgrass.h

+7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class QgsGrass {
6565
FATAL /*!< Fatal error. Function faild. */
6666
};
6767

68+
//! Map type
69+
enum MapType { Raster, Vector, Region };
70+
6871
//! Reset error code (to OK). Call this before a piece of code where an error is expected
6972
static void resetError ( void ); // reset error status
7073

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

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

114121
static void init (void);
115122

0 commit comments

Comments
 (0)