Skip to content
Permalink
Browse files
GRASS 7 raster provider
  • Loading branch information
blazek committed May 22, 2014
1 parent 1c52f09 commit bf6effdd67b80a37aa01b9f0458a3f6098f31d72
@@ -570,36 +570,49 @@ TARGET_LINK_LIBRARIES(grassrasterprovider qgisgrass qgis_core)
# the modules go under libexec subdir
SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_LIBEXEC_SUBDIR}/grass/modules)

# TODO: upgrade to GRASS 7
#
# grass raster display module
#
ADD_EXECUTABLE(qgis.d.rast qgis.d.rast.c)
IF (GRASS_MAJOR_VERSION LESS 7 )

#
# grass raster display module
#

ADD_EXECUTABLE(qgis.d.rast qgis.d.rast.c)
TARGET_LINK_LIBRARIES(qgis.d.rast
${GRASS_LIBRARY_gis}
${GRASS_LIBRARY_datetime}
${GDAL_LIBRARY}
)
ELSE (GRASS_MAJOR_VERSION LESS 7 )
TARGET_LINK_LIBRARIES(qgis.d.rast
${GRASS_LIBRARY_gis}
${GRASS_LIBRARY_datetime}
${GRASS_LIBRARY_raster}
${GDAL_LIBRARY}
)
ENDIF (GRASS_MAJOR_VERSION LESS 7 )

#
# grass info module
#
#
# grass info module
#

ADD_EXECUTABLE(qgis.g.info qgis.g.info.c)
ADD_EXECUTABLE(qgis.g.info qgis.g.info.c)
IF (GRASS_MAJOR_VERSION LESS 7 )
TARGET_LINK_LIBRARIES(qgis.g.info
${GRASS_LIBRARY_gis}
${GRASS_LIBRARY_datetime}
${GRASS_LIBRARY_gproj}
${GDAL_LIBRARY}
)
IF (UNIX)
TARGET_LINK_LIBRARIES(qgis.g.info m)
ENDIF (UNIX)

ELSE (GRASS_MAJOR_VERSION LESS 7 )
TARGET_LINK_LIBRARIES(qgis.g.info
${GRASS_LIBRARY_gis}
${GRASS_LIBRARY_datetime}
${GRASS_LIBRARY_gproj}
${GRASS_LIBRARY_raster}
${GDAL_LIBRARY}
)
ENDIF (GRASS_MAJOR_VERSION LESS 7 )
IF (UNIX)
TARGET_LINK_LIBRARIES(qgis.g.info m)
ENDIF (UNIX)

########################################################
# Install
@@ -617,14 +630,11 @@ INSTALL(TARGETS grassprovider
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})

# TODO: upgrade to GRASS 7
IF (GRASS_MAJOR_VERSION LESS 7 )
INSTALL(TARGETS grassrasterprovider
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
INSTALL(TARGETS grassrasterprovider
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})

