Skip to content

COG tiles near ±180° longitude cause RasterReprojector mesh divergence in Web Mercator mode #366

Closed

Description

@james-willis

Description

When rendering an EPSG:4326 COG that spans the antimeridian (±180° longitude) in a Web Mercator viewport, tiles near the dateline cause RasterReprojector mesh refinement to diverge, producing mislocated rectangles across the map.

The root cause: forwardTo3857 maps nearby source coordinates on opposite sides of ±180° to EPSG:3857 x-values ~40 million meters apart (+20M vs -20M). The mesh triangles connecting these vertices span the entire map, and the reprojection error never converges (error=43200 pixels after 10001 iterations).

Reproduction

Load a global EPSG:4326 COG (e.g. WorldPop population data):

new COGLayer({
  geotiff: 's3://wherobots-examples/data/ppp_2020_1km_Aggregated.tif',
  // ...
})

Console shows:

RasterReprojector: mesh refinement did not converge after 10001 iterations
(maxError=0.125, currentError=43200.00017279999)

Analysis

In _renderSubLayers, for Web Mercator viewports, reprojectionFns.forwardReproject is set to forwardTo3857. For tiles at the antimeridian, this projection has a discontinuity — longitude values like +179° and -179° (which are 2° apart geographically) map to x-values ~40M meters apart in EPSG:3857. The RasterReprojector mesh subdivision cannot resolve this discontinuity no matter how many iterations it runs.

Workaround

We're patching _renderSubLayers to detect antimeridian-crossing tiles by checking if the tile's corner x-coordinates in EPSG:3857 span more than half the world circumference. When detected, forwardTo3857 is wrapped to shift negative x-values by +circumference, making the mesh continuous:

const HALF_CIRCUMFERENCE = WEB_MERCATOR_METER_CIRCUMFERENCE / 2;
const cornerXs = /* compute tile corners in EPSG:3857 */;
if (Math.max(...cornerXs) - Math.min(...cornerXs) > HALF_CIRCUMFERENCE) {
    tileForwardTo3857 = (x, y) => {
        const [px, py] = forwardTo3857(x, y);
        return [px < 0 ? px + WEB_MERCATOR_METER_CIRCUMFERENCE : px, py];
    };
    tileInverseFrom3857 = (x, y) => {
        const unwrapped = x > HALF_CIRCUMFERENCE ? x - WEB_MERCATOR_METER_CIRCUMFERENCE : x;
        return inverseFrom3857(unwrapped, y);
    };
}

Environment

@developmentseed/deck.gl-geotiff: 0.4.0
@developmentseed/raster-reproject: 0.4.0

Activity

  1. kylebarron commented on Mar 24, 2026

    @kylebarron
    Member

    We don't claim to support imagery spanning the antimeridian yet. See #171. You can test out #269 but it's vibe coded, this is important to get right, and I haven't had time to dive into it yet.

    We have an example now of an image rendering correctly when its extent is (-180, -90, 180, 90)

    Image

    The Eoxcloudless example here https://developmentseed.org/deck.gl-raster/examples/cog-basic/


    For imagery actually spanning the antimeridian, we'll probably implement some sort of clipping or wrapping, but I don't know the best approach yet.

    Feel free to make a branch/PR and I can evaluate it in conjunction with #269.

  2. james-willis commented on Mar 25, 2026

    @james-willis
    ContributorAuthor

    I'll raise a PR tomorrow for the mesh divergence issue. My use case isn't "true" wrapping, just half pixel offset or floating point rounding errors.

    My example COG has the following bbox: bounds: [-180.0012493, -72.0004162, 179.9987493, 83.9995832]. For this case just fixing the mesh divergence issue is sufficient.

  3. added 2 commits that reference this issue on Mar 25, 2026
    39cf0d5
    7280242
  4. kylebarron commented on Apr 7, 2026

    @kylebarron
    Member

    I'll raise a PR tomorrow for the mesh divergence issue. My use case isn't "true" wrapping, just half pixel offset or floating point rounding errors.

    My example COG has the following bbox: bounds: [-180.0012493, -72.0004162, 179.9987493, 83.9995832]. For this case just fixing the mesh divergence issue is sufficient.

    FWIW this could also be solved with #351, by clamping the rendered part of the image and the mesh generation to the valid part of the coordinate space.

  5. willjnz commented on Oct 15, 2026

    @willjnz
    Contributor

    I get this issue for images that are near the anti meridian, but do not cross. Here is an example https://dep-public-staging.s3.us-west-2.amazonaws.com/dep_ls_lulc/0-0-9/065/020/2025/dep_ls_lulc_065_020_2025.stac-item.json
    It has 4326 bounds [ 179.1054152054725, -18.47792657674854, 179.96779787822723, -17.65281330691017 ]

  6. kylebarron commented on Oct 15, 2026

    @kylebarron
    Member

    13. I get this issue for images that are near the anti meridian, but do not cross. Here is an example dep-public-staging.s3.us-west-2.amazonaws.com/dep_ls_lulc/0-0-9/065/020/2025/dep_ls_lulc_065_020_2025.stac-item.json
    It has 4326 bounds [ 179.1054152054725, -18.47792657674854, 179.96779787822723, -17.65281330691017 ]

    According to claude, those are the bounds of the valid portion of the image. But there are empty pixels on the right side of the image that overlap the antimeridian, and that's what it's crashing on.

    Hopefully #714 will fix antimeridian handling. I'm planning to work through the internals of that today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions