Hi Glynn, Martin,  Hamish and rest of GRASS mailing list<div>Thanks for your feedback. Unfortunely, I was &quot;analyzing&quot; my problem in the wrong way...</div><div>WHat I need is to:</div><div>- Export raster values in an ASCII file written from left to right and bottom to top and each line only includes Raster value (not X neither Y). </div>
<div>Is this possible in GRASS with a Python Script?</div><div><br></div><div>Also I will need to import raster values written in ASCII file written from left to right and bottom to top where each line is a single raster value without X and Y.</div>
<div><br></div><div>Is there any easy-to-implement solution?</div><div>Thanks</div><div><br>Best regards and sorry for my previous mistake,</div><div>Kim<br><br><div class="gmail_quote">2011/3/9 Glynn Clements <span dir="ltr">&lt;<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im"><br>
Martin Landa wrote:<br>
<br>
&gt; &gt; so just flipping all the rows in the file you can get now?<br>
&gt; &gt;<br>
&gt; &gt; don&#39;t know how to do that in python, but if unix shell powertools are<br>
&gt; &gt; available:<br>
&gt; &gt;   r.out.ascii | tac<br>
<br>
</div><div class="im">&gt; print os.linesep.join(reversed(grass.read_command(&#39;r.out.ascii&#39;,<br>
<br>
</div>FWIW, both of these are sub-optimal.<br>
<br>
The Python approach reads everything into memory then generates a<br>
reversed copy, so you need enough memory to hold two copies of the<br>
output from r.out.ascii.<br>
<br>
When given a file, tac reads the input file backwards a block at a<br>
time, so it only needs enough memory to hold a complete line, rounded<br>
up to a whole number of blocks.<br>
<br>
However, it can&#39;t do this when reading from a pipe; it has to store<br>
everything in memory.<br>
<br>
If you want to reverse a large file without storing everything in<br>
memory, the simplest solution is e.g.:<br>
<br>
        r.out.ascii ... &gt; tmp.txt<br>
        tac tmp.txt &gt; reversed.txt<br>
        rm tmp.txt<br>
<br>
If this was likely to be a common operation, r.out.ascii could easily<br>
be modified to flip the row number passed to Rast_get_row(). However,<br>
while that will be optimal for native GRASS rasters, it may be<br>
sub-optimal (or even fail) for &quot;linked&quot; (r.external) rasters; many<br>
raster formats have to be read top-to-bottom (I don&#39;t know how GDAL<br>
handles out-of-order reads for such formats).<br>
<font color="#888888"><br>
--<br>
Glynn Clements &lt;<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>&gt;<br>
</font></blockquote></div><br></div>