Skip to content

Commit bf6effd

Browse files
committed
GRASS 7 raster provider
1 parent 1c52f09 commit bf6effd

File tree

4 files changed

+95
-29
lines changed

4 files changed

+95
-29
lines changed

src/providers/grass/CMakeLists.txt

+34-24
Original file line numberDiff line numberDiff line change
@@ -570,36 +570,49 @@ TARGET_LINK_LIBRARIES(grassrasterprovider qgisgrass qgis_core)
570570
# the modules go under libexec subdir
571571
SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_LIBEXEC_SUBDIR}/grass/modules)
572572

573-
# TODO: upgrade to GRASS 7
573+
#
574+
# grass raster display module
575+
#
576+
ADD_EXECUTABLE(qgis.d.rast qgis.d.rast.c)
574577
IF (GRASS_MAJOR_VERSION LESS 7 )
575-
576-
#
577-
# grass raster display module
578-
#
579-
580-
ADD_EXECUTABLE(qgis.d.rast qgis.d.rast.c)
581578
TARGET_LINK_LIBRARIES(qgis.d.rast
582579
${GRASS_LIBRARY_gis}
583580
${GRASS_LIBRARY_datetime}
584581
${GDAL_LIBRARY}
585582
)
583+
ELSE (GRASS_MAJOR_VERSION LESS 7 )
584+
TARGET_LINK_LIBRARIES(qgis.d.rast
585+
${GRASS_LIBRARY_gis}
586+
${GRASS_LIBRARY_datetime}
587+
${GRASS_LIBRARY_raster}
588+
${GDAL_LIBRARY}
589+
)
590+
ENDIF (GRASS_MAJOR_VERSION LESS 7 )
586591

587-
#
588-
# grass info module
589-
#
592+
#
593+
# grass info module
594+
#
590595

591-
ADD_EXECUTABLE(qgis.g.info qgis.g.info.c)
596+
ADD_EXECUTABLE(qgis.g.info qgis.g.info.c)
597+
IF (GRASS_MAJOR_VERSION LESS 7 )
592598
TARGET_LINK_LIBRARIES(qgis.g.info
593599
${GRASS_LIBRARY_gis}
594600
${GRASS_LIBRARY_datetime}
595601
${GRASS_LIBRARY_gproj}
596602
${GDAL_LIBRARY}
597603
)
598-
IF (UNIX)
599-
TARGET_LINK_LIBRARIES(qgis.g.info m)
600-
ENDIF (UNIX)
601-
604+
ELSE (GRASS_MAJOR_VERSION LESS 7 )
605+
TARGET_LINK_LIBRARIES(qgis.g.info
606+
${GRASS_LIBRARY_gis}
607+
${GRASS_LIBRARY_datetime}
608+
${GRASS_LIBRARY_gproj}
609+
${GRASS_LIBRARY_raster}
610+
${GDAL_LIBRARY}
611+
)
602612
ENDIF (GRASS_MAJOR_VERSION LESS 7 )
613+
IF (UNIX)
614+
TARGET_LINK_LIBRARIES(qgis.g.info m)
615+
ENDIF (UNIX)
603616

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

