Re: [GRASS-user] compare a DCELL and FCELL question
Zoltan <[email protected]>
| Newsgroups | gmane.comp.gis.grass.devel |
|---|---|
| Organization | Geograph (Pty) Ltd |
| Message-ID | <[email protected]> |
No inconvenience - general list etiquette usually says start with 'user' and then move to 'dev' if it looks like a SW issue. But I am NOT lecturing you, so please do not take offense. Keep well, Zoltan On 2021-01-24 18:28, ming han wrote: > sorry for the inconvenience. I was just not sure if it is problem that > needs developers to answer. > Best regards > Ming > > Zoltan <[email protected] <mailto:[email protected]>> > 于2021年1月24日周日 上午11:13写道: > > Hi, > Is it important to cross-post this discussion on both dev and user > lists? > > Regards, > Zoltan > > > On 2021-01-24 17:56, Markus Metz wrote: >> Trying to answer the original question: with a DCELL map >> "cat1_acc_riv" and a FCELL map "cat1_minacc", why is >> "float(cat1_acc_riv) == float(cat1_minacc)" not equal to >> "int(cat1_acc_riv) == int(cat1_minacc)" ? >> >> int truncates to integer while float converts to single precision >> floating point. E.g. with cat1_acc_riv = 1.1 and cat1_minacc = >> 1.9, "float(cat1_acc_riv) == float(cat1_minacc)" becomes "1.1 == >> 1.9" whereas "int(cat1_acc_riv) == int(cat1_minacc)" becomes "1 >> == 1", thus the results are different. >> >> Another reason for possible differences is that float can only >> represent max 7 decimal digits. E.g. float(194320567) becomes >> 194320560 but int(194320567) preserves the value 194320567. >> >> Thus the safest is to cast everything to the type with the >> highest precision. In this case with FCELL and DCELL, use >> "double(cat1_acc_riv) == double(cat1_minacc)" or even better the >> suggestion of Markus N. >> >> Markus M >> >> >> On Sun, Jan 24, 2021 at 3:51 PM ming han <[email protected] >> <mailto:[email protected]>> wrote: >> > >> > Hi Markus and Micha >> > >> > I am just trying to find grids have the same values in >> these two rasters, I will try the threshold approach. >> > >> > Thanks >> > Ming >> > >> > Markus Neteler <[email protected] <mailto:[email protected]>> >> 于2021年1月24日周日 上午6:58写道: >> >> >> >> Hi Ming, >> >> >> >> On Sun, Jan 24, 2021 at 10:49 AM ming han <[email protected] >> <mailto:[email protected]>> wrote: >> >> > >> >> > Hi Micha >> >> > >> >> > Many thanks for your reply. >> >> > Here is the command I am using: >> >> > >> >> > if(float(cat1_acc_riv) == float(cat1_minacc), str_r, >> null()) >> >> > >> >> > The str_r is a CELL raster. the result is different >> when I change it to: >> >> > if(int(cat1_acc_riv) == int(cat1_minacc), str_r, null()) >> >> >> >> Note that numerical "equality" is better tested with a >> threshold test >> >> against the map pixel difference. >> >> As the threshold, we use GRASS_EPSILON which is defined as >> 1.0e-15. >> >> >> >> Hence the test needs to be implemented in a different way, i.e. by >> >> using an epsilon. >> >> Essentially something like this: >> >> >> >> if(fabs(map_A - map_B) <= 1.0e-15, ... ) >> >> >> >> In your case (untested): >> >> r.mapcalc diffepsilon = if( abs( map_A - map_B) <= 1.0e-15, >> str_r , null()) >> >> >> >> See related discussions here: [1], [2] and elsewhere. >> >> >> >> [1] Comment by Glynn: >> https://trac.osgeo.org/grass/ticket/2854#comment:9 >> <https://trac.osgeo.org/grass/ticket/2854#comment:9> >> >> [2] Comment by Glynn: >> >> >> https://lists.osgeo.org/pipermail/grass-user/2015-October/073200.html >> <https://lists.osgeo.org/pipermail/grass-user/2015-October/073200.html> >> >> >> >> Best, >> >> Markus >> > >> > _______________________________________________ >> > grass-dev mailing list >> > [email protected] <mailto:[email protected]> >> > https://lists.osgeo.org/mailman/listinfo/grass-dev >> <https://lists.osgeo.org/mailman/listinfo/grass-dev> >> >> _______________________________________________ >> grass-dev mailing list >> [email protected] <mailto:[email protected]> >> https://lists.osgeo.org/mailman/listinfo/grass-dev <https://lists.osgeo.org/mailman/listinfo/grass-dev> > > -- > > ============================================= > Zoltan Szecsei GPrGISc 0031 > Geograph (Pty) Ltd. > GIS and Photogrammetric Services > > Cape Town, South Africa. > > Mobile: +27-83-6004028 > www.geograph.co.za <http://www.geograph.co.za> > ============================================= > > _______________________________________________ > grass-dev mailing list > [email protected] <mailto:[email protected]> > https://lists.osgeo.org/mailman/listinfo/grass-dev > <https://lists.osgeo.org/mailman/listinfo/grass-dev> > -- ============================================= Zoltan Szecsei GPrGISc 0031 Geograph (Pty) Ltd. GIS and Photogrammetric Services Cape Town, South Africa. Mobile: +27-83-6004028 www.geograph.co.za ============================================= _______________________________________________ grass-dev mailing list [email protected] https://lists.osgeo.org/mailman/listinfo/grass-dev