Skip to content
Prev 6003 / 29559 Next

Distribute points along lines

On Fri, 3 Jul 2009, Agustin Lobo wrote:

            
With the meuse.riv data set, this cannot be reproduced. Please provide a 
reproducible example.

The problem is occurring in the output from sp:::.bboxCoords(), with an NA 
bounding box value, but that means that sample.Line() is probably getting 
a Line with no length:
+ type="regular")
Error in validObject(.Object) :
   invalid class "SpatialPoints" object: bbox should never contain NA values

which means that no sample points are found. This suggests that the user 
error ought to be caught earlier, and maybe that Line objects with no 
length and all identical coordinates should be made invalid (this 
requirement was removed two years ago), but the onus is on the user to 
provide sensible data.
For samples from lines, it is used as:

# default is: ..., offset = runif(1), ...
((1:n) - offset)/n * maxl
[1]  2  4  6  8 10

so a proportion in [0,1], but it seems to work backwards at present, with 
an offset of 0 anchoring to the final, not the first, point.
calcLength() is in PBSmapping. Adding a length slot to Line objects is an 
option, or rather providing length methods which would be less invasive. 
I'll take a look.

Roger

PS. The answers to these relatively detailed questions are in the source, 
which can easily be browsed on:

http://r-spatial.cvs.sourceforge.net/viewvc/r-spatial/sp/

or from the source bundle. Suggestions with patches are appreciated.