620-
# TODO: upgrade to GRASS 7
621-
IF (GRASS_MAJOR_VERSION LESS 7 )
622-
INSTALL(TARGETS grassrasterprovider
623-
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
624-
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
633+
INSTALL(TARGETS grassrasterprovider
634+
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
635+
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
625636

626-
INSTALL(TARGETS qgis.d.rast qgis.g.info
627-
RUNTIME DESTINATION ${QGIS_LIBEXEC_DIR}/grass/modules
628-
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
637+
INSTALL(TARGETS qgis.d.rast qgis.g.info
638+
RUNTIME DESTINATION ${QGIS_LIBEXEC_DIR}/grass/modules
639+
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
629640
)
630-
ENDIF (GRASS_MAJOR_VERSION LESS 7 )

src/providers/grass/qgis.d.rast.c

+22
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <fcntl.h>
3434
#include <io.h>
3535
#endif
36+
#include <grass/version.h>
3637
#include <grass/gis.h>
3738
#include <grass/raster.h>
3839
#include <grass/display.h>
@@ -43,6 +44,23 @@
4344
#define NAN (INFINITY-INFINITY)
4445
#endif
4546

47+
#if GRASS_VERSION_MAJOR >= 7
48+
#define G_allocate_raster_buf Rast_allocate_buf
49+
#define G_close_cell Rast_close
50+
#define G_free_colors Rast_free_colors
51+
#define G_get_cellhd Rast_get_cellhd
52+
#define G_get_raster_map_type Rast_get_map_type
53+
#define G_get_raster_row Rast_get_row
54+
#define G_is_null_value Rast_is_null_value
55+
#define G_lookup_raster_colors Rast_lookup_colors
56+
#define G_open_cell_old Rast_open_old
57+
#define G_raster_map_type Rast_map_type
58+
#define G_raster_size Rast_cell_size
59+
#define G_read_colors Rast_read_colors
60+
#define G_window_cols Rast_window_cols
61+
#define G_window_rows Rast_window_rows
62+
#endif
63+
4664
int display( char *name, char *mapset, RASTER_MAP_TYPE data_type, char *format );
4765

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

86104
/* Make sure map is available */
105+
#if GRASS_VERSION_MAJOR < 7
87106
mapset = G_find_cell2( name, "" );
88107
if ( mapset == NULL )
89108
G_fatal_error(( "Raster map <%s> not found" ), name );
109+
#else
110+
mapset = "";
111+
#endif
90112

91113
/* It can happen that GRASS data set is 'corrupted' and zone differs in WIND and
92114
* cellhd, and G_open_cell_old fails, so it is better to read window from map */

src/providers/grass/qgis.g.info.c

+39
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,34 @@
2828
#include <stdio.h>
2929
#include <string.h>
3030
#include <float.h>
31+
#include <grass/version.h>
3132
#include <grass/gis.h>
3233
#include <grass/raster.h>
3334
#include <grass/display.h>
3435
#include <grass/gprojects.h>
3536

37+
#if GRASS_VERSION_MAJOR >= 7
38+
#define G_allocate_c_raster_buf Rast_allocate_c_buf
39+
#define G_allocate_d_raster_buf Rast_allocate_d_buf
40+
#define G_close_cell Rast_close
41+
#define G_colors_count Rast_colors_count
42+
#define G_easting_to_col Rast_easting_to_col
43+
#define G_get_c_raster_row Rast_get_c_row
44+
#define G_get_cellhd Rast_get_cellhd
45+
#define G_get_d_raster_row Rast_get_d_row
46+
#define G_get_f_color_rule Rast_get_fp_color_rule
47+
#define G_get_fp_range_min_max Rast_get_fp_range_min_max
48+
#define G_get_raster_map_type Rast_get_map_type
49+
#define G_is_null_value Rast_is_null_value
50+
#define G_northing_to_row Rast_northing_to_row
51+
#define G_open_cell_old Rast_open_old
52+
#define G_raster_map_type Rast_map_type
53+
#define G_read_colors Rast_read_colors
54+
#define G_read_fp_range Rast_read_fp_range
55+
#define G_window_cols Rast_window_cols
56+
#define G_window_rows Rast_window_rows
57+
#endif
58+
3659
int main( int argc, char **argv )
3760
{
3861
struct GModule *module;
@@ -226,21 +249,29 @@ int main( int argc, char **argv )
226249

227250
if ( rast_type == CELL_TYPE )
228251
{
252+
#if GRASS_VERSION_MAJOR < 7
229253
if ( G_get_c_raster_row( fd, cell, row ) < 0 )
230254
{
231255
G_fatal_error(( "Unable to read raster map <%s> row %d" ),
232256
rast_opt->answer, row );
233257
}
258+
#else
259+
G_get_c_raster_row( fd, cell, row );
260+
#endif
234261
val = cell[col];
235262
ptr = &( cell[col] );
236263
}
237264
else
238265
{
266+
#if GRASS_VERSION_MAJOR < 7
239267
if ( G_get_d_raster_row( fd, dcell, row ) < 0 )
240268
{
241269
G_fatal_error(( "Unable to read raster map <%s> row %d" ),
242270
rast_opt->answer, row );
243271
}
272+
#else
273+
G_get_d_raster_row( fd, dcell, row );
274+
#endif
244275
val = dcell[col];
245276
ptr = &( dcell[col] );
246277
}
@@ -312,19 +343,27 @@ int main( int argc, char **argv )
312343
{
313344
if ( rast_type == CELL_TYPE )
314345
{
346+
#if GRASS_VERSION_MAJOR < 7
315347
if ( G_get_c_raster_row( fd, cell, row ) < 0 )
316348
{
317349
G_fatal_error(( "Unable to read raster map <%s> row %d" ),
318350
rast_opt->answer, row );
319351
}
352+
#else
353+
G_get_c_raster_row( fd, cell, row );
354+
#endif
320355
}
321356
else
322357
{
358+
#if GRASS_VERSION_MAJOR < 7
323359
if ( G_get_d_raster_row( fd, dcell, row ) < 0 )
324360
{
325361
G_fatal_error(( "Unable to read raster map <%s> row %d" ),
326362
rast_opt->answer, row );
327363
}
364+
#else
365+
G_get_d_raster_row( fd, dcell, row );
366+
#endif
328367
}
329368

330369
for ( col = 0; col < ncols; col++ )

src/providers/grass/qgsgrassprovider.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -1046,12 +1046,7 @@ struct Map_info *QgsGrassProvider::layerMap( int layerId )
10461046

10471047
QgsCoordinateReferenceSystem QgsGrassProvider::crs()
10481048
{
1049-
// TODO7: enable/fix qgis.g.info
1050-
#if GRASS_VERSION_MAJOR < 7
10511049
return QgsGrass::crs( mGisdbase, mLocation );
1052-
#else
1053-
return QgsCoordinateReferenceSystem();
1054-
#endif
10551050
}
10561051

10571052
int QgsGrassProvider::grassLayer()

0 commit comments

Comments
 (0)