This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Create an offline map from collection of tiles

Tags: None
(comma "," separated)
Beacon11
Registered Member
Posts
35
Karma
0
Hello. I have a computer that's not connected to the internet, and I have a map that is tiled according to OSM specs but is not online. How would I got about creating a map using this information? To the best of my understanding, the .dgml files have two ways of working: from an installmap, and from a tile server. I have neither, so I'm uncertain how to proceed.

I would appreciate any advice!
Beacon11
Registered Member
Posts
35
Karma
0
It's worth mentioning that my tiles do not cover the entire planet; I'm okay with the rest just being black (which I assume will be the case?).
User avatar
tackat
KDE Developer
Posts
131
Karma
0
OS
It shouldn't be a problem if you specify an invalid (or no?) tile server with the data being present on the hard disc already. it's also no problem if some tiles simply don't exist as long as the level 0 tile does exist.

Any more questions?
Beacon11
Registered Member
Posts
35
Karma
0
tackat wrote:it's also no problem if some tiles simply don't exist as long as the level 0 tile does exist.


Ah! This may be the problem I'm having. Basically, I have map sections only at very high zoom levels (e.g. 18). I don't have a level 0 tile, which may explain why I can't seem my high zoom tiles either, even when I zoom in super far. Can I get away with making just a black level 0 tile? Then even skipping zoom levels will be okay?
User avatar
tackat
KDE Developer
Posts
131
Karma
0
OS
IIRC Nowadays this should work indeed. Personally I'd recommend to write a script that would create the remaining levels.

With graphics magick installed it should work about like this:
Basically this script takes the input path as a first parameter where the higher level tiles are located, the input level (e.g. 18) tells the input level. And the Output path is the path where the next lower level (e.g. 17) should get stored. XSTART allows you to start at a certain x-position (in case you need to restart the script due to errors after partial completion). I forgot what the -s OPT parameter did exactly.

Calling this script multiple times will bring you down to level 0 eventually.

USE AT YOUR OWN RISK!!! Beware: I haven't tested this code recently and it contains enough "rm"s to be cautious!!!!!

Code: Select all
#!/bin/bash
INPATH=$1
INLEVEL=$2
OUTPATH=$3
XSTART=$4
OPT=$5
OUTLEVEL=$((INLEVEL-1))
INBLACK="$3/black.png"
WIDTH=4096

echo "Input Path: " $INPATH
echo "Input Level: " $INLEVEL
echo "Output Path: " $OUTPATH

HORNUMBER=$((2**$OUTLEVEL))
VERNUMBER=$((2**$OUTLEVEL))

echo $HORNUMBER " tiles in horizontal direction"
echo $VERNUMBER " tiles in vertical direction"

X=$(($XSTART))
Y=0

while [ $X -lt $HORNUMBER ]
do
    mkdir -p $OUTPATH"/"$X
    convert -size $((WIDTH))x$((WIDTH)) xc:black "$INBLACK"
    echo "Creating directory: "$OUTPATH"/"$X
    while [ $Y -lt $VERNUMBER ]
    do
   echo "Processing picture"
   INPUTTL="$INPATH/$((X*2))/$((Y*2)).png"
   INPUTTR="$INPATH/$((X*2+1))/$((Y*2)).png"
   INPUTBL="$INPATH/$((X*2))/$((Y*2+1)).png"
   INPUTBR="$INPATH/$((X*2+1))/$((Y*2+1)).png"
   if [ ! -f "$INPUTTL" ];
   then
           echo "Blackening 1: $INPUTTL"   
      INPUTTL=$INBLACK
   fi
   if [ ! -f "$INPUTTR" ];
   then
           echo "Blackening 2: $INPUTTR"   
      INPUTTR=$INBLACK
   fi
   if [ ! -f "$INPUTBL" ];
   then
           echo "Blackening 3: $INPUTBL"   
      INPUTBL=$INBLACK
   fi
        if [ ! -f "$INPUTBR" ];
   then
           echo "Blackening 4: $INPUTBR"   
      INPUTBR=$INBLACK
   fi
   if ( [ $INPUTTL = $INBLACK ] && [ $INPUTTR = $INBLACK ] && [ $INPUTBL = $INBLACK ] && [ $INPUTBR = $INBLACK ] );
   then
      echo "All black"
      if  [ "$OPT" != "-s" ];
      then
         echo "Keeping fully black areas transparent"
         Y=$((Y+1))
         continue
      fi
   fi
   montage -mode concatenate -tile 2x2 "$INPUTTL" "$INPUTTR" "$INPUTBL" "$INPUTBR" "$OUTPATH/tbjoin.png"
   if ( [ "$OPT" != "-s" ] );
   then
      convert "$OUTPATH/tbjoin.png" -resize 50% "$OUTPATH/$X/$Y.png"
      rm "$OUTPATH/tbjoin.png"
   else
      mv "$OUTPATH/tbjoin.png" "$OUTPATH/$X/$Y.png"
   fi

   echo "Output file: "$OUTPATH"/"$X"/"$Y".jpg"
   Y=$((Y+1))
    done
    X=$((X+1))
    Y=0
