Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad reprojection of antimeridian query bbox #2648

Closed
craigds opened this issue Jan 20, 2015 · 0 comments
Closed

Bad reprojection of antimeridian query bbox #2648

craigds opened this issue Jan 20, 2015 · 0 comments

Comments

@craigds
Copy link

craigds commented Jan 20, 2015

Maps are hard in New Zealand.

We've found a bug rendering an image of a dataset covering both mainland NZ (west of the antimeridian) and the Chatham Islands (east of the antimeridian.)

Some data near the antimeridian is missing from the rendered image, due to a badly calculated query bbox.

The bug happens when all of these are true:

  • the map is in NZTM.
  • the layer is in WGS84
  • the map's maximum-extent in NZTM covers the antimeridian
  • there is data quite close to the antmeridian (within a few degrees of +/- 180)

It seems the logic for calculating the query bbox in this instance is:

  • take render extent in NZTM (covers a big part of the world, since this a low zoom level)
  • crop it to the map's maximum-extent, and potentially buffers it a little (0px in this case)
  • interpolates the extent in NZTM into a 20-point box.

so far so good - see screenshot:
parcel-rendering-before-reprojection

Then:

  • reprojects each of the 20 points into WGS84
  • takes the bounding-box of the 20 reprojected points.
  • Because of the antimeridian split, some of the points are on the left of the world and some are on the right. However it happens that there's no points exactly at 180, so the query bounds only goes to -177 and +178ish, thus missing some data on the east cape of NZ.

parcel-rendering-after-projection

Here's a fairly minimal testcase (a few points) which demonstrates the render gap across the antimeridian.

I suspect a fix might involve calculating cross-products to determine winding order of the 20-point query box. If the winding order changes when reprojected, the box has hit the antimeridian. Then you could snap the X values outward to +/- 180.

A related performance issue: in this case the query box covers the whole width of the world, so potentially is going to be quite slow. Snapping the X values outward to fix the rendering gap won't fix that performance issue. However an alternative would involve splitting the box into multiple boxes, and that'd probably be much harder.

rcoup added a commit to rcoup/mapnik that referenced this issue Jan 27, 2015
When doing an envelope-points reprojection to a geographic CS, check
the points stay in clockwise order. Otherwise expand the resulting bounds
to include the world.
rcoup added a commit to rcoup/mapnik that referenced this issue Jan 27, 2015
When doing an envelope-points reprojection to a geographic CS, check
the points stay in clockwise order. Otherwise expand the resulting bounds
to include the world.

Includes visual test. Cairo tests aren't finding differences, but the renderer
is doing the right thing.
rcoup added a commit to rcoup/mapnik that referenced this issue Jan 27, 2015
When doing an envelope-points reprojection to a geographic CS, check
the points stay in clockwise order. Otherwise expand the resulting bounds
to include the world.

Includes visual test. Cairo tests aren't finding differences, but the renderer
is doing the right thing.
rcoup added a commit to rcoup/mapnik that referenced this issue Jan 27, 2015
When doing an envelope-points reprojection to a geographic CS, check
the points stay in clockwise order. Otherwise expand the resulting bounds
to include the world.

Includes visual test. Cairo tests aren't finding differences, but the renderer
is doing the right thing.
@rcoup rcoup closed this as completed in 93f67f9 Jan 27, 2015
rcoup added a commit that referenced this issue Jan 28, 2015
When doing an envelope-points reprojection to a geographic CS, check
the points stay in clockwise order. Otherwise expand the resulting bounds
to include the world.

Backport of #2657 from master to 2.3.x. Fixes #2648.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant