OpenSeaMap Forum

For new registrations: Please create and activate an account. Afterwards send an email to forum.openseamap@gmail.com including a short message and your username to get write access to this forum. Thanks!
Für neue Registrierungen: Bitte erstelle einen neuen Account und schalte ihn frei. Anschließend sende eine kurze Mail mit deinem Nutzernamen an forum.openseamap@gmail.com um Schreibzugriff für dieses Forum zu bekommen. Danke!

You are not logged in.

#1 2016-06-21 20:45:55

colinstone
Member
Registered: 2016-06-21
Posts: 1

Convert mbtiles or .osm.pbf. to kap/BSB charts for OpenCPN

Hi,
Completely new to all this,  so please excuse my Q.

Just been looking at OpenStreetMap and OpenSeaMap to see if I can use OStreetM data in OpenCPN for inland waterway navigation.
Seems that OSeaM uses some OStreetMap data that has been converted to .kap files for use in OpenCPN.
I've found OStreetMap files for European countries in formats including .osm.pbf and also Mbtiles from kap.grade.de covering the inland waterways.
What I can't work out is how to convert to .kap or BSB to use in OpenCPN?

Offline

#2 2016-06-22 14:08:00

seandepagnier
Member
Registered: 2016-06-22
Posts: 3

Re: Convert mbtiles or .osm.pbf. to kap/BSB charts for OpenCPN

I have been looking at mbtiles.  I am considering supporting it in opencpn as a native chart format, but in the meantime they have to be converted.

I have a few commands which work assuming you have a complete rectangle of tiles, but it's horrible it should be a script that can deal with holes:

first convert mbtiles to tiles using mbutil

for i in `ls`; do                                                               
   echo $i                                                                      
   montage -geometry 256x256+0+0 -tile 1x `find $i | sort -r | xargs echo`/out1\
.png;                                                                           
   done                                                                         
                                                                                
# combine columns to make full image                                            
montage -geometry 256x$((256*($(find $(ls -1 | head -n 1) | wc -l)-2)))+0+0 -ti\
le `ls -1 | wc -l`x1 `find | grep out1.png | sort | xargs echo` out2.png        
                                                                                
# clean up intermediate files                                                   
find | grep out1.png | xargs rm                                                 
                                                                                
# flip                                                                          
convert out2.png -flip out.png                                                  
rm out2.png                                 

# use convert to reduce to 16 color?                                            
                                                                                
~/build/imgkap out.png 15 -61.6 15.75 -61.2 out.kap                             
                                                                                

The last bit is work in progress, it doesn't compute the lat/lon correctly...  let me know how it goes, if we can develop a universal script.

Offline

#3 2016-06-22 17:20:06

seandepagnier
Member
Registered: 2016-06-22
Posts: 3

Re: Convert mbtiles or .osm.pbf. to kap/BSB charts for OpenCPN

I have improved the script so that it has the correct coordinates, there is not support for missing tiles though.

#!/bin/bash

#convert tiles to kap
# requires montage and convert from imagemagick as well as imgkap
# kap is a single image not a pyramid, select first directory
#Z=`ls -1 | head -n 1`

#cd $Z
echo "entering `pwd`"

Z=18


# combine into columns
for i in `ls`; do
   echo $i
   montage -geometry 256x256+0+0 -tile 1x `find $i | sort -r | xargs echo`/out1.png;
   done

# combine columns to make full image (this can be slow and use lots of ram)
echo "montage -geometry 256x$((256*($(find $(ls -1 | head -n 1) | wc -l)-2)))+0+0 -tile `ls -1 | wc -l`x1 `find | grep out1.png | sort | xargs echo` out2.png"
montage -geometry 256x$((256*($(find $(ls -1 | head -n 1) | wc -l)-2)))+0+0 -tile `ls -1 | wc -l`x1 `find | grep out1.png | sort | xargs echo` out2.png

# clean up intermediate files
find | grep out1.png | xargs rm

# flip y for kap
convert out2.png -flip out.png
rm out2.png

# use convert to reduce to 16 color for better compression
convert out.png -colors 16 out.png

# calculate lat/lon coordinates
X0=`ls -1 | head -n 1`
X1=`ls -1 | grep -v out.png | tail -n 1`
# .35 is a mystery
STARTLON=$(echo "360*($X0)/2^$Z-180" | bc -l)
ENDLON=$(echo "360*($X1+1)/2^$Z-180" | bc -l)

Y0=`ls -1 $X0 | head -n 1 | sed s/\\.png//1`
Y1=`ls -1 $X0 | tail -n 1 | sed s/\\.png//1` 
STARTLAT=$(echo "pi=4*a(1); n=pi-2*pi*($Y0)/(2^$Z); 180/pi*a(.5*(e(-n)-e(n)))" | bc -l)
ENDLAT=$(echo "pi=4*a(1); n=pi-2*pi*($Y1+1)/(2^$Z); 180/pi*a(.5*(e(-n)-e(n)))" | bc -l)

imgkap out.png $STARTLAT $STARTLON $ENDLAT $ENDLON ../out.kap
rm out.png

Offline

Board footer

Powered by FluxBB