Answer the question
In order to leave comments, you need to log in
Are there libraries to implement clustering in PHP?
There is a task of data clustering. Briefly:
The input array contains some coordinates expressed as x and y constants (latitude and longitude). It is necessary to perform clustering, the method is not important, special accuracy is also not important.
There is only one obligatory condition: PHP+Apache.
Actually, the essence of the question is, how can this be done so as not to climb into the deep jungle of algorithms? Are there libraries for implementing the algorithm?
Answer the question
In order to leave comments, you need to log in
if you don’t necessarily need honest clustering, then you can write it yourself for a short time:
$objects = array(array('lon' => 1, 'lat' => 2), ..., ...);
$cluster = array();
$levels = 10;
$firstRectWidth = 0.01; //самый маленький "квадрат" будет 1111 на 1111
for ($i = 0; $i < count($objects); $i++)
{
$obj = $objects[$i];
for ($level = 1; $level <= $levels; $level++)
{
$lon_index = ($obj->lon) / ($firstRectWidth * (2 ^ $level)); // не помню как степень в php
$lat_index = ($obj->lat) / ($firstRectWidth * (2 ^ $level)); // не помню как степень в php
$cluster[$level][$lon_index . "-" . $lat_index][] = $i;
}
}
// использование
$zoom = 1..10;
echo "кластеров ".(count($cluster[$zoom]))."<br >";
foreach ($cluster[$zoom] as $key => $value)
{
echo "область ".$key."<br >";
echo "кол-во элеметнов ". (count($value));
}
Here's an example of how I calculate the distance between two coordinates in SQL.
I'll calculate the distance, in principle you can write clustering in PHP, if necessary :-)
"google maps cluster" - search in a search engine, I think you will find a lot of interesting things, both PHP, MySQL and JS solutions.
$query = $this->db->query('SELECT
pan.id,
ROUND(ATAN(SQRT(POW(COS(RADIANS(pan.latitude)) * SIN(ABS(RADIANS('.$pano->longitude.')-RADIANS(pan.longitude))),2) + POW( COS(RADIANS('.$pano->latitude.')) * SIN(RADIANS(pan.latitude)) - SIN(RADIANS('.$pano->latitude.')) * COS(RADIANS(pan.latitude))*COS(ABS(RADIANS('.$pano->longitude.')-RADIANS(pan.longitude))),2))/(SIN(RADIANS(pan.latitude)) * SIN(RADIANS('.$pano->latitude.')) + COS(RADIANS(pan.latitude)) * COS(RADIANS('.$pano->latitude.'))* COS(ABS(RADIANS('.$pano->longitude.')-RADIANS(pan.longitude))))) * 6373000, 0) AS distance
FROM pano pan
WHERE pan.latitude IS NOT NULL
AND pan.longitude IS NOT NULL
AND pan.id != '.$pano->id);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question