|
25 | 25 | #include "qdir.h"
|
26 | 26 | #include "qtextstream.h"
|
27 | 27 | #include "qsettings.h"
|
28 |
| - |
29 |
| -//#include "qgsapplication.h" |
| 28 | +#include <QMessageBox> |
30 | 29 | #include <QCoreApplication>
|
31 | 30 | #include "qgsgrass.h"
|
32 | 31 |
|
33 | 32 | extern "C" {
|
34 | 33 | #include <unistd.h>
|
| 34 | +#include <grass/gis.h> |
| 35 | +#include <grass/Vect.h> |
35 | 36 | }
|
36 | 37 |
|
37 | 38 | void QgsGrass::init( void )
|
@@ -641,3 +642,65 @@ QStringList QgsGrass::elements ( QString mapsetPath, QString element )
|
641 | 642 | }
|
642 | 643 | return list;
|
643 | 644 | }
|
| 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 | + |
0 commit comments