circle-to-polygon
circle-to-polygon copied to clipboard
Out of range values for longitude and latitude
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]);
}
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.
@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?
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
// ]
// ]
// ]
// }