0

I found the following algorithm which works perfectly with single values [2;4;56;10;34;....]: https://radixcode.com/k-mean-clustering-algorithm-implementation-in-c-java

Now I want to replace my singular dataset with geolocation coordinates-

For example, let's assume I have the following pairs:

Longitude: 759849.934, Latitude: 193728.08
Longitude: 760151.603, Latitude: 192624.342
Longitude: 759217.306, Latitude: 191895.671
Longitude: 758446.428, Latitude: 191074.83
Longitude: 758422.0, Latitude: 192359.0

Is there a way to calculate a single value from Longitude and Latitude so as to apply this algorithm?

Sachin Aggarwal
  • 1,095
  • 8
  • 17
hublo
  • 1,010
  • 2
  • 12
  • 33

2 Answers2

1

There are several ways to do that but what these aren't suitable to cluster Geo points think of coordinates as 2 dimensional vectors so you would have all the vector norms to transform them into a one dimensional values see her for different norms but that won't help you much.

    for (int c : cz) {
        row.add(abs(c - aItem));
      }
   groups.get(row.indexOf(Collections.min(row))).add(aItem);
   row.removeAll(row);

K-Means in a perfect implementation would also take a Distance function as a parameter. In the for loop you see that your code is using absolute value abs(c - aItem) as a the distance function you would need to change that to use a suitable distance function look here for example.

ketrox
  • 889
  • 1
  • 12
  • 23
  • Thanks Ketrox. No problem if not perfect, I'm only looking for a first implementation which works "as best as possible". But My original question still remains: is there a way to convert a Longitude and Latitude values into a single value? I ready also that following could do it: (lat+90)*180+lng ... Do you agree? – hublo Sep 18 '17 at 13:02
0

There is a concept called geohash which essentially convert the lattitude longitude to a string (alpha - numeric) and from that it is easy to find the nearby places. You can take a look. There are libraries to find neighbors of a geohash.

However, K-means doesn't work well on the geo-spatial data. For the simple reason that the geo-spatial data is non-linear. Generally it is preferable to use the DBSCAN/CLARA for this purpose.

On the converting geo-spatial data to a Single value. I thing the same topic has been discussed here :

https://stackoverflow.com/questions/8285599/is-there-a-formula-to-change-a-latitude-and-longitude-into-a-single-number
Avishek Bhattacharya
  • 6,534
  • 3
  • 34
  • 53