[Qgis-user] Clustering visibility in QGIS

Max Pyziur pyz at brama.com
Thu Mar 28 16:09:14 PDT 2024


Greetings,

I've been trying some clustering functions in PostGIS

I have an ongoing project where I layer a variety of energy 
infrastructure. The data is is stored in SRS 4326; the target SRS is 2163.

Currently, I'm trying to build clusters of filling stations located within 
3000 feet.

I first create a table of filling stations (data is taken from All The 
Places).

I then create a geom field from the latitude and longitude attributes in 
SRS 4326.

To build a table of clusters I do it via SQL using the following command:
DROP TABLE shapefiles.filling_station_clusters;

CREATE TABLE shapefiles.filling_station_clusters AS
SELECT city, state, ST_ClusterDBScan( ST_Transform(geom,2163), eps := 
0.3048*5000, minpoints :=2) OVER () AS cluster_id, aa.geom
FROM shapefiles.atp_filling_stations aa WHERE aa.amenity = 'fuel'
AND aa.ctry_code = 'US' AND aa.geom IS NOT NULL;

Then using the DB Manager in QGIS I run the following SQL:
SELECT cluster_id AS cid1 , 
ST_Collect(ST_MinimumBoundingCircle(ST_Collect(geom)), ST_Collect(geom)) 
AS geom, COUNT(*) as ct
FROM shapefiles.filling_station_clusters
WHERE cluster_id IS NOT NULL
GROUP BY 1;

The SQL runs both in the PostgreSQL monitor as well as in DB Manager. But 
nothing shows up visually. Using Properties, I can't assign any sort of 
symbology.

All of my QGIS layers are called via PostGIS. So the challenge here is 
somewhere in the code, not the connections between PostgreSQL, PostGIS, 
and QGIS.

Thank you,

Max Pyziur
pyz at brama.com


More information about the QGIS-User mailing list