Continuing on clustering queries

Regina Obe lr at pcorp.us
Thu Mar 28 15:18:47 PDT 2024


> The reason is that it doesn't seem that QGIS can work w TEMP tables.
> 
TEMP tables are only visible to the session that created them, so not a huge
surprise QGIS can't work with them.
I use them mostly to store intermediary results before dumping to another
table.


> From this, I want to create a layer; I use 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 GROUP BY
> 1;
> 
> (for some reason, it rejected the SQL if a result was returned with column
> name of cluster_id - possible reserved name?)
> 
Strange.  I should try that sometime.

> This SQL variant does not return errors, but it isn't visible in my QGIS
project
> (it's an ongoing project with about twenty layers built with PostGIS).
> 
> Any advice?
> 
> Should I direct this inquiry to the QGIS list?
> 
> Thank you,
> 
> Max
It might be because it returns a geometry collection.  I recall QGIS not
liking geometry collections.
Also depending on how you are creating this -- is this a view or an inline
SQL, you might need to force the type for it to show as a layer option.

Try:
       
       SELECT cluster_id AS cid1 ,
       ST_Collect(ST_MinimumBoundingCircle(ST_Collect(geom)),
ST_Collect(geom))::geometry(GEOMETRYCOLLECTION,4326) AS geom
       , COUNT(*) as ct FROM shapefiles.filling_station_clusters GROUP BY
       1;

Or having as two separate layers:
-- layer 1
SELECT cluster_id AS cid1 ,
ST_MinimumBoundingCircle(ST_Collect(geom)):geometry(POLYGON,4326) AS geom
, COUNT(*) as ct FROM shapefiles.filling_station_clusters GROUP BY
1;

-- layer 2
SELECT cluster_id AS cid1 ,  ST_Collect(geom):geometry(MULTIPOINT,4326) AS
geom
, COUNT(*) as ct FROM shapefiles.filling_station_clusters GROUP BY
1;

Could also be a permission issue.
If that doesn't help, then yes QGIS mailing list might have more useful
answers.

Hope this helps,
Regina



More information about the postgis-users mailing list