Leaflet clustering choropleth regions - leaflet

I'm fairly new to Leaflet library and I would like to ask if following functionality is somehow already implemented in Leaflet(or maybe in some other library).
I've found the following example which does clustering based on markers on the map and map also contains choropleth areas displayed.
My question is - Is it possible to do clustering based on choropleth data? Like if I have geojson data for some regions and would also have geojson data of subregions for every region. So if I do zooming then those subregions would collapse to big regions or big regions would be divided to small ones?
Big thanks for any advices or links!

No, because clustering algorithms work only on point data.
You might want to just hide the regions and display the "subregions" when zooming in.
If data becomes too dense when zooming out, consider making the union of the polygon geometries to display that instead. A naïve algorithm would be search for the smallest polygon, then search for the smallest neighboring polygon, replace them by their union, repeat. Stop the algorithm when the smallest polygon is larger than a given threshold.

Related

Hide polygons that are within a specific area

I'm trying to create an experience where I have a couple of detailed 3D models of buildings on the map with extruded building footprints of neighboring buildings via a vector tile source. The 3D models would be the main focus point and the extruded footprints would be for reference. One challenge I'm running into is that I have a global building footprint layer and it has a footprint for the 3D buildings which doesn't match up perfectly. Additionally, when extruded, it ends up merging/overlapping the nice 3D models.
I'd like to be able to hide the individual footprints that overlap the 3D models. My original thought was to grab the bounding box of the 3D model and then use the new within style expression, but it looks like this will only filter points and lines, not polygons. The building footprint polygons have no unique information in them that I could use to filter on.
I know I could monitor map movements and query the rendered features and manually detect intersecting polygons, but since there is no unique property on the footprint, I can't filter or use feature state.
Any ideas of how to efficiently avoid rendering individual polygons in a specific area that come in from a vector tile source?
It is a common issue that the buildings layer in Mapbox Streets don't contain any unique attributes to allow filtering or rendering differently.
The best solution is usually to source a different buildings layer, and in this case, remove those redundant buildings in pre-processing.
I can think of one rather crazy workaround that might work here, although the performance may be poor.
Add the building layer with very low opacity, of type fill, essentially invisible. (Maybe invisible would work.) Call your main source buildings`.
Create a secondary building source of type geojson, and a secondary fill-extrusion layer. Call this source buildings-copy.
On map move or moveend, use querySourceFeatures to obtain a copy of all buildings.
Process this copy using Turf to remove the buildings you don't want, and call setData to set the copy as the data for buildings-copy.
You may need to do some clever caching to get reasonable performance.

POSTGIS: Dissolve Multi-polygons to enable joined classification

I have a number of spatial database, through which I have identified particular types of land-cover. The topographic layer [defining land-cover] is made up of multi-polygons and I am using a separate point layer in order to join a classification type to it. However, the areas portrayed in the topographic layer may be formed from several individual polygons, without a total perimeter outline to identify the area. Therefore, the classification point may sit in just one individual polygon of the overall area [see below].
Example. Image is of a park, which consists of over 20 individual polygons. The point that classifies the area as a park sits within one of the polygons and cannot be attached to the entire area.
I would like to be able to apply the point based classification to the whole park area. I have tried to use ST_UNION function in order to do such, but have been unable. Does anyone know of a way to dissolve the area into a single shape/remove the pathways? This is a small example of a much larger data set, where there is little scope of manually defining area sand buffers in order to classify the data, thus I wondered if there was a practicable solution.
If anyone can help, it would be hugely appreciated....
SELECT ST_Collect(t.the_geom) as singlegeom FROM TABLE t; http://postgis.net/docs/ST_Collect.html

Visualising road segments as heatmap in Leaflet efficiently

I have data consisting of parts of road segments of a city, with different number of visits. I want to plot the data on a Map and visualise it in the form of a heatmap.
I have two related questions:
I have the data from Open Street Maps (OSM) in the form of pairs of node ID's, where node ID correspond to the unique ID being assigned to a point by OSM. I also have a mapping for each node Id to its corresponding coordinates. Is there any Leaflet or Mapbox utility or plugin, which can plot a trip / highlight the road segment using 2 node ID's. I can always do it manually (by using the coordinate mapping and converting it into GeoJSON), but the problem occurs with the line width -- I have to make it exactly overlap with the width of the road, so that it seems that I am highlighting a road segment.
Is there any plugin / utility for Leaflet or Mapbox, which can be used for plotting polylines or geojson as heatmap efficiently? My current approach is calculating the color for each polyline and encoding that as a geojson property. But the problem is that with the increase in the number of lines (> 1K) the rendering becomes a pain and the method is not feasible. There are some plugins for Leaflet out there for plotting heatmap, but all of them are for points only and not lines. Any approach using WebGL would be really great.
An approach which I thought of could be converting my data into a shape file, upload to Mapbox Studio and use as a layer directly. But I have no idea how to go about doing that i.e. creating a shapes file, encoding the information in such a way that the complete road segment gets highlighted in the correct color.

How to make Folium's Heatmap weights not be influenced by the number of points in a region?

I'm trying to build a home value Heat Map for a city using Folium (a python library that uses Leaflet to plot geo data). My Dataframe contains Latitude, Longitude, and Price (variable which is going to act as weight). Cheap areas should be green and expensive, red. The problem is that some poor regions with many dots seem to be more expensive, because those dots overlay each other and turn that region red. The method has some parameters to switch, but any of them solved my problem. Does anyone have a way to overcome this or an alternative library to make interactive heat maps using python?

Does using the Overpass polygon query have a computational advantage over a bounding box?

For a project on geospatial data analytics, we are currently extracting road type and speed limit data of certain roads along a track by using Overpass' polygon query (where we define the roads by a buffer zone around them). The problem is that in the case of separate tracks, we can end up with disconnected polygons which often lead to a significant increase in computation time. In this situation, we were wondering how Overpass' polygon query actually works. Does the algorithm actually query only the data inside this polygon/these polygons, or does it query inside a bounding box, after which it filters out the data inside the polygons?
The algorithm checks if nodes are inside the defined polygon, or if a way crosses the polygon. It's not based on bounding boxes as you mentioned.
From your description it's not quite clear why disconnected polygons pose an issue. You should get decent performance with a lz4-based backend and a reasonable number of lat/lon pairs in your (poly: ) filter (the more pairs you provide, the more expensive the computation gets).
BTW: The best approach to tackle this issue would be something I described in this blog post: https://www.openstreetmap.org/user/mmd/diary/42055 - unfortunately, this feature is not yet available in the official branch. If you see some use for it, please upvote here: https://github.com/drolbr/Overpass-API/issues/418