[R] Can I calculate the area of a polygon?
Andreas Kretschmer,,,
kretschmer at kaufbach.delug.de
Sun Dec 19 15:41:32 CET 2004
am Sun, dem 19.12.2004, um 13:40:32 -0000 mailte Ted Harding folgendes:
> Not sure what you mean by "the installed plr - Language", but for
The Database-System PostgreSQL is ready to extend with external
features. As example: pl/r is a procedural language. So can I share data
between the database and R.
,----[ lynx --dump plr-overview.html ]
| Chapter 1. Overview
|
| PL/R is a loadable procedural language that enables you to write
| PostgreSQL functions and triggers in the [6]R programming language.
| PL/R offers most (if not all) of the capabilities a function writer
| has in the R language.
`----
> calculating areas og polygons you may find the following function
> useful.
> Example based on the coordinates ((0,0),(0,2),(2,2),(3,3),(5,0))
> you give above.
>
> Let X be the matrix of the coordinates:
>
> > X
> [,1] [,2]
> [1,] 0 0
> [2,] 0 2
> [3,] 2 2
> [4,] 3 3
> [5,] 5 0
>
>
> Function "area":
>
> area<-function(X){
> X<-rbind(X,X[1,])
> x<-X[,1]; y<-X[,2]; lx<-length(x)
> -sum((x[2:lx]-x[1:lx-1])*(y[2:lx]+y[1:lx-1]))/2
> }
>
> > area(X)
> [1] -9.5
Danke, Merci, thank you.
> Hoping this helps,
Yes.
Regards, Andreas
--
Diese Message wurde erstellt mit freundlicher Unterstützung eines freilau-
fenden Pinguins aus artgerechter Freilandhaltung. Er ist garantiert frei
von Micro$oft'schen Viren. (#97922 http://counter.li.org) GPG 7F4584DA
Was, Sie wissen nicht, wo Kaufbach ist? Hier: N 51.05082°, E 13.56889° ;-)
More information about the R-help
mailing list