[R-sig-Geo] tolerance in points2grid()

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Wed Jan 22 14:03:30 CET 2014


On Wed, Jan 22, 2014 at 12:26 PM, Agustin Lobo <alobolistas at gmail.com> wrote:
> Hi!
>
> I do
> points2grid(tmetad1)
>
> and get:
> suggested tolerance minimum: 0.000856898
> Error in points2grid(tmetad1) :
>   dimension 2 : coordinate intervals are not constant
>
> then just try:
> tmetadg <- points2grid(tmetad1,tolerance=0.000856898)
>
> and works fine. But this is very inconvenient unless the task is being carried
> interactively. Is there a way of actually geting the value of the
> suggested tolerance into
> a variable?
> Also, why not having the option:
>
> tmetadg <- points2grid(tmetad1,tolerance="suggested")
>

 I don't see a way of getting this short of really hacky methods
(wrapping the call in a "try", capturing the output, parsing it to get
the suggested value). Better to just look at the source code and use
that.

 Its a bit of a twisty turny maze of diffs and floors and maxes and
mins, but its there. One complication is that the tolerance is
computed independently for each dimension, so what you actually need
to do is loop over dimensions and use the largest computed suggested
tolerance. At the moment the code stop()s when it hits the first
tolerance fail:

 > xy=SpatialPoints(cbind(c(1,2,3,4,5.01),c(1,2,3,4,5.02)))

> points2grid(xy)
suggested tolerance minimum: 0.01
Error in points2grid(xy) :
  dimension 1 : coordinate intervals are not constant

 oops, dimension 1 (x) out of tolerance, lets' up that:

> points2grid(xy, tolerance=0.01)
suggested tolerance minimum: 0.02
Error in points2grid(xy, tolerance = 0.01) :
  dimension 2 : coordinate intervals are not constant

 and now dimension 2 is out. I guess this would be a pain in a ten
dimensional universe...

 Barry



More information about the R-sig-Geo mailing list