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

Out of range values for longitude and latitude #4

Open
omidmaldar opened this issue Aug 22, 2018 · 3 comments
Open

Out of range values for longitude and latitude #4

omidmaldar opened this issue Aug 22, 2018 · 3 comments
Labels

Comments

@omidmaldar
Copy link

Hi, I noticed that if the center of the circle is located up north (e.g. [24, 60]) and the radius is a big number like 5000000( 5000 KM) the output includes out of range values for longitude and latitude.
I resolved it by adding the following part before returning the result but wondering if there are cleaner ways of doing it?

for (let i = 0; i < coordinates.length; i++) {
        if (coordinates[i][0] > 180)   coordinates[i][0] = 180;
        if (coordinates[i][0] < -180)  coordinates[i][0] = -180;
        if (coordinates[i][1] < -90) coordinates[i][1] = -90;
        if (coordinates[i][1] > 90)  coordinates[i][1] = 90;
        // console.log(coordinates[i][0], coordinates[i][1]);
    }
@gabzim
Copy link
Owner

gabzim commented Sep 21, 2018

That's a good point, I haven't had time to look into this as the project I'm working on right now is completely different, but I'll see if I can figure something out.

@brandonmcconnell
Copy link

brandonmcconnell commented Nov 2, 2023

@omidmaldar @gabzim Did either of you have a fix for this yet?

@johachi Was this fixed via #6 and/or #9? If so, can we close this, @gabzim?

@hunterwilhelm
Copy link

This issue is still present.

FYI The out-of-range longitude value 204 from this example is correctly understood in some systems, but not others.

const circleToPolygon = require('circle-to-polygon');

const coordinates = [24, 60]; 
const radius = 5000 * 1000; 
const numberOfEdges = 4;

const polygon = circleToPolygon(coordinates, radius, numberOfEdges);
console.log(JSON.stringify(polygon, null, ' '));

//  {
//   "type": "Polygon",
//   "coordinates": [
//    [
//     [
//      204,
//      75.08423579402391
//     ],
//     [
//      -39.36750067319971,
//      37.82647346052107
//     ],
//     [
//      23.99999999999999,
//      15.084235794023924
//     ],
//     [
//      87.36750067319969,
//      37.82647346052106
//     ],
//     [
//      204,
//      75.08423579402391
//     ]
//    ]
//   ]
//  }
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants