Coder Social home page Coder Social logo

Comments (6)

dhdeangelis avatar dhdeangelis commented on June 19, 2024

You need to add the -d flag to your command to achieve your expected results:

-d Force output to 'double' raster map type (DCELL)

Try:

echo "0.0:18.7:0.0:1.0" | r.recode -d input=myinput output=myoutput rules=-

from grass.

ecodiv avatar ecodiv commented on June 19, 2024

You need to add the -d flag to your command to achieve your expected results:

-d Force output to 'double' raster map type (DCELL)

Try:

echo "0.0:18.7:0.0:1.0" | r.recode -d input=myinput output=myoutput rules=-

Thanks. I know you can use the -d flag (and I wrote that in the bug report), but the point I was trying to make is that based on the manual, I would not necessarily expect r.recode to convert the floating map to an integer map, as I used decimal numbers for the new minimum and maximum value. I think that either the behavior should be changed, or the behavior (when does the function change the data type) should be explained more explicitly.

from grass.

dhdeangelis avatar dhdeangelis commented on June 19, 2024

I know you can use the -d flag (and I wrote that in the bug report)

I see, I missed that.

based on the manual, I would not necessarily expect r.recode to convert the floating map to an integer map, as I used decimal numbers for the new minimum and maximum value. I think that either the behavior should be changed, or the behavior (when does the function change the data type) should be explained more explicitly.

I agree with this. I also find the manual confusing on this regard. The manual first states that r.recode is for recoding categorical maps, which it seems to be made for, but then gives an example of rescaling, for which r.mapcalc is more convenient.

from grass.

ninsbl avatar ninsbl commented on June 19, 2024

This seems like a bug to me.

r.recode appears to be intended to produce FCELL results too. See e.g.: https://github.com/OSGeo/grass/blob/25961a86c26765f293d582900b00bb37403a780d/raster/r.recode/read_rules.c#L143C25-L143C29

from grass.

dhdeangelis avatar dhdeangelis commented on June 19, 2024

It seems that the problem lies in parsing or managing the input, as numbers ending in zero are not interpreted as float.

Example:
echo "0.0:18.7:0.0:1.0" | r.recode input=r output=test rules=- --overwrite
produces a raster of type CELL
while
echo "0.0:18.7:0.01:1.0" | r.recode input=r output=test rules=- --overwrite
or
echo "0.0:18.7:0.0:1.01" | r.recode input=r output=test rules=- --overwrite
produce rasters of type FCELL

Edit: deleted reference to rules, as I could not trace the exact source of the problem.

from grass.

dhdeangelis avatar dhdeangelis commented on June 19, 2024

It seems to me that this part in read_rules.c is not working as intended:

int update_type(RASTER_MAP_TYPE *map_type, DCELL val)
{
/* check if val is not an integer number */
if (make_dcell)
*map_type = DCELL_TYPE;
else {
if ((DCELL)((CELL)val) != val)
*map_type = FCELL_TYPE;
}
return 0;
}

Perhaps line 142 could be replaced with a call to a function to tell if val is a float or integer. . I am not so fluent in C but it seems that is not so straightforward.

A simple work around could be to default output to integer, unless it is forced to double using the -d switch, or to float using a new switch, for example: -f. This I just tested and works. But it is perhaps not the expected behaviour? Also it adds a new switch and may break backwards compatibility.

from grass.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.