[R-sig-Geo] kmlPolygon (maptools) with simple data frame/matrix

Roger Bivand Roger.Bivand at nhh.no
Mon Jan 31 22:06:03 CET 2011


On Mon, 31 Jan 2011, Markus Loecher wrote:

> Dear all,
> I am looking for example code that lets me use the kmlPolygon() function
> (pckg: maptools) with a simple (non projected) data frame of lat/lons.
> I found the documentation on converting data frames to SpatialPolygons in
> the package sp very sparse and that seems to be a prerequisite to use
> kmlPolygon() ?
>
> Wishful thinking would be the following:
>
> x <- cbind(lat = c(38.100, 38.100, 38.116, 38.116, 38.100), lon =
> c(-122.400, -122.384, -122.384, -122.400, -122.400) )

Always longitude first, latitude second, (x, y). Then:

x <- cbind(lon = c(-122.400, -122.384, -122.384, -122.400, -122.400),
   lat = c(38.100, 38.100, 38.116, 38.116, 38.100))
Pls <- Polygons(list(Polygon(x)), "1")
kmlPolygon(Pls)

Wishful is as simple as possible (and generic), but not more so ...

Roger


> kmlPolygon(x, ....)
>
> Thx,
>
> Markus Loecher
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list