Jonathan,

A point with an x coordinate that is on the border between two cells is
normally assigned to the right hand cell, but because of floating point
math imprecision, this sometimes does not happen and the left hand cell is
selected instead. That does not bother me too much as the choice is
arbitrary anyway. The issue is illustrated here:

> print(0.1 / 0.1, 22)
[1] 1
> print(0.2 / 0.1, 22)
[1] 2
>
> print(0.3 / 0.1, 22)
[1] 2.999999999999999555911
> # should have been 3
>
> print(0.4 / 0.1, 22)
[1] 4
>

Robert

On Sat, Apr 13, 2013 at 5:11 PM, Jonathan <j2kennel@gmail.com> wrote:

> Hello group,
>
> I am trying to get the column from point that exists the interfaces of two
> cells and find that the results I'm getting are not consistent.

In the
> below example I am getting the higher boundary for the cell for 0.1, 0.2,
> and 0.4.  However, I get the lower boundary for 0.3.
>
> My current solution is to add a very small number to the coordinate if the
> value falls on the interface but does anyone know a better workaround?
>

> library(raster)
> H <- raster(matrix(sample.int(100), ncol=10))
>
> colFromX(H, 0.1)  # 2
> colFromX(H, 0.2)  # 3
> colFromX(H, 0.3)  # 3
> colFromX(H, 0.4)  # 5
>
> colFromX(H, 0.30000000000000001)  #3
> colFromX(H, 0.3000000000000001)   #4
>
> Cheers,
> -Jonathan
>
>
> Session Info
> R version 3.0.0 (2013-04-03)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
> States.1252
> [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] raster_2.1-16 sp_1.0-8
>
> loaded via a namespace (and not attached):
> [1] grid_3.0.0      lattice_0.20-15 tools_3.0.0
>
>
>
> --
> View this message in context:
> http://r-sig-geo.2731867.n2.nabble.com/Raster-package-colFromX-behaviour-tp7583304.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

