Skip to content

Commit 7354757

Browse files
author
rblazek
committed
region jokes and version
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5081 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 9094e48 commit 7354757

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

src/providers/grass/qgsgrass.cpp

+108
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern "C" {
3333
#include <unistd.h>
3434
#include <grass/gis.h>
3535
#include <grass/Vect.h>
36+
#include <grass/version.h>
3637
}
3738

3839
void QgsGrass::init( void )
@@ -643,6 +644,43 @@ QStringList QgsGrass::elements ( QString mapsetPath, QString element )
643644
return list;
644645
}
645646

647+
QString QgsGrass::regionString( struct Cell_head *window )
648+
{
649+
QString reg;
650+
int fmt;
651+
char buf[1024];
652+
653+
fmt = window->proj;
654+
655+
// TODO 3D
656+
657+
reg = "proj:" + QString::number(window->proj) + ";" ;
658+
reg += "zone:" + QString::number(window->zone) + ";" ;
659+
660+
G_format_northing (window->north,buf,fmt);
661+
reg += "north:" + QString(buf) + ";" ;
662+
663+
G_format_northing (window->south,buf,fmt);
664+
reg += "south:" + QString(buf) + ";" ;
665+
666+
G_format_easting (window->east,buf,fmt);
667+
reg += "east:" + QString(buf) + ";" ;
668+
669+
G_format_easting (window->west,buf,fmt);
670+
reg += "west:" + QString(buf) + ";" ;
671+
672+
reg += "cols:" + QString::number(window->cols) + ";" ;
673+
reg += "rows:" + QString::number(window->rows) + ";" ;
674+
675+
G_format_resolution (window->ew_res,buf,fmt);
676+
reg += "e-w resol:" + QString(buf) + ";" ;
677+
678+
G_format_resolution (window->ns_res,buf,fmt);
679+
reg += "n-s resol:" + QString(buf) + ";" ;
680+
681+
return reg;
682+
}
683+
646684
bool QgsGrass::region( QString gisbase,
647685
QString location, QString mapset,
648686
struct Cell_head *window )
@@ -656,6 +694,66 @@ bool QgsGrass::region( QString gisbase,
656694
return true;
657695
}
658696

697+
bool QgsGrass::writeRegion( QString gisbase,
698+
QString location, QString mapset,
699+
struct Cell_head *window )
700+
{
701+
std::cerr << "QgsGrass::writeRegion()" << std::endl;
702+
std::cerr << "n = " << window->north << " s = " << window->south << std::endl;
703+
std::cerr << "e = " << window->east << " w = " << window->west << std::endl;
704+
705+
QgsGrass::setMapset( gisbase, location, mapset );
706+
707+
if ( G_put_window(window) == -1 ) {
708+
return false;
709+
}
710+
711+
return true;
712+
}
713+
714+
void QgsGrass::copyRegionExtent( struct Cell_head *source,
715+
struct Cell_head *target )
716+
{
717+
target->north = source->north;
718+
target->south = source->south;
719+
target->east = source->east;
720+
target->west = source->west;
721+
target->top = source->top;
722+
target->bottom = source->bottom;
723+
}
724+
725+
void QgsGrass::copyRegionResolution( struct Cell_head *source,
726+
struct Cell_head *target )
727+
{
728+
target->ns_res = source->ns_res;
729+
target->ew_res = source->ew_res;
730+
target->tb_res = source->tb_res;
731+
target->ns_res3 = source->ns_res3;
732+
target->ew_res3 = source->ew_res3;
733+
}
734+
735+
void QgsGrass::extendRegion( struct Cell_head *source,
736+
struct Cell_head *target )
737+
{
738+
if ( source->north > target->north )
739+
target->north = source->north;
740+
741+
if ( source->south < target->south )
742+
target->south = source->south;
743+
744+
if ( source->east > target->east )
745+
target->east = source->east;
746+
747+
if ( source->west < target->west )
748+
target->west = source->west;
749+
750+
if ( source->top > target->top )
751+
target->top = source->top;
752+
753+
if ( source->bottom < target->bottom )
754+
target->bottom = source->bottom;
755+
}
756+
659757
bool QgsGrass::mapRegion( int type, QString gisbase,
660758
QString location, QString mapset, QString map,
661759
struct Cell_head *window )
@@ -735,3 +833,13 @@ bool QgsGrass::mapRegion( int type, QString gisbase,
735833
return true;
736834
}
737835

836+
int QgsGrass::versionMajor()
837+
{
838+
return QString(GRASS_VERSION_MAJOR).toInt();
839+
}
840+
int QgsGrass::versionMinor()
841+
{
842+
return QString(GRASS_VERSION_MINOR).toInt();
843+
}
844+
845+

src/providers/grass/qgsgrass.h

+24
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,37 @@ class QgsGrass {
118118
QString location, QString mapset, QString map,
119119
struct Cell_head *window );
120120

121+
// ! String representation of region
122+
static QString QgsGrass::regionString( struct Cell_head *window );
123+
121124
// ! Read current mapset region
122125
static bool QgsGrass::region( QString gisbase,
123126
QString location, QString mapset,
124127
struct Cell_head *window );
125128

129+
// ! Write current mapset region
130+
static bool QgsGrass::writeRegion( QString gisbase,
131+
QString location, QString mapset,
132+
struct Cell_head *window );
133+
134+
// ! Set (copy) region extent, resolution is not changed
135+
static void QgsGrass::copyRegionExtent( struct Cell_head *source,
136+
struct Cell_head *target );
137+
138+
// ! Set (copy) region resolution, extent is not changed
139+
static void QgsGrass::copyRegionResolution( struct Cell_head *source,
140+
struct Cell_head *target );
141+
142+
// ! Extend region in target to source
143+
static void QgsGrass::extendRegion( struct Cell_head *source,
144+
struct Cell_head *target );
145+
126146
static void init (void);
127147

148+
//! Library version
149+
static int QgsGrass::versionMajor();
150+
static int QgsGrass::versionMinor();
151+
128152
private:
129153
static int initialized; // Set to 1 after initialization
130154
static bool active; // is active mode

0 commit comments

Comments
 (0)