On 11 May 2018 at 10:54, Markus Metz <markus.metz.gisw...@gmail.com> wrote:
> Hi Luca,
>

Hi Markus,

> On Fri, May 11, 2018 at 10:26 AM, Luca Delucchi <lucadel...@gmail.com>
> wrote:
>>
>> Hi devs,
>>
>> I would like to remove a raster map inside a C module, looking aroung
>> I found the M_do_remove function used in g.remove and r.reclass. So I
>> tried to use it but I get error in compilation
>>
>> OBJ.x86_64-pc-linux-gnu/main.o: In function `main':
>> main.c:(.text.startup+0x9eb): undefined reference to `M_get_element'
>> main.c:(.text.startup+0x9f5): undefined reference to `M_do_remove'
>> collect2: error: ld returned 1 exit status
>
> this is a problem of the linker: you need to link against the manage lib,
> see e.g. the Makefile for g.remove. Try
>
> LIBES = $(MANAGELIB) $(RASTERLIB) $(GISLIB)
> DEPENDENCIES = $(MANAGEDEP) $(RASTERDEP) $(GISDEP)
>
> in the Makefile of your module.
>

thanks, now it compile but I get "Segmentation fault", the module is
r.tile, I attached the diff, could someone have a look to it please?

> HTH,
>
> Markus M
>



-- 
ciao
Luca

www.lucadelu.org
Index: raster/r.tile/Makefile
===================================================================
--- raster/r.tile/Makefile	(revision 72704)
+++ raster/r.tile/Makefile	(working copy)
@@ -2,8 +2,8 @@
 
 PGM = r.tile
 
-LIBES = $(RASTERLIB) $(GISLIB)
-DEPENDENCIES = $(RASTERDEP) $(GISDEP)
+LIBES = $(MANAGELIB) $(RASTERLIB) $(GISLIB)
+DEPENDENCIES = $(MANAGEDEP) $(RASTERDEP) $(GISDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 
Index: raster/r.tile/main.c
===================================================================
--- raster/r.tile/main.c	(revision 72704)
+++ raster/r.tile/main.c	(working copy)
@@ -15,12 +15,15 @@
 #include <stdlib.h>
 #include <grass/gis.h>
 #include <grass/raster.h>
+#include <grass/manage.h>
 #include <grass/glocale.h>
+#include <grass/calc.h>
 
 static struct
 {
     struct Option *rastin, *rastout, *width, *height, *overlap;
 } parm;
+
 static struct Cell_head dst_w, src_w, ovl_w;
 static int xtiles, ytiles;
 static RASTER_MAP_TYPE map_type;
@@ -30,6 +33,9 @@
 int main(int argc, char *argv[])
 {
     struct GModule *module;
+    struct Range int_range;
+    struct FPRange fp_range;
+    struct Flag *flag;
     int infile;
     const char *mapset;
     size_t cell_size;
@@ -75,6 +81,10 @@
     parm.overlap->multiple = NO;
     parm.overlap->description = _("Overlap of tiles");
 
+    flag = G_define_flag();
+    flag->key = 'n';
+    flag->description = _("Does not create tiles having only NULL values");
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -149,8 +159,31 @@
 	}
 
 	for (xtile = 0; xtile < xtiles; xtile++) {
-	    Rast_close(outfiles[xtile]);
-	    write_support_files(xtile, ytile, overlap);
+            Rast_close(outfiles[xtile]);
+            write_support_files(xtile, ytile, overlap);
+            if (flag->answer){
+                char name[GNAME_MAX];
+                sprintf(name, "%s-%03d-%03d", parm.rastout->answer, ytile, xtile);
+                if (map_type == CELL_TYPE) {
+                    CELL min, max;
+                    Rast_read_range(name, G_mapset(), &int_range);
+                    min = int_range.min;
+                    max = int_range.max;
+                    if (IS_NULL_C(&min) && IS_NULL_C(&max)){
+                        M_do_remove(M_get_element("raster"), name);
+                        G_debug(0, "Removed empty tile %s", name);
+                    }
+                } else {
+                    DCELL min, max;
+                    Rast_read_fp_range(name, mapset, &fp_range);
+                    min = fp_range.min;
+                    max = fp_range.max;
+                    if (IS_NULL_D(&min) && IS_NULL_D(&max)){
+                        M_do_remove(M_get_element("raster"), name);
+                        G_debug(0, "Removed empty tile %s", name);
+                    }
+                }
+            }
 	}
     }
 
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to