INSTALL(TARGETS qgis.d.rast qgis.g.info
RUNTIME DESTINATION ${QGIS_LIBEXEC_DIR}/grass/modules
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
INSTALL(TARGETS qgis.d.rast qgis.g.info
RUNTIME DESTINATION ${QGIS_LIBEXEC_DIR}/grass/modules
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
ENDIF (GRASS_MAJOR_VERSION LESS 7 )
@@ -33,6 +33,7 @@
#include <fcntl.h>
#include <io.h>
#endif
#include <grass/version.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/display.h>
@@ -43,6 +44,23 @@
#define NAN (INFINITY-INFINITY)
#endif

#if GRASS_VERSION_MAJOR >= 7
#define G_allocate_raster_buf Rast_allocate_buf
#define G_close_cell Rast_close
#define G_free_colors Rast_free_colors
#define G_get_cellhd Rast_get_cellhd
#define G_get_raster_map_type Rast_get_map_type
#define G_get_raster_row Rast_get_row
#define G_is_null_value Rast_is_null_value
#define G_lookup_raster_colors Rast_lookup_colors
#define G_open_cell_old Rast_open_old
#define G_raster_map_type Rast_map_type
#define G_raster_size Rast_cell_size
#define G_read_colors Rast_read_colors
#define G_window_cols Rast_window_cols
#define G_window_rows Rast_window_rows
#endif

int display( char *name, char *mapset, RASTER_MAP_TYPE data_type, char *format );

int main( int argc, char **argv )
@@ -84,9 +102,13 @@ int main( int argc, char **argv )
name = map->answer;

/* Make sure map is available */
#if GRASS_VERSION_MAJOR < 7
mapset = G_find_cell2( name, "" );
if ( mapset == NULL )
G_fatal_error(( "Raster map <%s> not found" ), name );
#else
mapset = "";
#endif

/* It can happen that GRASS data set is 'corrupted' and zone differs in WIND and
* cellhd, and G_open_cell_old fails, so it is better to read window from map */
@@ -28,11 +28,34 @@
#include <stdio.h>
#include <string.h>
#include <float.h>
#include <grass/version.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/display.h>
#include <grass/gprojects.h>

#if GRASS_VERSION_MAJOR >= 7
#define G_allocate_c_raster_buf Rast_allocate_c_buf
#define G_allocate_d_raster_buf Rast_allocate_d_buf
#define G_close_cell Rast_close
#define G_colors_count Rast_colors_count
#define G_easting_to_col Rast_easting_to_col
#define G_get_c_raster_row Rast_get_c_row
#define G_get_cellhd Rast_get_cellhd
#define G_get_d_raster_row Rast_get_d_row
#define G_get_f_color_rule Rast_get_fp_color_rule
#define G_get_fp_range_min_max Rast_get_fp_range_min_max
#define G_get_raster_map_type Rast_get_map_type
#define G_is_null_value Rast_is_null_value
#define G_northing_to_row Rast_northing_to_row
#define G_open_cell_old Rast_open_old
#define G_raster_map_type Rast_map_type
#define G_read_colors Rast_read_colors
#define G_read_fp_range Rast_read_fp_range
#define G_window_cols Rast_window_cols
#define G_window_rows Rast_window_rows
#endif

int main( int argc, char **argv )
{
struct GModule *module;
@@ -226,21 +249,29 @@ int main( int argc, char **argv )

if ( rast_type == CELL_TYPE )
{
#if GRASS_VERSION_MAJOR < 7
if ( G_get_c_raster_row( fd, cell, row ) < 0 )
{
G_fatal_error(( "Unable to read raster map <%s> row %d" ),
rast_opt->answer, row );
}
#else
G_get_c_raster_row( fd, cell, row );
#endif
val = cell[col];
ptr = &( cell[col] );
}
else
{
#if GRASS_VERSION_MAJOR < 7
if ( G_get_d_raster_row( fd, dcell, row ) < 0 )
{
G_fatal_error(( "Unable to read raster map <%s> row %d" ),
rast_opt->answer, row );
}
#else
G_get_d_raster_row( fd, dcell, row );
#endif
val = dcell[col];
ptr = &( dcell[col] );
}
@@ -312,19 +343,27 @@ int main( int argc, char **argv )
{
if ( rast_type == CELL_TYPE )
{
#if GRASS_VERSION_MAJOR < 7
if ( G_get_c_raster_row( fd, cell, row ) < 0 )
{
G_fatal_error(( "Unable to read raster map <%s> row %d" ),
rast_opt->answer, row );
}
#else
G_get_c_raster_row( fd, cell, row );
#endif
}
else
{
#if GRASS_VERSION_MAJOR < 7
if ( G_get_d_raster_row( fd, dcell, row ) < 0 )
{
G_fatal_error(( "Unable to read raster map <%s> row %d" ),
rast_opt->answer, row );
}
#else
G_get_d_raster_row( fd, dcell, row );
#endif
}

for ( col = 0; col < ncols; col++ )
@@ -1046,12 +1046,7 @@ 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()

0 comments on commit bf6effd

Please sign in to comment.