L
L
Lighter Ilya2019-02-19 12:42:01
Django
Lighter Ilya, 2019-02-19 12:42:01

How to cluster markers on a Python/Django/GeoJSON stack?

Good afternoon!
Straight to the point. We are developing an API for a project using the Django/REST Framework/Postgresql stack . Some models have fields containing geodata (coordinates) in JSON format (using django-geojson ).
The user receives a request that contains a geovector (coordinates of the lower left and upper right points of the map), the size of the map in pixels, and the size of the cluster icon in pixels. He needs to give JSON like:

[
    {
        "cluster_id": 0,
        "coordinates": [
            37.6184755,
            55.7582595
        ],
        "ids": [
            1,
            2
        ]
    }
]

where cluster_id is the cluster ID (not that important, really), coordinates are the cluster coordinates and ids are the IDs of the objects that are part of the cluster.
Are there any extensions or packages (for python, djanga or db) that allow you to do this kind of thing? Or maybe you can suggest some algorithm for this action?
This is currently implemented using Postgresql 's kmeans extension , but this solution does not take into account the size of the icon , and the icons of two clusters that are actually close enough can overlap, making this process useless (the second icon simply cannot be clicked).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dom1n1k, 2019-02-19
@dom1n1k

The simplest is grid clustering.
Specify the size of the cell more than the change of your icon and that's it.
https://video.yandex.ru/users/ya-events/view/721/u...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question