Turfjs / Turfjs/turf

turf.square needs mercator coordinates to work correctly

Open
#1,727 1 comment 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

@turf/square
Dominant language
TypeScript
Stars
10.5k
Forks
1k
Avg merge
1h 11m
Merged PRs (30d)
4

Description

I've been struggling with getting a correct turf.square using real world coordinates until I realized I needed to pass mercator coordinates to make it work correctly on earth.

Maybe we could just add a hint in the docs or add a function that detects wgs84 coordinates and makes the correct calculation / conversion.

This is the result doing it with Wgs84 lat long:
Bildschirmfoto 2019-07-07 um 03 12 39

And the expected result with conversion to mercator and back:
Bildschirmfoto 2019-07-07 um 14 39 12

Quick code for the second result:

	var originalbboxx = [-2.440916, 49.4627643, -2.4579404, 49.4828877]
	
	var point1 = [originalbboxx[0], originalbboxx[1]]
	var point2 = [originalbboxx[2], originalbboxx[3]]

	var converted1 = turf.toMercator(point1);
	var converted2 = turf.toMercator(point2);

	var squared = turf.square([converted1[0],converted1[1],converted2[0],converted2[1]] )

	var squarept1 = [squared[0], squared[1]]
	var squarept2 = [squared[2], squared[3]]

	var wsg1 = turf.toWgs84(squarept1);
	var wsg2 = turf.toWgs84(squarept2);

	var newSquaredBbox = [wsg1[0],wsg1[1],wsg2[0],wsg2[1] ]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the turf.square entry point and its documentation, then inspect the toMercator and toWgs84 usage shown in the report. Compare the WGS84 and Mercator examples and establish whether the intended resolution is documentation guidance or changed coordinate handling; done means the selected behavior is documented or works consistently with a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.