Skip to content

Distribute points along lines

3 messages · Roger Bivand, Agustin Lobo

#
On Sun, 5 Jul 2009, Agustin Lobo wrote:

            
The problem was that sp:::sample.Line() was not handling a zero-length 
line segment (two identical consecutive coordinates in a Line object) 
properly, provoking an error when offset was set to 0.

I've committed changes to sourceforge:

cvs -z3 \
-d:pserver:anonymous at r-spatial.cvs.sourceforge.net:/cvsroot/r-spatial \
co -P sp

(all one line), then

R CMD INSTALL sp

to try out. I have also reversed the meaning of offset for lines, 0 is now 
the start coordinate of the Line object. If possible, could you please 
check out the revision, install it from source, and try it - it resolves 
the problem for your case as far as I can tell.
There are LineLength(), LinesLength(), and SpatialLinesLengths() 
functions in sp, more used internally than exposed, but should be OK. I've 
converted LineLength() to use C code, so they can now also measure lengths 
in km even if the data are in geographical coordinates (assuming WGS84), 
as in spDistsN1().

Roger

  
    
#
Roger,

your newer code works fine, thanks.
I'm doing:
 > fl1 <- 
readOGR(dsn="/media/Transcend/MONTSENY2008/MONTSENY_UAV2/Linies_CastVila1",layer="Linies_CastVila1")
 > plot(fl1)
 > points(spsample(fl1[4,],5,offset=0.0,type="regular"))

and points start at the starting point of the line.

Regarding the length, by now I'm using coordinates() to get
the length of each line, i.e.
 > max(dist(as.matrix(coordinates(fl1)[[1]][[1]])))

for the first line. Is there a simpler syntax? I found
the [[1]][[1]] by trial and error, don't actually understand
why the simpler command
 > as.matrix(coordinates(fl1)[[1]])
does not work

I think it would make sense
having a field length in the object as you mentioned, and perhaps also area for 
polygons. Or maybe just having
a function sparealen() to calculate length of lines
and length of each side, perimeter and area of polygons would be
more appropriate.

Thanks

Agus
Roger Bivand wrote:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alobolistas.vcf
Type: text/x-vcard
Size: 251 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20090705/016a29cd/attachment.vcf>
#
On Sun, 5 Jul 2009, Agustin Lobo wrote:

            
Good, thanks, I'll release soon.
Maybe try SpatialLinesLengths() in sp for the lines case. The polygon case 
is much harder, because the topology has to be built. It can be done using 
the topology built in GRASS. Perimiter is OK, but anything more requires a 
GIS.

Roger