turf icon indicating copy to clipboard operation
turf copied to clipboard

Unexpected scale behavior for large areas that intersect WGS84 boundaries

Open lamuertepeluda opened this issue 8 years ago • 4 comments

I tried to double the bounding box of Europe using turf and I get this weird result:

  • Gist: https://gist.github.com/anonymous/5c524c6f302d07ba32674f7b7f2420d0
  • Code to reproduce:
const Europe = /* See GeoJSON */;
const doubleEurope = transformScale(Europe,2);
const boundsOfDoubleEurope = bboxPolygon(bbox(transformScale(Europe, 2)));

The gist is quite self-explanatory.
The wrong result of transformScale clearly affects everything else. What I don't get is why it warps the resulting rectangle, extending its northern side much more than twice (or perhaps it is just inverting some sign).

Other similar odd results:

  • using a different center (e.g. 'ne', 'sw') results in other wrong figures
  • using scale factors higher than 2 results in even stranger figures.

I would expect the scaled figured to be clipped with WGS84 properly, and to never warp.

lamuertepeluda avatar Oct 30 '17 14:10 lamuertepeluda

👍 Definitely a bug 🐛 !

image

CC: @stebogit Any thoughts?

DenisCarriere avatar Oct 30 '17 15:10 DenisCarriere

1.5 scale factor does the following:

image

DenisCarriere avatar Oct 30 '17 15:10 DenisCarriere

I was just looking at this and I believe it's mainly due to the WGS84 projection. Also in this case, like for grids, we should probably work with Mercator. Why it's inverting the vertices I don't know right now.

I guess we could have an optional projection='wgs84'|'meractor' parameter allowing the user to decide (mainly in the borderline cases) or decide to automatically switch to Mercator above a certain dimension/extension of the input, like I did here to correct the expected output.

stebogit avatar Oct 30 '17 16:10 stebogit

👍 @stebogit Yep definitely a projection issue, we can default to Mercator and have an option to preserve the transformation in WGS84.

We tackle this issue for Turf v5.1+

DenisCarriere avatar Oct 30 '17 20:10 DenisCarriere