{"action":"closed","issue":{"url":"https://api.github.com/repos/mapnik/mapnik/issues/2648","labels_url":"https://api.github.com/repos/mapnik/mapnik/issues/2648/labels{/name}","comments_url":"https://api.github.com/repos/mapnik/mapnik/issues/2648/comments","events_url":"https://api.github.com/repos/mapnik/mapnik/issues/2648/events","html_url":"https://github.com/mapnik/mapnik/issues/2648","id":54937993,"number":2648,"title":"Bad reprojection of antimeridian query bbox","user":{"login":"craigds","id":32112,"avatar_url":"https://avatars.githubusercontent.com/u/32112?v=3","gravatar_id":"","url":"https://api.github.com/users/craigds","html_url":"https://github.com/craigds","followers_url":"https://api.github.com/users/craigds/followers","following_url":"https://api.github.com/users/craigds/following{/other_user}","gists_url":"https://api.github.com/users/craigds/gists{/gist_id}","starred_url":"https://api.github.com/users/craigds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/craigds/subscriptions","organizations_url":"https://api.github.com/users/craigds/orgs","repos_url":"https://api.github.com/users/craigds/repos","events_url":"https://api.github.com/users/craigds/events{/privacy}","received_events_url":"https://api.github.com/users/craigds/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-20T20:53:07Z","updated_at":"2015-01-27T22:44:51Z","closed_at":"2015-01-27T22:44:51Z","body":"Maps are hard in New Zealand.\r\n\r\nWe'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.)\r\n\r\nSome data near the antimeridian is missing from the rendered image, due to a badly calculated query bbox.\r\n\r\nThe bug happens when all of these are true:\r\n * the map is in [NZTM](http://spatialreference.org/ref/epsg/nzgd2000-new-zealand-transverse-mercator-2000/).\r\n * the layer is in WGS84\r\n * the map's `maximum-extent` in NZTM covers the antimeridian\r\n * there is data quite close to the antmeridian (within a few degrees of +/- 180)\r\n\r\nIt seems the logic for calculating the query bbox in this instance is:\r\n\r\n * take render extent in NZTM (covers a big part of the world, since this a low zoom level)\r\n * crop it to the map's `maximum-extent`, and potentially buffers it a little (0px in this case)\r\n * interpolates the extent in NZTM into a 20-point box.\r\n\r\nso far so good - see screenshot: \r\n![parcel-rendering-before-reprojection](https://cloud.githubusercontent.com/assets/32112/5825721/732c8a88-a152-11e4-881b-8ee59b515783.png)\r\n\r\nThen:\r\n\r\n * reprojects each of the 20 points into WGS84\r\n * takes the bounding-box of the 20 reprojected points.\r\n * 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.\r\n\r\n![parcel-rendering-after-projection](https://cloud.githubusercontent.com/assets/32112/5825762/b2c39632-a152-11e4-853a-ddab2efe9174.png)\r\n\r\n\r\nHere's a [fairly minimal testcase](https://drive.google.com/file/d/0B39m5rsOl0o_WDY5VUU2UDA0Szg/view?usp=sharing) (a few points) which demonstrates the render gap across the antimeridian.\r\n\r\nI 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.\r\n\r\nA 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."}}