Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

There is no way to visualize a convexhull in qgis 1.8 lisboa? I have tried following views in Postgis 1.5

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

1.

create or replace view con_hull_baeume3(bid) as
select '0', ST_ConvexHull(ST_Collect(geom)) FROM baeume;

2.

create or replace view con_hull_baeume4(bid) as
select bid, ST_ConvexHull(ST_Collect(geom)) FROM baeume group by bid;

but this one make a convexhull on each of the geometrypoints. 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.

share|improve this question
    
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 '13 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 '13 at 10:29
add comment

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.

share|improve this answer
    
This works for me. Thanks! –  EvilInside Feb 12 at 7:02
add comment

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!

share|improve this answer
    
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 '13 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 '13 at 12:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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