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

squareGrid creates rectangles #2136

Closed
paligrudic opened this issue Jun 28, 2021 · 3 comments
Closed

squareGrid creates rectangles #2136

paligrudic opened this issue Jun 28, 2021 · 3 comments

Comments

@paligrudic
Copy link

Hi,
I'm trying to create a square grid using https://turfjs.org/docs/#squareGrid, but instead of squares, it returns rectangles. This is how it looks like:

222

When I try to decrease cellSide the rectangles become narrower
555

`
var coordinates = [[
[ 9.628698847753714, -82.659521999370077 ],
[ 9.628698847753714, -82.654521999370077 ],
[ 9.509698847753714, -82.579521999370077 ],
[ 9.509698847753714, -82.654521999370077 ],
[ 9.628698847753714, -82.659521999370077 ],
]]
var polygon = turf.polygon(coordinates);
var bbox = turf.bbox(polygon);

  var cellSide = 0.3;
  var options = {units: 'kilometers'};
  var grid = turf.squareGrid(bbox, cellSide,options);`
@twelch
Copy link
Collaborator

twelch commented Jun 29, 2021

@paligrudic, what version of Turf are you running? Are you sure your code snippet matches your screenshot? When I paste it into the Turf sandbox (running latest 6.4.0) I get what looks like squares, and they are in Antarctica, which I suspect there are no green fields like in your screenshot. Can you try the latest version of Turf?

Turf Sandbox

var coordinates = [[
[ 9.628698847753714, -82.659521999370077 ],
[ 9.628698847753714, -82.654521999370077 ],
[ 9.509698847753714, -82.579521999370077 ],
[ 9.509698847753714, -82.654521999370077 ],
[ 9.628698847753714, -82.659521999370077 ],
]]
var polygon = turf.polygon(coordinates);
var bbox = turf.bbox(polygon);

  var cellSide = 0.3;
  var options = {units: 'kilometers'};
  var grid = turf.squareGrid(bbox, cellSide,options);

console.log(JSON.stringify(grid))

return grid;

image

@JamesLMilner
Copy link
Collaborator

As there's been no follow up I think it's safe to assume this issue is resolved.

@twelch
Copy link
Collaborator

twelch commented Jun 28, 2024

See related issue with possible workaround here - #2638. In short, the behavior of this function changed around July/August 2021 and matches the behavior described by the OP.

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

3 participants