manimaul / njord

Open Source Electronic Navigation Chart Server
https://openenc.com
Apache License 2.0
25 stars 5 forks source link

Why does the map offset when zooming out? #36

Closed echohye closed 11 months ago

echohye commented 1 year ago

Hello, thank you very much for this project. However, I've got the problem in the picture. As shown in the picture, why does the map offset when I zoom in and out. Do you have any solution ? Thanks in advance. image

manimaul commented 1 year ago

@echohye My guess would be an error in the source data. Can you load the S57 source data into OpenCPN and check what happens there?

The red chart outling (PLY) layer is calculated using the M_COVR geometry:

Here is where the geometry is encoded into the tile: https://github.com/manimaul/njord/blob/master/chart_server/src/main/kotlin/io/madrona/njord/geo/TileEncoder.kt#L81 https://github.com/manimaul/njord/blob/master/chart_server/src/main/kotlin/io/madrona/njord/geo/TileEncoder.kt#L105-L110

Here is where M_COVR with CATCOV==1 is read: https://github.com/manimaul/njord/blob/master/chart_server/src/main/kotlin/io/madrona/njord/geo/S57.kt#L67-L69

Info on M_COVR: https://openenc.com/control/symbols/M_COVR/CATCOV

echohye commented 1 year ago

@echohye My guess would be an error in the source data. Can you load the S57 source data into OpenCPN and check what happens there?

The red chart outling (PLY) layer is calculated using the M_COVR geometry:

Here is where the geometry is encoded into the tile: https://github.com/manimaul/njord/blob/master/chart_server/src/main/kotlin/io/madrona/njord/geo/TileEncoder.kt#L81 https://github.com/manimaul/njord/blob/master/chart_server/src/main/kotlin/io/madrona/njord/geo/TileEncoder.kt#L105-L110

Here is where M_COVR with CATCOV==1 is read: https://github.com/manimaul/njord/blob/master/chart_server/src/main/kotlin/io/madrona/njord/geo/S57.kt#L67-L69

Info on M_COVR: https://openenc.com/control/symbols/M_COVR/CATCOV

This is an example data. Based on the element fid query in the database, I found that they are the same feature. At lower zoom levels, they may offset, while at higher zoom levels, they may overlap. I guess there was an issue during the process of querying the data and converting it to PBF format.

echohye commented 1 year ago

Also, it can find this issue in https://openenc.com/enc image

echohye commented 1 year ago

At different levels, using Chart Query,click on the query features and it is found that they have the same attributes but different geometries. Copy their JSON data and display it here. The effect is as follows image

manimaul commented 1 year ago

Ok, I can replicate this problem looking at any small scale chart zoomed out. I think I have the same chart data GB1B20M4.000 from the UKHO collection. Looking at the geometries in the db example:

select layer, st_asgeojson(geom)::JSON from features where chart_id=1;

The raw geometries in the db ----^ are fine which is good as those are coming straight from Gdal.

However, there's definitely a latitude distortion issue in the tile encoding process which I believe is only effecting small scale / very zoomed out tiles. I suspect either the VectorTileEncoder and/or the query is introducing the latitude distortion. https://github.com/manimaul/njord/blob/master/chart_server/src/main/kotlin/io/madrona/njord/db/ChartDao.kt#L91-L101

Screenshot 2023-09-12 at 11 04 03 PM
echohye commented 1 year ago

So is this problem caused by an error during the conversion of this function(ST_AsMVTGeom), or is it caused by a writing error in this class(TileSystem), but why does the ply layer not have this problem😂

echohye commented 1 year ago

ST_AsMVTGeom supports 3857 by default. image

manimaul commented 1 year ago

@echohye - did you want to submit a pull request with the proposed fix?