[R-sig-Geo] Distribute points along lines

Agustin Lobo alobolistas at gmail.com
Sun Jul 5 19:55:26 CEST 2009


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:
> On Sun, 5 Jul 2009, Agustin Lobo wrote:
> 
>> Roger,
>>
>> Roger Bivand wrote:
>>
>>> 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.
>>
>> Would it be too hard adding the offset to the first point? And actually
>> ordering the points starting from the initial point of the line?
> 
> 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.
> 
>>
>>>
>>>> I'm actually trying to set real field sampling sites, so this 
>>>> matters. The best would be being able to set the first point in the 
>>>> line and then the nb of points for random sites (as it is currently 
>>>> done) and the length interval for regular sampling.
>>>>
>>>> By now I can adjust the nb. of points for the interval I want if the 
>>>> length of the line is known, but how can I calculate the length of 
>>>> the lines? calcLength requires another type of spatial object.
>>>
>>> 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.
>>
>> Thanks, please let me know. By now I measure the actual length in qgis.
> 
> 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
> 
>>
>> Agus
>>
>>
> 
-------------- 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>


More information about the R-sig-Geo mailing list