GRASS7 vector provider

This commit is contained in:
Radim Blazek 2014-04-17 17:55:25 +02:00
parent ad1eaf7ae0
commit cbee1b5219
6 changed files with 614 additions and 506 deletions

View File

@ -10,8 +10,26 @@ MACRO (CHECK_GRASS G_PREFIX)
FIND_PATH (GRASS_INCLUDE_DIR grass/version.h ${G_PREFIX}/include)
FILE(READ ${GRASS_INCLUDE_DIR}/grass/version.h VERSIONFILE)
# We can avoid the following block using version_less version_equal and
# version_greater. Are there compatibility problems?
STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[^ ]+" GRASS_VERSION ${VERSIONFILE})
STRING(REGEX REPLACE "^([0-9]*)\\.[0-9]*\\..*$" "\\1" GRASS_MAJOR_VERSION ${GRASS_VERSION})
STRING(REGEX REPLACE "^[0-9]*\\.([0-9]*)\\..*$" "\\1" GRASS_MINOR_VERSION ${GRASS_VERSION})
STRING(REGEX REPLACE "^[0-9]*\\.[0-9]*\\.(.*)$" "\\1" GRASS_MICRO_VERSION ${GRASS_VERSION})
# Add micro version too?
# How to numerize RC versions?
MATH( EXPR GRASS_NUM_VERSION "${GRASS_MAJOR_VERSION}*10000 + ${GRASS_MINOR_VERSION}*100")
SET (GRASS_LIBRARIES_FOUND TRUE)
SET (GRASS_LIB_NAMES gis vect dig2 dbmiclient dbmibase shape dgl rtree datetime linkm form gproj)
SET (GRASS_LIB_NAMES gis dig2 dbmiclient dbmibase shape dgl rtree datetime linkm gproj)
IF (GRASS_MAJOR_VERSION LESS 7 )
LIST(APPEND GRASS_LIB_NAMES vect)
LIST(APPEND GRASS_LIB_NAMES form)
ELSE (GRASS_MAJOR_VERSION LESS 7 )
LIST(APPEND GRASS_LIB_NAMES vector)
LIST(APPEND GRASS_LIB_NAMES raster)
ENDIF (GRASS_MAJOR_VERSION LESS 7 )
FOREACH (LIB ${GRASS_LIB_NAMES})
MARK_AS_ADVANCED ( GRASS_LIBRARY_${LIB} )
@ -68,17 +86,6 @@ ENDIF (WITH_GRASS)
###################################
IF (GRASS_FOUND)
FILE(READ ${GRASS_INCLUDE_DIR}/grass/version.h VERSIONFILE)
# We can avoid the following block using version_less version_equal and
# version_greater. Are there compatibility problems?
STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[^ ]+" GRASS_VERSION ${VERSIONFILE})
STRING(REGEX REPLACE "^([0-9]*)\\.[0-9]*\\..*$" "\\1" GRASS_MAJOR_VERSION ${GRASS_VERSION})
STRING(REGEX REPLACE "^[0-9]*\\.([0-9]*)\\..*$" "\\1" GRASS_MINOR_VERSION ${GRASS_VERSION})
STRING(REGEX REPLACE "^[0-9]*\\.[0-9]*\\.(.*)$" "\\1" GRASS_MICRO_VERSION ${GRASS_VERSION})
# Add micro version too?
# How to numerize RC versions?
MATH( EXPR GRASS_NUM_VERSION "${GRASS_MAJOR_VERSION}*10000 + ${GRASS_MINOR_VERSION}*100")
IF (NOT GRASS_FIND_QUIETLY)
MESSAGE(STATUS "Found GRASS: ${GRASS_PREFIX} (${GRASS_VERSION})")
ENDIF (NOT GRASS_FIND_QUIETLY)

View File

@ -23,7 +23,9 @@ IF (POSTGRES_FOUND)
ENDIF (POSTGRES_FOUND)
IF (GRASS_FOUND)
ADD_SUBDIRECTORY(grass)
IF (GRASS_MAJOR_VERSION LESS 7 )
ADD_SUBDIRECTORY(grass)
ENDIF (GRASS_MAJOR_VERSION LESS 7 )
ENDIF (GRASS_FOUND)
IF (WITH_GLOBE)

File diff suppressed because it is too large Load Diff

View File

