grass icon indicating copy to clipboard operation
grass copied to clipboard

[Bug] Output r.what mixed up on Windows

Open ecodiv opened this issue 3 years ago • 8 comments

Describe the bug When running r.what on Windows, the output is mixed up on the command line. When printing to file, there is a line break, i.e., the coordinates and cat are printed on one line, the raster number and label on the next (see below).

To Reproduce Steps to reproduce the behavior (using NC dataset), run the following on the command line

v.extract input=points_of_interest@PERMANENT cats=846,638,815 output=test
v.out.ascii input=test format=point separator=space | r.what -f map=landuse

This gives the following output:

|5|forest793668|221428.92714025|638
|5|forest185879|221089.93863305|815
|1|developed724|221674.76921058|846

Printing to file

v.extract input=points_of_interest@PERMANENT cats=846,638,815 output=test
v.out.ascii input=test format=point separator=space | r.what -f map=landuse output=test_out_windows.txt

This gives a text file with the content looking like:

636960.09793668|221428.92714025|638
|5|forest
636961.12185879|221089.93863305|815
|5|forest
636733.24374724|221674.76921058|846
|1|developed

Expected behavior

The outcome (on the command line and as text in the text file) should look like (and does on my Linux computer) like:

636960.097936684499|221428.927140250133|638|5|forest
636961.121858786792|221089.938633049664|815|5|forest
636733.243747240631|221674.769210582715|846|1|developed

Screenshots

The problematic line endings are of type \r

image

System description (please complete the following information):

  • Operating System: Windows 10
  • GRASS GIS version 7.8.6
  • GRASS GIS 8.0.dev (ffb060a9c)

Additional context

On Linux r.what works as expected.

A workaround in Python, using .replace("\r", "")

point2ascii = Module(
        "v.out.ascii", input="test", 
        format="point",  
        separator="space", 
        stdout_=PIPE,
).outputs.stdout
rcats = Module(
        "r.what",
        flags="f", 
        map="landuse",
        stdin_=point2ascii, 
        stdout_=PIPE,
).outputs.stdout.replace("\r", "")
print(rcats)

Gives the desired outcome:

636960.097936684499|221428.927140250133|638|5|forest
636961.121858786792|221089.938633049664|815|5|forest
636733.243747240631|221674.769210582715|846|1|developed

ecodiv avatar Jan 15 '22 10:01 ecodiv

Since there is no PR yet, may we bump this to the milestone 8.0.1? Let's go and release 8.0.0.

neteler avatar Jan 25 '22 20:01 neteler

Since it has a straightforward workaround, let's not stop 8.0.0 because of it.

wenzeslaus avatar Jan 25 '22 21:01 wenzeslaus

@ecodiv Would you mind to propose a pull request with your suggested change?

neteler avatar Feb 28 '23 09:02 neteler

On February 28, 2023 14:45:20 Markus Neteler @.***> wrote:

@ecodiv Would you mind to propose a pull request with your suggested change?

I'm traveling but will do when back home

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

ecodiv avatar Mar 06 '23 03:03 ecodiv

Hi @neteler, the above was just about using post-processing the results in Python. However, not sure what has changed between 8.0 and 8.2.1, but the function now seems to work just fine. Perhaps good if somebody else can verify, but otherwise, this bug report can be closed.

ecodiv avatar Mar 17 '23 12:03 ecodiv

I think the best would be to review the existing tests and see if this case is covered, and enhance them if needed. The tests for r.what need a review anyway.

wenzeslaus avatar Mar 17 '23 13:03 wenzeslaus

tested with

GRASS version: 8.3.2                                                            
Code revision: exported                                                         
Build date: 2024-05-20                                                          
Build platform: x86_64-w64-mingw32                                              
GDAL: 3.9.0                                                                     
PROJ: 9.4.0                                                                     
GEOS: 3.12.1                                                                    
SQLite: 3.45.1                                                                  
Python: 3.12.4                                                                  
wxPython: 4.2.1                                                                 
Platform: Windows-11-10.0.22631-SP0 (OSGeo4W)             
r.what -f map=elevation@PERMANENT,landuse@PERMANENT,geology@PERMANENT points=elev_random@user1
637127.406308486|218683.533072994||93.44175||5|forest|217|CZfg
642028.961360735|221996.145373778||81.08843||1|developed|270|CZig
642462.435432521|221440.92182009||82.12705||5|forest|270|CZig
632235.183045549|228120.135009856||128.8752||5|forest|405|CZbg
634009.610646886|218779.249031151||104.5237||5|forest|217|CZfg
635090.389191026|222331.934811514||140.605||3|herbaceous|217|CZfg
642444.686872389|219999.696677265||89.15485||1|developed|270|CZig
635779.850575356|226501.69393888||149.6294||1|developed|217|CZfg
639165.310296154|226682.45275302||122.7894||1|developed|262|CZlg
640250.929114697|226643.029458669||119.2165||1|developed|262|CZlg

r.what -f map=elevation@PERMANENT,landuse@PERMANENT,geology@PERMANENT points=elev_random@user1 output=C:\wd\test_rwhat.txt

grafik

it seems to work here. closing issue?

hellik avatar Jun 16 '24 10:06 hellik

Is there now a test that touches that?

echoix avatar Jun 16 '24 21:06 echoix