done
rm $3/black.png

User avatar
tackat
KDE Developer
Posts
131
Karma
0
OS
Oh and btw: the previous script assumes Mercator projection ( = number of tiles in vertical and horizontal direction are equal). I guess that is the case for you.
Beacon11
Registered Member
Posts
35
Karma
0
Thanks for all your help Tackat.

Unfortunately, my map section is 2:1 instead of 1:1, so I'm trying to not add all zoom levels and see if I can skip from zoom level 0 to zoom level 18. Adding the two tiles under zoom level 0 works, but when I zoom to high levels toward the equator, instead of showing my zoom level 18 tiles that I put there (using these formulas but naming in the marble convention of zoom/x/x_y.jpg: http://wiki.openstreetmap.org/wiki/Tile ... .2FC.2B.2B), it starts garbling up the level 0 tiles. I'd love to upload it and show you... it's rather tiny. But I don't know where to upload it. Help?
Beacon11
Registered Member
Posts
35
Karma
0
By the way, I want to make sure you know I'm creating a standalone Qt tool to generate map sections like this. As soon as I get the kinks worked out I can see this functionality being super useful in Marble. Imagine multiple installmaps, with a corner lat/lon and a width/height in meters, with tiles automatically generated where they're supposed to be. Eh?
Beacon11
Registered Member
Posts
35
Karma
0
Wait, wait! It does work! But for some reason, when I use the actual standalone Marble, trying to zoom far enough to see the zoom level of 18 segfaults. Using the Marble program I wrote, I can zoom far enough to see them! Yay! But... why does Marble crash?
Beacon11
Registered Member
Posts
35
Karma
0
Okay so I was a little too optimistic... something strange is happening with the tiles.

For example, my tileXs start at 131072 (they go to 131084). Inside the 18/131072/ directory I have a file named 131072_131065.jpg. However, when I turn tile IDs on on my Marble widget, 131072_131065 is a shrunk version of one of the 0 tiles instead of my 131072_131065.jpg. Also, several of my tiles are displayed with the tile ID showing the X being 131071. I don't even HAVE that column in my tiles! What's going on? How are my tiles being displayed in the wrong spot?
Beacon11
Registered Member
Posts
35
Karma
0
Gahh! I named them all backwards! Reference: http://blogs.kde.org/node/3269

OSM has zoom/x/y, so I glanced at the reference and read zoom/x/x_y-- why would it be different. Of course, it's actually zoom/y/y_x :P . Works great now other than Marble crashing!
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Do you have a backtrace (generated using gdb) for this crash?
It will be fairly hard to debug it without a backtrace.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
Beacon11
Registered Member
Posts
35
Karma
0
bcooksley wrote:Do you have a backtrace (generated using gdb) for this crash?
It will be fairly hard to debug it without a backtrace.


Here you are:

