<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 27 October 2016 at 13:53, Moritz Lennert <span dir="ltr"><<a target="_blank" href="mailto:mlennert@club.worldonline.be">mlennert@club.worldonline.be</a>></span> wrote:<br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><span class="gmail-">On 27/10/16 12:51, James Duffy wrote:<br>
</span><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><span class="gmail-">
<br>
<br>
On 27 October 2016 at 11:45, Moritz Lennert<br></span><span class="gmail-">
<<a target="_blank" href="mailto:mlennert@club.worldonline.be">mlennert@club.worldonline.be</a> <mailto:<a target="_blank" href="mailto:mlennert@club.worldonline.be">mlennert@club.worldonl<wbr>ine.be</a>>> wrote:<br>
<br>
<br>
<br>
    Le 27 octobre 2016 12:35:14 GMT+02:00, James Duffy<br></span>
    <<a target="_blank" href="mailto:james.philip.duffy@gmail.com">james.philip.duffy@gmail.com</a> <mailto:<a target="_blank" href="mailto:james.philip.duffy@gmail.com">james.philip.duffy@gma<wbr>il.com</a>>><span class="gmail-"><br>
    a écrit :<br>
    >On 27 October 2016 at 11:08, Moritz Lennert<br></span>
    ><<a target="_blank" href="mailto:mlennert@club.worldonline.be">mlennert@club.worldonline.be</a> <mailto:<a target="_blank" href="mailto:mlennert@club.worldonline.be">mlennert@club.worldonl<wbr>ine.be</a>>><span class="gmail-"><br>
    >wrote:<br>
    ><br>
    >><br>
    >><br>
    >> Le 27 octobre 2016 11:22:02 GMT+02:00, James Duffy <<br>
    >> <a target="_blank" href="mailto:james.philip.duffy@gmail.com">james.philip.duffy@gmail.com</a><br></span>
    <mailto:<a target="_blank" href="mailto:james.philip.duffy@gmail.com">james.philip.duffy@gma<wbr>il.com</a>>> a écrit :<div><div class="gmail-h5"><br>
    >> >Hello,<br>
    >> ><br>
    >> >I'm trying to use i.segment.stats with GRASS 7.0.4 in the osgeolive<br>
    >> >32bit<br>
    >> >operating system.<br>
    >> ><br>
    >> >Prior to using this tool I have successfully created my segmented<br>
    >map<br>
    >> >using<br>
    >> >i.segment.<br>
    >> ><br>
    >> >When I try to execute the following command:<br>
    >> ><br>
    >> >i.segment.stats --overwrite --verbose map=gp_seg_optimum@gp1 \<br>
    >> >rasters=gp_ortho.1@gp1,gp_ort<wbr>ho.2@gp1,gp_ortho.3@gp1,gp_ort<wbr>ho.4@gp1<br>
    >\<br>
    >> >raster_statistics=min,max,mea<wbr>n,stddev,variance,sum \<br>
    >> >csvfile=/home/jpd205/Wales_GR<wbr>ASS/GarronPill/gp_seg_stats \<br>
    >> >separator=comma<br>
    >> ><br>
    >> >I get this error:<br>
    >> ><br>
    >> >Calculating geometry statistics<br>
    >> >ERROR: G_malloc: unable to allocate 4273800320 bytes of memory at<br>
    >> >       /tmp/tmpgzUtnA/r.object.geome<wbr>try/main.c:129<br>
    >><br>
    >> This is coming from r.object.geometry.<br>
    >><br>
    >> What are your region settings (g.region -p) ? How many segments do<br>
    >you<br>
    >> have ?<br>
    >><br>
    ><br>
    >GRASS 7.0.4 (GarronPill):~ > g.region -p<br>
    >projection: 99 (OSGB 1936 / British National Grid)<br>
    >zone:       0<br>
    >datum:      osgb36<br>
    >ellipsoid:  airy<br>
    >north:      208007.00931776<br>
    >south:      207952.59780698<br>
    >west:       200993.90853302<br>
    >east:       201097.28911076<br>
    >nsres:      0.00430914<br>
    >ewres:      0.00430914<br>
    >rows:       12627<br>
    >cols:       23991<br>
    >cells:      302934357<br>
<br>
    Are you sure 4mm is correct for the resolution ?<br>
<br>
<br>
Yes. It's high resolution imagery from a drone.<br>
<br>
<br>
<br></div></div>
    What does <a target="_blank" rel="noreferrer" href="http://r.info">r.info</a> <<a target="_blank" rel="noreferrer" href="http://r.info">http://r.info</a>> on<span class="gmail-"><br>
<br>
<br>
    ><br>
    ><br>
    >><br>
    >> Try running I.segment.stats without requesting form statistics.<br>
    ><br>
    ><br>
    >Running:<br>
    ><br>
    >i.segment.stats --overwrite --verbose map=gp_seg_optimum@gp1 \<br>
    >csvfile=/home/jpd205/Wales_GR<wbr>ASS/GarronPill/gp_seg_stats \<br>
    >separator=comma<br>
<br>
    Default is to do form statistics, so the above line also does. I<br>
    have to admit that I don't know what happens when you give an empty<br>
    parameter such as<br>
<br>
    area_measures= or area_measures=""<br>
<br></span>
    What does <a target="_blank" rel="noreferrer" href="http://r.info">r.info</a> <<a target="_blank" rel="noreferrer" href="http://r.info">http://r.info</a>> gp_seg_optimum give you ?<div><div class="gmail-h5"><br>
<br>
<br>
+-----------------------------<wbr>------------------------------<wbr>-----------------+<br>
 | Map:      gp_seg_optimum                 Date: Thu Oct 27 06:45:57<br>
2016    |<br>
 | Mapset:   gp1                            Login of Creator:<br>
jpd205          |<br>
 | Location:<br>
GarronPill                                                       |<br>
 | DataBase:<br>
/home/jpd205/Wales_GRASS                                         |<br>
 | Title:     ( gp_seg_optimum<br>
)                                              |<br>
 | Timestamp:<br>
none                                                            |<br>
 |----------------------------<wbr>------------------------------<wbr>------------------|<br>
 |<br>
|<br>
 |   Type of Map:  raster               Number of Categories:<br>
0               |<br>
 |   Data Type:<br>
CELL                                                       |<br>
 |   Rows:<br>
12627                                                      |<br>
 |   Columns:<br>
23991                                                      |<br>
 |   Total Cells:<br>
302934357                                                  |<br>
 |        Projection: OSGB 1936 / British National<br>
Grid                       |<br>
 |            N: 208007.00931776    S: 207952.59780698   Res:<br>
0.00430914      |<br>
 |            E: 201097.28911076    W: 200993.90853302   Res:<br>
0.00430914      |<br>
 |   Range of data:    min = 35  max =<br>
133556294                              |<br>
 |<br>
</div></div></blockquote>
<br>
Ok, I think I see at least part of the problem: in GRASS 7.0 i.segment numbers segments non sequentially, i.e. whenever a new segment is created out of the merger of two existing segments, a new id is assigned. In GRASS trunk (the development version) i.segment is rewritten to, at the end, number all segments sequentially from 1 to the number of segments.<br>
<br>
r.object.geometry allocates memory according to the new system. As it says in the code:<br>
<br>
    /* REMARK: The following is only true if object ids are continuously numbered */<br>
    n_objects = max - min + 1;<br>
    obj_geos = G_malloc(n_objects * sizeof(struct obj_geo));<br>
<br>
So, one solution would be to use the development version of GRASS. </blockquote><div> </div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">Another would be to run r.clump on the result of the segmentation in order to renumber the segments before running it through i.segment.stats.<br></blockquote><div><br></div><div>This option seemed the most straightforward given my current setup. I ran r.clump with diagnoal enabled, and the output looked good. It only took 2mins to run.<br><br></div><div>I then proceeded with the original i.segment.stats command and got the following:<br><br>Calculating geometry statistics<br>Calculating statistics for raster gp_ortho.1@gp1<br>ERROR: G_realloc: unable to allocate 572000 bytes of memory at<br>       raster/r.univar/r.univar_main.c:324<br><br></div><div>It looks like the tool got further, but is still getting stuck on something...<br></div><div><br><br></div><div> </div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">
<br>
A third option, potentially a bit faster than the second, would be to write a little script which gets all category values from the segment map (using r.category), and reassigns sequential category values to those using r.reclass. I.e. something like this:<br>
<br>
r.category segment_map | awk 'BEGIN{cat=1} {printf"%d=%d\n", $1, cat; cat++}' | r.reclass segment_map out=sequential_segment_map rules=-<br>
<br>
Moritz<br>
<br>
</blockquote></div><br></div><div class="gmail_extra">James<br clear="all"></div></div>