Skip to content

Commit

Permalink
region jokes and version
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5081 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Mar 23, 2006
1 parent 9094e48 commit 7354757
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
108 changes: 108 additions & 0 deletions src/providers/grass/qgsgrass.cpp
Expand Up @@ -33,6 +33,7 @@ extern "C" {
#include <unistd.h>
#include <grass/gis.h>
#include <grass/Vect.h>
#include <grass/version.h>
}

void QgsGrass::init( void )
Expand Down Expand Up @@ -643,6 +644,43 @@ QStringList QgsGrass::elements ( QString mapsetPath, QString element )
return list;
}

QString QgsGrass::regionString( struct Cell_head *window )
{
QString reg;
int fmt;
char buf[1024];

fmt = window->proj;

// TODO 3D

reg = "proj:" + QString::number(window->proj) + ";" ;
reg += "zone:" + QString::number(window->zone) + ";" ;

G_format_northing (window->north,buf,fmt);
reg += "north:" + QString(buf) + ";" ;

G_format_northing (window->south,buf,fmt);
reg += "south:" + QString(buf) + ";" ;

G_format_easting (window->east,buf,fmt);
reg += "east:" + QString(buf) + ";" ;

G_format_easting (window->west,buf,fmt);
reg += "west:" + QString(buf) + ";" ;

reg += "cols:" + QString::number(window->cols) + ";" ;
reg += "rows:" + QString::number(window->rows) + ";" ;

G_format_resolution (window->ew_res,buf,fmt);
reg += "e-w resol:" + QString(buf) + ";" ;

G_format_resolution (window->ns_res,buf,fmt);
reg += "n-s resol:" + QString(buf) + ";" ;

return reg;
}

bool QgsGrass::region( QString gisbase,
QString location, QString mapset,
struct Cell_head *window )
Expand All @@ -656,6 +694,66 @@ bool QgsGrass::region( QString gisbase,
return true;
}

bool QgsGrass::writeRegion( QString gisbase,
QString location, QString mapset,
struct Cell_head *window )
{
std::cerr << "QgsGrass::writeRegion()" << std::endl;
std::cerr << "n = " << window->north << " s = " << window->south << std::endl;
std::cerr << "e = " << window->east << " w = " << window->west << std::endl;

QgsGrass::setMapset( gisbase, location, mapset );

if ( G_put_window(window) == -1 ) {
return false;
}

return true;
}

void QgsGrass::copyRegionExtent( struct Cell_head *source,
struct Cell_head *target )
{
target->north = source->north;
target->south = source->south;
target->east = source->east;
target->west = source->west;
target->top = source->top;
target->bottom = source->bottom;
}

void QgsGrass::copyRegionResolution( struct Cell_head *source,
struct Cell_head *target )
{
target->ns_res = source->ns_res;
target->ew_res = source->ew_res;
target->tb_res = source->tb_res;
target->ns_res3 = source->ns_res3;
target->ew_res3 = source->ew_res3;
}

void QgsGrass::extendRegion( struct Cell_head *source,
struct Cell_head *target )
{
if ( source->north > target->north )
target->north = source->north;

if ( source->south < target->south )
target->south = source->south;

if ( source->east > target->east )
target->east = source->east;

if ( source->west < target->west )
target->west = source->west;

if ( source->top > target->top )
target->top = source->top;

if ( source->bottom < target->bottom )
target->bottom = source->bottom;
}

bool QgsGrass::mapRegion( int type, QString gisbase,
QString location, QString mapset, QString map,
struct Cell_head *window )
Expand Down Expand Up @@ -735,3 +833,13 @@ bool QgsGrass::mapRegion( int type, QString gisbase,
return true;
}

int QgsGrass::versionMajor()
{
return QString(GRASS_VERSION_MAJOR).toInt();
}
int QgsGrass::versionMinor()
{
return QString(GRASS_VERSION_MINOR).toInt();
}


24 changes: 24 additions & 0 deletions src/providers/grass/qgsgrass.h
Expand Up @@ -118,13 +118,37 @@ class QgsGrass {
QString location, QString mapset, QString map,
struct Cell_head *window );

// ! String representation of region
static QString QgsGrass::regionString( struct Cell_head *window );

// ! Read current mapset region
static bool QgsGrass::region( QString gisbase,
QString location, QString mapset,
struct Cell_head *window );

// ! Write current mapset region
static bool QgsGrass::writeRegion( QString gisbase,
QString location, QString mapset,
struct Cell_head *window );

// ! Set (copy) region extent, resolution is not changed
static void QgsGrass::copyRegionExtent( struct Cell_head *source,
struct Cell_head *target );

// ! Set (copy) region resolution, extent is not changed
static void QgsGrass::copyRegionResolution( struct Cell_head *source,
struct Cell_head *target );

// ! Extend region in target to source
static void QgsGrass::extendRegion( struct Cell_head *source,
struct Cell_head *target );

static void init (void);

//! Library version
static int QgsGrass::versionMajor();
static int QgsGrass::versionMinor();

private:
static int initialized; // Set to 1 after initialization
static bool active; // is active mode
Expand Down

0 comments on commit 7354757

Please sign in to comment.