rob42 / freeboard-server

Freeboard WIFI server, marine navigation, instruments, NMEA, Seatalk, autopilot, and chartplotter via browser, typically run on Raspberry Pi or laptop
GNU General Public License v3.0
88 stars 25 forks source link

Some charts do not convert accurately #10

Closed rob42 closed 8 years ago

rob42 commented 8 years ago

Leaving this for @RBerliner to add to. "chart conversion failed on numerous charts from Region 7 of the NOAA charts. Mainly it seems not to handle the "chart insets" well."

rob42 commented 8 years ago

I am using as an example, NOAA chart 11552. It has 3 insets that are Extensions (in the language of the BSB files). 11552_3 is in the lower left hand corner and 11552_2 is just above it. At the top margin is 11552_4. The charts 11552_1 (the base chart), 11552_2 and 11552_3 are properly converted. The conversion fails for 11552_4 and the error is signaled with a java.lang.NegativeArraySizeException caused by the fact that the adjusted image has a height of -12 pixels.

The chart scale for all of the insets is 1:40000

Charts 11552_2 and 11552_3 generate tile pyramids with a MinZoom of 12 and a MaxZoom of 15. Chart 11552_4 generates a tile pyramid with a MinZoom of 15 and a MaxZoom of 18. This does not seem right given that the chart insets all have the same scale.

I looked into the code where the min/max zooms are determined and the calculation is dependent on the nw and se lat, lon values for the inset.

I used the program output to find the ne and sw lat and lon that KAPProcessor (or KAPParser) determined. The program generates the following values:

NW Lat  Lon     SE Lat  Lon     
dLat    dLon

11552_2 35.100588288 -77.16013281 35.045127676 -77.0605901199
0.055460612 -0.0995426901 11552_3 35.071764715 -77.24376335 34.9948638141 -77.1430415568
0.0769009009 -0.1007217932 11552_4 35.230615303 -77.097964183 35.126697689 -77.0890019626
0.103917614 -0.0089622204

The dLat and dLon are the differences between the NW and SE lat and lon values (the breadth of the chart insets).

The results for 11552_2 and 11552_3 are "reasonable". The result for 11552_4 is not. The latitude difference is too large by at least a factor of 2 (when you compare it to the height (on the page) of 11552_2. the longitude difference is way too small.

rob42 commented 8 years ago

looks like the problem is that the 11552_4 image is rotated (skewed) and in the KAP file the parameter SK=298.2430556 suggests its about 300deg rotated. SK is thought to be 'Skew Angle' and this seems to confirm it.

There are java libs to rotate and manipulate images, but as the KAP params will need to be adjusted to suit its not trivial.

rob42 commented 8 years ago

Fixed by RBerliners epic fix of the signalk maptools package, adding support for skewed charts!