[Qgis-developer] Rendering Real-Time Data in QGIS

Florian El Ahdab felahdab at gmail.com
Sat Apr 25 05:38:03 EDT 2009


Hi.

I have been trying to use your tips to render dynamic data (AIS tracks,
probably the same objective as Chee Kiang Lim).

So as to do so, here is what I have done so far:
In a plugin, I have subclassed the MapCanvasItem (in fact, I have used a
renamed VertexMarker class). This subclass is named CustomMapCanvasItem.
I have created a QThread subclass (CustomMapCanvasItemThread), which moves
the CustomMapCanvasItem it received in reference every 500ms (that is, it
setCenter() on the item, then updatePosition()).

Here is my problem:
When I create 1 of those items, everything works fine. With a map loaded, I
can see the Item moving around every 500ms.
But when I create 10 of those items (and consequently 10 threads), I can see
them moving but qgis crashes randomly (between 1 and 10 seconds max).
I suspect this is because there is no synchronization in the access to the
Item data when the thread moves the item.
I have tried to freeze the MapCanvas before updating the position... but it
doesn't work either.

Wonder:
If my explanations are clear enough, can you help me?
Can you detail a little bit further how you would do such a thing for a
large amount of tracks (let's say 5000...).
If there is a need for synchronization, how can I synchronize the access to
the items that I have to add to the MapCanvas (which doesn't synchronize
before using the data apparently.)

Thanks a lot.
Florian

On Thu, Feb 5, 2009 at 7:24 PM, Martin Dobias <wonder.sk at gmail.com> wrote:

> On Thu, Feb 5, 2009 at 1:47 PM, Chee Kiang Lim <cheekiang.lim at gmail.com>
> wrote:
> > Hi,
> >
> > I'm new to the QGIS API and have explored it very briefly. I am trying to
> > write a c++ plugin that will take in the locations of approximately
> > 100 vessels and render their current position (which varies with time)on
> top
> > of an underlying map. I used polygons to represent those vessels on a
> vector
> > layer using the memory provider. Each update involves deleting old
> features
> > and adding new ones followed by refreshing of mapcanvas triggered when
> > changes are committed. As there is a need to render updates at a high
> > frequency for real time display, with positional data coming in at about
> > 1-2Hz, the application was too occupied refreshing the canvas. This makes
> > the application unresponsive to subsequent user commands. I tried
> > using update(Rect of changedExtent) for localized painting/canvas
> refreshing
> > but the rendering is still too taxing. Can you provide some advice on how
> i
> > can go about rendering this huge amount of data in real time?
> >
> > I also tried using rubberbands and they work much better but i need to
> > display text attributes beside each vessel which i do not know how to
> > achieve without labels. Any alternative to rendering text at specific map
> > location that i can update in real time?
>
> Custom map canvas items are perfectly suited for this type of task.
> They don't require map to be re-rendered when the item gets updated.
> You can subclass your own class directly from QgsMapCanvasItem or you
> can create specialized class from QgsRubberBand that will additionally
> draw text labels.
>
> You can also take a look on some brief documentation for map canvas:
> http://wiki.qgis.org/qgiswiki/MapCanvas_API
>
> Martin
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20090425/6b6ccaf3/attachment.html


More information about the Qgis-developer mailing list