Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ add GDAL_DATA to env GDAL_DATA=c:\Program Files\GDAL\gdal-data
2. download imgkap.exe
http://www.dacust.com/inlandwaters/imgkap/

3. the python script
3. download pngquant.exe
https://pngquant.org/

4. the python script

You can find the script also at http://www.wellenvogel.net/software/bsb_from_moac/index.php

4. On Linux Systems you need to compile imgkap by your own - but this is easy (Thanks to Oleg for his description)
5. On Linux Systems you need to compile imgkap by your own - but this is easy (Thanks to Oleg for his description)

sudo aptitude install git gcc python-gdal libfreeimage-dev
sudo aptitude install git gcc python-gdal libfreeimage-dev pngquant

git clone https://github.com/nohal/imgkap.git

Expand Down
30 changes: 24 additions & 6 deletions convert_to_bsb.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,19 @@ def imgkap():
else:
return "imgkap.exe"

def pngquant():
sysname, nodename, release, version, machine = os.uname()
if sysname == "Linux":
return "pngquant"
else:
return "pngquant.exe"


#------------------------------------
def convertChartListGDAL(chartlist):


imgkapbin=imgkap()
pngquantbin=pngquant()
for chart in chartlist:

dataset = gdal.Open( chart, gdal.GA_ReadOnly )
Expand All @@ -133,8 +142,12 @@ def convertChartListGDAL(chartlist):
(lrlon,lrlat)=gdal.ApplyGeoTransform(geotr,dataset.RasterXSize,dataset.RasterYSize)
log("raster: ullat=%f ullon=%f lrlat=%f lrlon=%f"% (geotr[3],geotr[0],lrlat,lrlon))
(lrlon,lrlat,z)=transformer.TransformPoint(lrlon,lrlat,0)
cmd="%s %s %f %f %f %f"% (imgkap(),chart,ullat,ullon,lrlat,lrlon)
log("running "+cmd)
if chart.lower().endswith(".png"):
cmd="%s 127 -f --ext .png %s" % (pngquantbin,chart)
log("running: %s " % cmd)
os.system(cmd)
cmd="%s %s %f %f %f %f"% (imgkapbin,chart,ullat,ullon,lrlat,lrlon)
log("running: %s " % cmd)
os.system(cmd)

#from gdal2tiles.py
Expand All @@ -149,7 +162,8 @@ def metersToLonLat(mx,my):

#------------------------------------
def convertChartListDirect(chartlist):

imgkapbin=imgkap()
pngquantbin=pngquant()
for chart in chartlist:
log("direct "+chart)
f=open(chart, "rb")
Expand Down Expand Up @@ -198,8 +212,12 @@ def convertChartListDirect(chartlist):
log(chart+" raster: ullat=%f ullon=%f lrlat=%f lrlon=%f"% (uly,ulx,lry,lrx))
(ullon,ullat)=metersToLonLat(ulx, uly)
(lrlon,lrlat)=metersToLonLat(lrx, lry)
cmd="imgkap.exe %s %f %f %f %f"% (chart,ullat,ullon,lrlat,lrlon)
log("running "+cmd)
if chart.lower().endswith(".png"):
cmd="%s 127 -f --ext .png %s" % (pngquantbin,chart)
log("running %s" % cmd)
os.system(cmd)
cmd="%s %s %f %f %f %f"% (imgkapbin,chart,ullat,ullon,lrlat,lrlon)
log("running %s" % cmd)
os.system(cmd)


Expand Down
Binary file added pngquant.exe
Binary file not shown.