# Clustering spatial data in R

I have a set of sea surface temperature (SST) monthly data and I want to apply some cluster methodology to detect regions with similar SST patterns. I have a set of monthly data files running from 1985 to 2009 and want to apply clustering to each month as a first step.

Each file contains gridded data for 358416 points where approximately 50% are land and are marked with a 99.99 value that will be NA. Data format is:

   lon     lat   sst
-10.042  44.979  12.38
-9.998  44.979  12.69
-9.954  44.979  12.90
-9.910  44.979  12.90
-9.866  44.979  12.54
-9.822  44.979  12.37
-9.778  44.979  12.37
-9.734  44.979  12.51
-9.690  44.979  12.39
-9.646  44.979  12.36


I have tried CLARA clustering method and got some apparently nice results but it also seems to me that is just smoothing (grouping) isolines. Then I am not sure this is the best clustering method to analyse spatial data.

Is there any other clustering method devoted to this type of datasets? Some reference would be good to start reading.

• You should check out cran.r-project.org/web/views/Spatial.html . There are a few packages that have cluster right in the name that would probably be of interest. – Andy W Apr 19 '11 at 14:57
• Did you find any good R package to cluster spatial data? – kaptan Dec 6 '11 at 2:48
• @kaptan Unfortunately I didn't and it is one of the – pacomet Dec 6 '11 at 23:04
• This question's title is confusing: $(x,y,T)\in\mathbb{R}^3$, not $\mathbb{R}$! – GeoMatt22 Sep 19 '16 at 1:13

There is different approach for scalable clustering, divide and conquer approach, parallel clustering and incremental one. This is for general approach after you can use normal clustering methods. There a good method of clustering i really appreciate is DBSCAN (Density-Based Spatial Clustering of Applications with Noise) it is one of the most used clustering algorithm.

• Ok, I'll look for DBSCAN and give it a try. Thanks – pacomet May 13 '11 at 6:43
• If any answer helped you or you find out another way it is better to give us, so all community will take advantage of that. Or choose an answer to close the question, thx. – 404Dreamer_ML May 20 '11 at 15:26
• I'm sorry for the delay in answering but the point is I haven't got much time to try dbscan and first attempts resulted in a memory problem. R says it can not allocate vector. I start with a 4 km spaced grid with 779191 points that ends in 300000 points when removing land (not valid) SST points. Maybe I'm not getting the right approach, any hint would be appreciated. – pacomet May 23 '11 at 12:21
• Hi, I can't still find a solution. I have read some docs about DBSCAN and have some questions about. How to find minimum distance with R? As my data are three dimensional longitude, latitude and temperature, which "distance" should I use? whicn dimension is related to that distance? temperature? Is there a method to determine the minimum number of points for a cluster? Searching thorugh Google I could not find an R example for using dbscan in a dataset similar to mine, do you know any website with such kind of examples? So I can read and try to adapt to my case. Thanks again – pacomet May 31 '11 at 9:42

A nicely documented python library for spatial analysis that has some clustering is pySAL.

Another python library in the development stage that is focused on spatial clustering is clusterPy (pdf slide presentation).

With a more limited choice of clustering algorithms but with nice mapping interface is the GUI software GeoGrouper.

• Thanks, I have not ever worked with python. I will try to find an R solution – pacomet May 6 '11 at 10:53