The following might work and could definitely be improved for speed  
and error catching.


require(sp)
require(maptools)

slopes <- function(k){
        x <- k[[1]]
        y <- vector(length=nrow(x)-1)
        for (i in 1: nrow(x)-1){
                y[i] <-(x[i+1,2]-x[i,2])/(x[i+1,1]-x[i,1])
                }
                return(y)
        }
        
angles <- function(k){
        y <- vector(length=length(k)-1)
        for (i in 1: length(k)-1){
                y[i] <- atan((k[i+1]-k[i])/(1+k[i]*k[i+1]))
                }
                return(y)
        }

xx <- readShapeLines(system.file("shapes/fylk-val.shp",  
package="maptools")[1],
  proj4string=CRS("+proj=utm +zone=33 +datum=WGS84"))

a <- coordinates(xx)
sl <- lapply(a, slopes)
ag <- lapply(sl, angles)


Nikhil Kaza
Asst. Professor,
City and Regional Planning
University of North Carolina

[email protected]

On Jul 30, 2010, at 3:33 AM, Rainer M Krug wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi
>
> a friend of mine wants (needs?) to determine the angle between  
> segments
> in an ESRI polyline (line vector feature). As there does not seem to  
> be
> an easy way in ArcGIS 9.2, I thought about askeng here:
>
> Is there way of calculating these angles between the different line
> segments in R (after importing the line feature into R)?
>
> Thanks,
>
> Rainer
>
> - --
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
> Biology, UCT), Dipl. Phys. (Germany)
>
> Centre of Excellence for Invasion Biology
> Natural Sciences Building
> Office Suite 2039
> Stellenbosch University
> Main Campus, Merriman Avenue
> Stellenbosch
> South Africa
>
> Tel:        +33 - (0)9 53 10 27 44
> Cell:       +27 - (0)8 39 47 90 42
> Fax (SA):   +27 - (0)8 65 16 27 82
> Fax (D) :   +49 - (0)3 21 21 25 22 44
> Fax (FR):   +33 - (0)9 58 10 27 44
> email:      [email protected]
>
> Skype:      RMkrug
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkxSgFYACgkQoYgNqgF2egp34ACeMiVR1XG9xb/YH7KpFJ+3jTln
> 5WUAn3Cxbl1BCr9iSidDFYcmwdiiYhFh
> =P2Jq
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> R-sig-Geo mailing list
> [email protected]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to