creating polygons of clusters of points?
Hi, Here is another approach, using something like a 'concave hull' -- i.e. alpha shapes: http://casoilresource.lawr.ucdavis.edu/drupal/node/919 Cheers, Dylan
On Friday 23 April 2010, Roman Lu?trik wrote:
How does this function sound (convexhull.xy {spatstat})?
http://bm2.genes.nig.ac.jp/RGM2/R_current/library/spatstat/man/convexhull.x
y.html
Convex Hull of Points Description
Computes the convex hull of a set of points in two dimensions.
Usage
convexhull.xy(x, y=NULL)
Arguments x vector of x coordinates of observed points, or a 2-column
matrix giving x,y coordinates, or a list with components x,y giving
coordinates (such as a point pattern object of class "ppp".) y (optional)
vector of ycoordinates of observed points, if
x is a vector.
Cheers,
Roman
On Fri, Apr 23, 2010 at 4:37 PM, Hans Ekbrand <hans at sociologi.cjb.net>wrote:
How to create nice polygons from a number of clusters? I have sorted list of clusters representing hot-spots
sorted.list.of.clusters
[1] 7 1 11 9 26 2 5 10 33 40 18 28 37 20 30 47 53 whereas my.cluster holds the classification of events (criminal fire-setting) to clusters: head(my.cluster, 100) [1] 1 2 3 3 4 5 6 7 8 5 9 10 11 12 1 13 2 14 15 10 16 17 5 13 7 7 18 19 18 20 20 2 21 16 22 18 10 1 [39] 9 23 4 7 24 9 9 7 7 5 2 11 25 12 7 7 26 27 13 7 7 28 18 28 29 9 2 5 30 11 31 14 18 1 32 26 2 31 [77] 29 33 2 34 2 26 35 36 7 2 35 37 26 38 11 2 11 26 30 7 4 11 8 11
number.of.fires.at.hotspots <- sapply(sorted.list.of.clusters,
function(x) {length(which(my.cluster == x))})
number.of.fires.at.hotspots
[1] 44 39 38 32 22 21 21 21 15 15 14 14 14 12 12 12 12 The "SpatialPointsDataFrame" object clust.geo.test holds the events. A list coordinates of the events of each cluster is generated with:
sapply(sorted.list.of.clusters, function(x)
{clust.geo.test at coords[which(my.cluster
== x),]})
[[1]]
Ost Nord
[1,] 322737.4 6406939
[2,] 323104.9 6406968
[3,] 323104.9 6406968
...
[[2]]
Ost Nord
[1,] 315359.9 6393110
[2,] 315177.0 6394031
[3,] 314697.8 6394565
...
And I can plot the points in the hot-spots with
plot(sdn) sapply(sorted.list.of.clusters, function(x)
{plot(clust.geo.test[which(my.cluster == x),], add = T)})
But would like to plot each cluster as a polygon, ideally filled with
darker colors for clusters with higher number of fires.
I guess I need to create polygons for each cluster and then plot each
polygon. How do you do that?
For your convenience I have created a RData object containing the
objects refered to above and uploaded to this URI
http://sociologi.cjb.net/temp/to-polygons-help.RData, so
print(load(url("http://sociologi.cjb.net/temp/to-polygons-help.RData")))
plot(sdn)
sapply(sorted.list.of.clusters, function(x)
{plot(clust.geo.test[which(my.cluster == x),], add = T)})
would get you to the point I am now.
Hans Ekbrand
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAkvRsLEACgkQfCyHKnBQYU4JrQCfWMlOgECamin5ZugGoHcUpqx3
fuQAoNDoG6iMVlLJCOYfoP5MRbNYHGlI
=jKTU
-----END PGP SIGNATURE-----
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Dylan Beaudette Soil Resource Laboratory http://casoilresource.lawr.ucdavis.edu/ University of California at Davis 530.754.7341