Hi Glynn, Martin, Hamish and rest of GRASS mailing list<div>Thanks for your feedback. Unfortunely, I was "analyzing" 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"><<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>></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>
> > so just flipping all the rows in the file you can get now?<br>
> ><br>
> > don't know how to do that in python, but if unix shell powertools are<br>
> > available:<br>
> > r.out.ascii | tac<br>
<br>
</div><div class="im">> print os.linesep.join(reversed(grass.read_command('r.out.ascii',<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'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 ... > tmp.txt<br>
tac tmp.txt > 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 "linked" (r.external) rasters; many<br>
raster formats have to be read top-to-bottom (I don't know how GDAL<br>
handles out-of-order reads for such formats).<br>
<font color="#888888"><br>
--<br>
Glynn Clements <<a href="mailto:glynn@gclements.plus.com">glynn@gclements.plus.com</a>><br>
</font></blockquote></div><br></div>