1

I am trying to develop an application that makes the most of (Py)Qt Graphics Framework applied to Geographical Maps (think rendering KML files over a tiled background, very similar to Google Maps).

On Web Maps, the conversion between pixels positions (i,j) and geographical positions (latitude,longitude) is not linear, due to Earth Sphericity, and I already perform this conversion successfully with the functions below:

TILE_SIZE = 256
EARTH_RADIUS = 6378137
EQUATOR_CIRCUMFERENCE = 2 * math.pi * EARTH_RADIUS
INITIAL_RESOLUTION = EQUATOR_CIRCUMFERENCE / TILE_SIZE
ORIGIN_SHIFT = EQUATOR_CIRCUMFERENCE / 2.0

def latlontopixels(lat, lon, zoom):
    mx = (lon * ORIGIN_SHIFT) / 180.0
    my = math.log(math.tan((90 + lat) * math.pi/360.0))/(math.pi/180.0)
    my = (my * ORIGIN_SHIFT) /180.0
    res = INITIAL_RESOLUTION / (2**zoom)
    px = (mx + ORIGIN_SHIFT) / res
    py = (my + ORIGIN_SHIFT) / res
    return px, py

def pixelstolatlon(pos, zoom):
    px, py = pos
    res = INITIAL_RESOLUTION / (2**zoom)
    mx = px * res - ORIGIN_SHIFT
    my = py * res - ORIGIN_SHIFT
    lat = (my / ORIGIN_SHIFT) * 180.0
    lat = 180 / pi * (2*atan(exp(lat*pi/180.0)) - pi/2.0)
    lon = (mx / ORIGIN_SHIFT) * 180.0
    return lon, lat

My question is:

Is there a way to transparently "embed" these transformations in the Scene, or View, or even each Item, subclassing and/or overriding some metod(s)?

For example, when I have a "GeoPolyLine" QGraphicsItem, I want to internally store its points as pairs of (lat, lon), probably using QPoint, but I want it to be "seen" by the Scene and the View by "latLonToPixels" coordinates.

Also, since I want my geometries to be "models", I don't think I should make them inherit from QGraphicsView, and I wonder if Qt's Model/View programming model would be useful for handling this mapping itself, instead of the Scene/View model.

heltonbiker
  • 26,657
  • 28
  • 137
  • 252
  • In case some good soul got interested, this is what I have so far, and I plan to keep working, depending on spare time (not so much to be frank): https://github.com/heltonbiker/MapComplete – heltonbiker Mar 22 '16 at 00:31

0 Answers0