There is no way to visualize a convex hull in QGIS 1.8 Lisboa? I have tried the following views in PostGIS 1.5

I was told to use an "id" column to publish it in QGIS. If you do not use an "id" column, you cannot load it anyway because of an error.


CREATE OR REPLACE VIEW con_hull_baeume3(bid) AS
SELECT '0', ST_ConvexHull(ST_Collect(geom)) FROM baeume;
CREATE OR REPLACE VIEW con_hull_baeume4(bid) AS
SELECT bid, ST_ConvexHull(ST_Collect(geom)) FROM baeume GROUP BY bid;

but this one makes a convex hull on each of the geometry points.

I mean just use SELECT ST_ConvexHull(ST_Collect(geom)) FROM baeume; works as SQL perfectly. But I must define it as a view to load it into a PostGIS layer of QGIS.

  • Hi, just to clarify: bid are they unique IDs (you group by bid and want a set of points...)? Otherwise, shoudn't you state something like "select geom from baueme bb where bb.bid = bid" within your ST_ConvexHull or something?
    – Aname
    Mar 22, 2013 at 9:22
  • hi thanks. the state group by is an advise of pgadmin to use. i want a convexhull over all points and not on each of them. So i do know to make this sql statement. I know it is:select ST_ConvexHull(ST_Collect(geom)) FROM baeume; But how to make a view of this, which is working i qgis?
    – ulan
    Mar 22, 2013 at 10:29
  • Please, do not forget about "What should I do when someone answers my question?"
    – Taras
    Oct 27, 2022 at 9:56

2 Answers 2


To get unique IDs in views so they display in QGIS I use the row_number() window function. In your example it would be:

SELECT row_number() OVER () As id, ST_ConvexHull(ST_Collect(geom)) FROM baeume;

If this is a one-off analysis you can skip creating a view and use the DB Manager plugin to visualize query results. Its SQL Window tool lets you run any SQL Query you want to against Postgres / SQLite databases and if the query returns a unique ID and a spatial field they can be brought into your QGIS map with just a few clicks.


I'm not familiar with the view concept nor st_collect at all so I may tell something stupid...

If the bid refers to the unique id of your points, you must remove the groupby statement so CvxHull gets all the points as an argument; otherwise you will have nbPoints hulls with one point in each! => something like CREATE OR REPLACE VIEW con_hull_baeume3 AS SELECT( some_id serial PRIMARY KEY as oid, ST_ConvexHull(ST_Collect(geom)) as the_geom) FROM baeume;

Grouping by bid is a good advice if bid is not a unique id and if you want to create a convex hull for each different bid (but I think this is not your case...)

Also, ansswers from How to make a spatial view in PostGIS and add it as a layer in QGIS? could help you, and http://hub.qgis.org/wiki/quantum-gis/Using_views_with_the_postgis_provider shows how to create a qgis acceptable view from postgis.

Good luck!

  • yes thanks. the main problem is that u can not declare a primary in a view of postgresql. so i think i will try the way, that i create a table with primary and try to load this spatial table into postgis layer.
    – ulan
    Mar 22, 2013 at 11:40
  • Ok it works with Tables. Not with views in qgis 1.8. If you want to visualize a convexhull from postgis in qgis , declare a table with primary key and spatial column and make an insert of your convexhull aggregration into it. So perhaps in the future it will also work with views automatically in 1.8. Thank you for your tip with primary key.
    – ulan
    Mar 22, 2013 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.