question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

toMercator changes polygons geometry

See original GitHub issue

When using toMercator on a polygon that overlap the -180 or 180 longitude, without antimeridian cutting.

The current implementation wraps every point one by one which ends up returning a wrong polygon:

Here is a polygon overlapping the -180 longitude:

code to reproduce the issue:

import { toWgs84, toMercator } from '@turf/projection';

toWgs84(toMercator({
  "type": "Feature",
  "properties": {}, 
  "geometry": {
    "type": "Polygon",
    "coordinates": [[
        [-181, 60],
        [-181, 61],
        [-179, 61],
        [-179, 60],
        [-181, 60]
    ]]
  }
}));

I think that when calling toMercator with a GeoJson, turf should not try to wrap longitude as it does. if this is an acceptable behavior I could submit a PR

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Darunecommented, Mar 14, 2020

I could retry writing tests for this, it has been stalled for way too long, but I might have time next week to digg this out of the dirt

0reactions
rowanwinscommented, Mar 6, 2019

Yeah unfortunately the tests and the code are currently setup to run against individual coordinates rather than seeing them in context of a geometry that is crossing the anti-median, so a bit of thought needs to happen to get things behaving and tested properly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

r - st_transform appears to change the area of the geometry of ...
No, the area of polygons is not guaranteed to remain constant when transforming between different CRSes. The Earth is round, maps & computer ......
Read more >
Solved: Detect Feature Changes for Polygons and Points
Is there any tool for detect feature changes (only geometry) for POINT and POLYGON features? Many thanks in advance ! Solved!
Read more >
Managing Projections — GeoPandas 0.12.2+0.gefcb367.dirty ...
The Coordinate Reference System (CRS) is important because the geometric shapes ... Re-projecting is the process of changing the representation of locations ...
Read more >
Advanced geospatial analysis - Turf.js
Feature <Polygon> - a Polygon representation of the bounding box ... cleanCoords. Removes redundant coordinates from any GeoJSON Geometry.
Read more >
Why does polygon area change when projection is changed ...
Some differences between the two features may be due to the geometry of the input feature. If the feature is built with two-point...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found