(gdb) bt
#0 0x00007ffff5a66100 in Marble::EquirectProjection::screenCoordinates(Marble::GeoDataCoordinates const&, Marble::ViewportParams const*, double*, double&, int&, QSizeF const&, bool&) const () from /usr/local/lib/libmarblewidget.so.12
#1 0x00007ffff5a3491e in Marble::GeoPainter::drawPixmap(Marble::GeoDataCoordinates const&, QPixmap const&) () from /usr/local/lib/libmarblewidget.so.12
#2 0x00007ffff5af2a15 in Marble::RoutingLayer::render(Marble::GeoPainter*, Marble::ViewportParams*, QString const&, Marble::GeoSceneLayer*) ()
from /usr/local/lib/libmarblewidget.so.12
#3 0x00007ffff5a43dc2 in Marble::LayerManager::renderLayer(Marble::GeoPainter*, Marble::ViewParams*, QString const&) ()
from /usr/local/lib/libmarblewidget.so.12
#4 0x00007ffff5a44695 in Marble::LayerManager::renderLayers(Marble::GeoPainter*, Marble::ViewParams*, QStringList const&) ()
from /usr/local/lib/libmarblewidget.so.12
#5 0x00007ffff59d9d13 in Marble::MarbleMapPrivate::paintGround(Marble::GeoPainter&, QRect&) () from /usr/local/lib/libmarblewidget.so.12
#6 0x00007ffff59ccec3 in Marble::MarbleWidget::paintEvent(QPaintEvent*) ()
from /usr/local/lib/libmarblewidget.so.12
#7 0x00007ffff6c5f212 in QWidget::event(QEvent*) ()
from /usr/lib/libQtGui.so.4
#8 0x00007ffff6c0922c in QApplicationPrivate::notify_helper(QObject*, QEvent*)
() from /usr/lib/libQtGui.so.4
#9 0x00007ffff6c0f69b in QApplication::notify(QObject*, QEvent*) ()
from /usr/lib/libQtGui.so.4
#10 0x00007ffff7ac82fc in QCoreApplication::notifyInternal(QObject*, QEvent*)
() from /usr/lib/libQtCore.so.4
#11 0x00007ffff6c6788d in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) ()
from /usr/lib/libQtGui.so.4
#12 0x00007ffff6e21b86 in ?? () from /usr/lib/libQtGui.so.4
#13 0x00007ffff6c58c00 in QWidgetPrivate::syncBackingStore() ()
from /usr/lib/libQtGui.so.4
#14 0x00007ffff6c5f915 in QWidget::event(QEvent*) ()
from /usr/lib/libQtGui.so.4
#15 0x00007ffff70224db in QMainWindow::event(QEvent*) ()
from /usr/lib/libQtGui.so.4
#16 0x00007ffff6c0922c in QApplicationPrivate::notify_helper(QObject*, QEvent*)
() from /usr/lib/libQtGui.so.4
#17 0x00007ffff6c0f69b in QApplication::notify(QObject*, QEvent*) ()
from /usr/lib/libQtGui.so.4
#18 0x00007ffff7ac82fc in QCoreApplication::notifyInternal(QObject*, QEvent*)
() from /usr/lib/libQtCore.so.4
#19 0x00007ffff6e1ef67 in ?? () from /usr/lib/libQtGui.so.4
#20 0x00007ffff6e223e6 in ?? () from /usr/lib/libQtGui.so.4
#21 0x00007ffff6c5b52b in QWidget::repaint(QRect const&) ()
from /usr/lib/libQtGui.so.4
#22 0x00007ffff6c5b5f3 in QWidget::repaint() () from /usr/lib/libQtGui.so.4
#23 0x00007ffff59cd45a in Marble::MarbleWidgetPrivate::repaint() ()
from /usr/local/lib/libmarblewidget.so.12
#24 0x00007ffff59cdf9a in Marble::MarbleWidget::zoomView(int, Marble::FlyToMode) () from /usr/local/lib/libmarblewidget.so.12
#25 0x00007ffff59d1e7b in Marble::MarbleWidget::qt_metacall(QMetaObject::Call, int, void**) () from /usr/local/lib/libmarblewidget.so.12
#26 0x00007ffff7adb06f in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib/libQtCore.so.4
#27 0x00007ffff59e00e1 in Marble::NavigationWidget::zoomChanged(int) ()
from /usr/local/lib/libmarblewidget.so.12
#28 0x00007ffff59e1a93 in Marble::NavigationWidget::qt_metacall(QMetaObject::Call, int, void**) () from /usr/local/lib/libmarblewidget.so.12
#29 0x00007ffff7adb06f in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib/libQtCore.so.4
#30 0x00007ffff72a339e in QAbstractSlider::valueChanged(int) ()
from /usr/lib/libQtGui.so.4
#31 0x00007ffff705e4fc in QSlider::mouseMoveEvent(QMouseEvent*) ()
from /usr/lib/libQtGui.so.4
#32 0x00007ffff6c5f28f in QWidget::event(QEvent*) ()
from /usr/lib/libQtGui.so.4
#33 0x00007ffff6c0922c in QApplicationPrivate::notify_helper(QObject*, QEvent*)
() from /usr/lib/libQtGui.so.4
#34 0x00007ffff6c0fe6b in QApplication::notify(QObject*, QEvent*) ()
from /usr/lib/libQtGui.so.4
#35 0x00007ffff7ac82fc in QCoreApplication::notifyInternal(QObject*, QEvent*)
() from /usr/lib/libQtCore.so.4
#36 0x00007ffff6c0f04e in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool) ()
from /usr/lib/libQtGui.so.4
#37 0x00007ffff6c8f025 in ?? () from /usr/lib/libQtGui.so.4
#38 0x00007ffff6c8d96c in QApplication::x11ProcessEvent(_XEvent*) ()
from /usr/lib/libQtGui.so.4
#39 0x00007ffff6cb9942 in ?? () from /usr/lib/libQtGui.so.4
#40 0x00007ffff2c749d2 in g_main_context_dispatch () from /lib/libglib-2.0.so.0
#41 0x00007ffff2c78858 in ?? () from /lib/libglib-2.0.so.0
#42 0x00007ffff2c78a0c in g_main_context_iteration ()
from /lib/libglib-2.0.so.0
#43 0x00007ffff7af17e3 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#44 0x00007ffff6cb952e in ?? () from /usr/lib/libQtGui.so.4
#45 0x00007ffff7ac6c22 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#46 0x00007ffff7ac6ffc in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#47 0x00007ffff7acad3b in QCoreApplication::exec() ()
from /usr/lib/libQtCore.so.4
#48 0x000000000041dbea in main ()
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Please file a bug report, including that backtrace, at bugs.kde.org so the marble developers can investigate when they get a spare moment.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell