[R] R: data.frame to shape
Guazzetti Stefano
Stefano.Guazzetti at ausl.re.it
Wed Aug 9 16:00:38 CEST 2006
assuming that the rows are sorted correctly
dat
id x y
1 50 1647685 4815259
2 50 1647546 4815196
3 50 1647454 4815294
4 50 1647405 4815347
5 50 1647292 4815552
6 50 1647737 4815410
7 74 1647555 4815201
8 74 1647464 4815023
9 74 1646970 4815129
10 74 1646895 4815264
11 74 1646762 4815513
> list.dat<-split(dat, dat$id)
>
> closed.polygons<-lapply(list.dat, function(x) rbind(x, x[1,]))
>
> do.call("rbind", closed.polygons)
id x y
50.1 50 1647685 4815259
50.2 50 1647546 4815196
50.3 50 1647454 4815294
50.4 50 1647405 4815347
50.5 50 1647292 4815552
50.6 50 1647737 4815410
50.11 50 1647685 4815259
74.7 74 1647555 4815201
74.8 74 1647464 4815023
74.9 74 1646970 4815129
74.10 74 1646895 4815264
74.11 74 1646762 4815513
74.71 74 1647555 4815201
but maybe there are better ways to do what you want
>-----Messaggio originale-----
>Da: r-help-bounces at stat.math.ethz.ch
>[mailto:r-help-bounces at stat.math.ethz.ch]Per conto di Leonardo Lami
>Inviato: 09 August, 2006 15:33
>A: r-help at stat.math.ethz.ch
>Oggetto: [R] data.frame to shape
>
>
>Hi all,
>I have a simple question:
>I have a data.frame like this:
>
> id x y
>1 50 1647685 4815259
>2 50 1647546 4815196
>3 50 1647454 4815294
>4 50 1647405 4815347
>5 50 1647292 4815552
>6 50 1647737 4815410
>7 74 1647555 4815201
>8 74 1647464 4815023
>9 74 1646970 4815129
>10 74 1646895 4815264
>11 74 1646762 4815513
>
>and I'd like to trasform it with the "convert.to.shapefile"
>function
>(shapefiles package) but to make this I must have a
>data.frame like this:
>
> id x y
>1 50 1647685 4815259
>2 50 1647546 4815196
>3 50 1647454 4815294
>4 50 1647405 4815347
>5 50 1647292 4815552
>6 50 1647737 4815410
>7 50 1647685 4815259
>8 74 1647555 4815201
>9 74 1647464 4815023
>10 74 1646970 4815129
>11 74 1646895 4815264
>12 74 1646762 4815513
>13 74 1646762 4815513
>
>with the first point of every id repeated to close the polygon.
>There is a function to make this indipendently by the
>number of the id
>
>Best regards
>Leonardo
>
>--
>Leonardo Lami
>email + jabber: lami at faunalia.it
>www.faunalia.it
>Cell: (+39)349-1310164 Tel+Fax: (+39) 0587-213742
>Piazza Garibaldi 5 - 56025 Pontedera (PI), Italy
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
>
>
More information about the R-help
mailing list