[wxpython-users] Live map widget

wxPython user mailing list, post #18,561
Author:
Date:
Subject:
 Alex Garbino
 2008-07-19 14:32:11
 [wxpython-users] Live map widget
Hello,

I'm just starting with python, and I'm trying develop a widget that
shows my position on a map, and updates it as new position information
comes in.
I found some examples with tk (pyGPS), but I want to use wxPython.
Furthermore, this is to use in a racecar (track the car position as it
goes around the circuit), so I don't need to use some big database of
the world (like basemap in the matlibplot module); I can draw the map
form aerial pictures (from Google earth) as a vector graphic, or I
could also do a few laps and use that data to draw the map.

Can someone give me some pointers on how to do this?
Specifically, I don't know:
- How I should build the window that draws the map: is it a picture
display? (I've gone through the simple text editor example, and looked
at demos)

- How do I update the position on the track? Do I draw a dot, delete
it, and then redraw it? (I get GPS position data every second)

- I found some examples (in the pyGPS/basemap examples) on how to
convert the lat/long to x,y coords, but how do I draw a dot on the map
with this (hopefully an example is out there..)


Thanks!
Alex
_______________________________________________
wxpython-users mailing list
[email protected]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Author:
Date:
Subject:
 Alec Bennett
 2008-07-19 18:59:17
 Re: [wxpython-users] Live map widget
I'm sure there's a much better way to do this, but if I were doing it the first thing I'd try is pasting an icon onto a larger picture, and then updating that picture on my canvas. Personally I'd use the PIL for this, and update a wxpython widget.

Off the top of my head, for the PIL part, something like:

import Image
map = Image.open(picture_of_your_map).convert('RGBA')
car = Image.open(car_icon).convert('RGBA')

map.paste(car, (x_coord, y_coord), car)

map.save(whatever_fname, quality = 95)

Then update your wx image:

bmp = wx.Image(whatever_fname, wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
map_pic = wx.StaticBitmap(panel, -1, bmp, pos=(0,0), size=(1024,768))

Let me know if you need more details on creating your panel and all that and I'll expand.


Disadvantages:

- slow, but should be able to keep up with every second

- you'll definitely get lots of flicker. If that's an issue, you might look into a more correct way of doing this, which is double buffering. But personally I've tried getting double buffering with plain old images working a couple of times and always walked away defeated and exhausted.

- another way to reduce flicker, be much faster, and more Pythonic, would be to use a String-IO instead of writing the file to your harddrive every time. Or you might try the wx load from stream function.

- I have no idea how to convert your GPS position to map position, but if its the same track all the time you might be able to calibrate it?

I'd point out that you could also do this with Google Earth Plus (the "plus" part allows syncornization with a GPS), but what fun would that be. But note that if you do take that approach, it works even if you're offline, you just have to do a "fly-by" beforehand to cache the location.









_______________________________________________
wxpython-users mailing list
[email protected]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Author:
Date:
Subject:
 Robin Dunn
 2008-07-20 12:07:17
 Re: [wxpython-users] Live map widget
Alex Garbino wrote:
> Hello,
>
> I'm just starting with python, and I'm trying develop a widget that
> shows my position on a map, and updates it as new position information
> comes in.
> I found some examples with tk (pyGPS), but I want to use wxPython.
> Furthermore, this is to use in a racecar (track the car position as it
> goes around the circuit), so I don't need to use some big database of
> the world (like basemap in the matlibplot module); I can draw the map
> form aerial pictures (from Google earth) as a vector graphic, or I
> could also do a few laps and use that data to draw the map.
>
> Can someone give me some pointers on how to do this?
> Specifically, I don't know:
> - How I should build the window that draws the map: is it a picture
> display? (I've gone through the simple text editor example, and looked
> at demos)
>
> - How do I update the position on the track? Do I draw a dot, delete
> it, and then redraw it? (I get GPS position data every second)

You can do this with a custom window class without too much trouble.
The basic drawing sequence would be something like this:

1. draw the background image to a bitmap
2. draw icons (or whatever) for the racers on the same bitmap
3. draw the bitmap to the screen

See the samples in the demo and wiki for double buffered drawing for
code showing the basic techniques of doing the above. If you ever have
very many racers or need more than 1 second accuracy then there are some
things you can do to optimize the drawing, but I expect that the simpler
approach will be good enough for most situations.

>
> - I found some examples (in the pyGPS/basemap examples) on how to
> convert the lat/long to x,y coords, but how do I draw a dot on the map
> with this (hopefully an example is out there..)

I don't have any experience with something like this, but I would think
that utilizing some sort of calibration/setup phase would be a good way
to go. In other words, your app can have a mode where you can take GPS
readings and allow the user to manually mark that position on the image
of the track. If you store a number of those positions then when the
software is running in race mode you can take the incoming GPS data and
interpolate positions on your track image based on the prior readings.


--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

_______________________________________________
wxpython-users mailing list
[email protected]
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users