@ -37,11 +37,22 @@ extern "C"
#ifndef _MSC_VER
#include <unistd.h>
#endif
#include <grass/gprojects.h>
#include <grass/Vect.h>
#include <grass/version.h>
#include <grass/gprojects.h>
#if GRASS_VERSION_MAJOR < 7
#include <grass/Vect.h>
#else
#include <grass/vector.h>
#include <grass/raster.h>
#endif
}
#if GRASS_VERSION_MAJOR >= 7
#define G_suppress_masking Rast_suppress_masking
#define BOUND_BOX bound_box
#endif
#if !defined(GRASS_VERSION_MAJOR) || \
!defined(GRASS_VERSION_MINOR) || \
GRASS_VERSION_MAJOR<6 || \
@ -106,7 +117,10 @@ void GRASS_LIB_EXPORT QgsGrass::init( void )
// I think that mask should not be used in QGIS as it can only confuses people,
// anyway, I don't think anybody is using MASK
// TODO7: Rast_suppress_masking (see G_suppress_masking() macro above) needs MAPSET
#if GRASS_VERSION_MAJOR < 7
G_suppress_masking();
#endif
// Set program name
G_set_program_name( "QGIS" );
@ -1026,10 +1040,15 @@ bool GRASS_LIB_EXPORT QgsGrass::region( QString gisbase,
{
QgsGrass::setLocation( gisbase, location );
#if GRASS_VERSION_MAJOR < 7
if ( G__get_window( window, ( char * ) "", ( char * ) "WIND", mapset.toUtf8().data() ) )
{
return false;
}
#else
// TODO7: unfortunately G__get_window does not return error code and calls G_fatal_error on error
G__get_window( window, ( char * ) "", ( char * ) "WIND", mapset.toUtf8().data() );
#endif
return true;
}
@ -1141,6 +1160,7 @@ bool GRASS_LIB_EXPORT QgsGrass::mapRegion( int type, QString gisbase,
if ( type == Raster )
{
#if GRASS_VERSION_MAJOR < 7
if ( G_get_cellhd( map.toUtf8().data(),
mapset.toUtf8().data(), window ) < 0 )
{
@ -1148,6 +1168,10 @@ bool GRASS_LIB_EXPORT QgsGrass::mapRegion( int type, QString gisbase,
QObject::tr( "Cannot read raster map region" ) );
return false;
}
#else
// TODO7: unfortunately Rast_get_cellhd does not return error code and calls G_fatal_error on error
Rast_get_cellhd( map.toUtf8().data(), mapset.toUtf8().data(), window );
#endif
}
else if ( type == Vector )
{
@ -1193,6 +1217,7 @@ bool GRASS_LIB_EXPORT QgsGrass::mapRegion( int type, QString gisbase,
}
else if ( type == Region )
{
#if GRASS_VERSION_MAJOR < 7
if ( G__get_window( window, ( char * ) "windows",
map.toUtf8().data(),
mapset.toUtf8().data() ) != NULL )
@ -1201,6 +1226,10 @@ bool GRASS_LIB_EXPORT QgsGrass::mapRegion( int type, QString gisbase,
QObject::tr( "Cannot read region" ) );
return false;
}
#else
// TODO7: unfortunately G__get_window does not return error code and calls G_fatal_error on error
G__get_window( window, ( char * ) "windows", map.toUtf8().data(), mapset.toUtf8().data() );
#endif
}
return true;
}

View File

@ -25,9 +25,42 @@
extern "C"
{
#include <grass/version.h>
#if GRASS_VERSION_MAJOR < 7
#include <grass/Vect.h>
#else
#include <grass/vector.h>
#define BOUND_BOX bound_box
#endif
}
#if GRASS_VERSION_MAJOR < 7
#else
void copy_boxlist_and_destroy( struct boxlist *blist, struct ilist * list )
{
Vect_reset_list( list );
for ( int i = 0; i < blist->n_values; i++ )
{
Vect_list_append( list, blist->id[i] );
}
Vect_destroy_boxlist( blist );
}
#define Vect_select_lines_by_box(map, box, type, list) \
{ \
struct boxlist *blist = Vect_new_boxlist(0);\
Vect_select_lines_by_box( (map), (box), (type), blist); \
copy_boxlist_and_destroy( blist, (list) );\
}
#define Vect_select_areas_by_box(map, box, list) \
{ \
struct boxlist *blist = Vect_new_boxlist(0);\
Vect_select_areas_by_box( (map), (box), blist); \
copy_boxlist_and_destroy( blist, (list) );\
}
#endif
QgsGrassFeatureIterator::QgsGrassFeatureIterator( QgsGrassFeatureSource* source, bool ownSource, const QgsFeatureRequest& request )
: QgsAbstractFeatureIteratorFromSource( source, ownSource, request )

View File

@ -50,11 +50,16 @@
extern "C"
{
#include <grass/version.h>
#include <grass/gprojects.h>
#include <grass/gis.h>
#include <grass/dbmi.h>
#if GRASS_VERSION_MAJOR < 7
#include <grass/Vect.h>
#include <grass/version.h>
#else
#include <grass/vector.h>
#define BOUND_BOX bound_box
#endif
}
#ifdef _MSC_VER
@ -1041,7 +1046,12 @@ struct Map_info *QgsGrassProvider::layerMap( int layerId )
QgsCoordinateReferenceSystem QgsGrassProvider::crs()
{
// TODO7: enable/fix qgis.g.info
#if GRASS_VERSION_MAJOR < 7
return QgsGrass::crs( mGisdbase, mLocation );
#else
return QgsCoordinateReferenceSystem();
#endif
}
int QgsGrassProvider::grassLayer()