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.

I have a postgis layer in Qgis that is a result of a complex query. Every screen update, Qgis runs the Query again and that's slow. Any suggestion on how to speed up?

EDIT - Here is the query:

 SELECT 
 parcela.id AS id, 
 st_union(areas.the_geom) AS geom,
  (((((('p'::text || round(avg(to_number(dado.valor -> 'pequena'::text, '99'::text)) * 10::numeric, 2)) || ',m'::text) || round(avg(to_number(dado.valor -> 'media'::text, '99'::text)) * 10::numeric, 2)) || ',g'::text) || round(avg(to_number(dado.valor -> 'grande'::text, '99'::text)) * 10::numeric, 2)) || ',mo'::text) || round(avg(to_number(dado.valor -> 'morta'::text, '99'::text)) * 10::numeric, 2) AS "legenda", 
  round(avg(to_number(dado.valor -> 'pequena'::text, '99'::text)) * 10::numeric, 2) AS pequenas, 
  round(avg(to_number(dado.valor -> 'media'::text, '99'::text)) * 10::numeric, 2) AS medias, 
  round(avg(to_number(dado.valor -> 'grande'::text, '99'::text)) * 10::numeric, 2) AS grandes, 
  round(avg(to_number(dado.valor -> 'morta'::text, '99'::text)) / 10::numeric, 2) AS mortas

  FROM petr.dado, petr.parcela, petr.parcela_rel, petr.areas
  WHERE dado.parcela_id = parcela.id AND parcela_rel.area_id = areas.gid AND parcela_rel.parcela_id = parcela.id
  GROUP BY parcela.id  
share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Hallo

Is it the QGIS rendering that makes things slow or the PostGIS query. Is the query in the definition of a view or why does it need to med evaluated more than once?

If it is the PostGIS query that is the problem, why can't you just make a table out of the query to make it static and add a spatial index to it?

If you need it to be a dynamic query you need to share more information about the query if it might be optimized in some way.

Regards Nicklas

share|improve this answer
    
Hi, It is the Postgis query that is slow, it was defined with RT_SQL Layer, it needs to be dynamic, but doesn't need to be evaluated every single zoom in and out. Thanks. –  Pablo May 5 '11 at 18:22
1  
@Pablo why does it have to be dynamic. maybe you could have one table prepared for use in qgis updated with triggers when things change in the original table. –  Nicklas Avén May 6 '11 at 20:51
    
Nice solution. That solves the problem. Thanks. –  Pablo May 9 '11 at 12:17
add comment

Creating indices on the columns in your WHERE condition will speed things up considerably, if you haven't already done that.

share|improve this answer
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.