seandepagnier / mbtiles-nautical-tools

tools for manipulating and converting mbtiles for nautical purposes
9 stars 1 forks source link

kap2mbtiles fails on optional missing kap headers #1

Open damianham opened 6 years ago

damianham commented 6 years ago

from this document it states that WPX, WPY, PWX and PWY are optional https://opencpn.org/wiki/dokuwiki/doku.php?id=opencpn:supplementary_software:chart_conversion_manual:bsb_kap_file_format

WPX – Polynomial longitude to x - optional. The Polynomials is an alternative to REF points for georeferencing. OpenCPN uses these polynomials if they are available. The existence of polynomials is a condition for using noaa:s chart reprojection tool. PWX – Polynomial x to longitude - optional WPY – Polynomial latitude to y - optional PWY – Polynomial y to latitude - optional

so it fails with the message "input kap has not enough polynominals" with this kap header

! - KAP File VER/3.0 CRR/2016, OpenSeamMap. All rights reserved. CHT/NA=L8-64-128-24-24,NU=8-64-128-24-24 CHF/Overview CED/SE=1,RE=2,ED=12/01/2017 BSB/NA=L8-64-128-24-24,NU=8-64-128-24-24,RA=6144,6144,DU=220 ORG/OpenSeaMap MFR/OpenSeaMap KNP/PR=MERCATOR,GD=WGS84,SC=1953125.0,SD=LAT,UN=METRES,SK=0.0,TA=90.0,PI=UNKNOWN ,SP=UNKNOWN,PP=8.795380589676796 REF/1,0,0,66.51326044311185,0.0 REF/2,6144,0,66.51326044311185,33.75 REF/3,6144,6144,48.922499263758255,33.75 REF/4,0,6144,48.922499263758255,0.0 PLY/1,66.51326044311185,0.0 PLY/2,66.51326044311185,33.75 PLY/3,48.922499263758255,33.75 PLY/4,48.922499263758255,0.0 DTM/0.0,0.0 CPH/0.0 OST/1 IFM/7

seandepagnier commented 6 years ago

The current code requires these parameters. It should be possible to generate them from the ply and ref points. opencpn does this if internally they are missing, but no logic to generate them exists in this script.

Why are you converting kap to mbtiles? I am curious what your application is.

damianham commented 6 years ago

any ideas how to generate them from the REFs ? I want to use the kaps as a source for an openlayers web map so it can be used offline I am building a product that does many things - including an AIS monitor

seandepagnier commented 6 years ago

The polynomials constants can be derived by using least squares based on the ref points. In the case of only 4 ref points at the corners, it would be linear.

Keep in mind that converting kap to mbtiles typically makes a larger file because mbtiles have fixed scales where kap is arbitrary. I would seek data already in mbtiles format if possible.

damianham commented 6 years ago

I wished I could say that explanation helped me :-) Plenty of disk space available - it is a least cost item.