gabzim / circle-to-polygon

Receives a Coordinate, a Radius and a Number of edges and aproximates a circle by creating a polygon that fills its area
ISC License
113 stars 29 forks source link

This package is giving invalid geocodes as polygon coordintaes, when calling with some edge geocode #6

Closed sanjaykumarns closed 4 years ago

sanjaykumarns commented 6 years ago

If we call this package with the below values, it's is giving some point which cannot be plotted in the google map.

var circleToPolygon = require("circle-to-polygon")
const coordinates = [ -179.9745, -22.3023]; //[lon, lat]
const radius = 50000;                           // in meters
const numberOfEdges = 500;                     //optional that defaults to 32

let polygon = circleToPolygon(coordinates, radius, numberOfEdges);

In the result, there are some point like:

[-180.02911542185794, -21.856002776317947] (long lat format) which cannot be plotted in the google map.

johachi commented 4 years ago

I have started to do a lot of plotting of data on maps and have been reading up on this.

Any longitude value less than -180 or bigger than 180 is obviously an invalid longitude value. However, the current geoJSON specification has a problem. This problem is easiest to explain with a LineString, and then expanded to include polygons.

Let's say that you have 2 lines

How do you tell these two lines apart? Please remember that direction is important. Line [[179, 90], [-179, 90] ] is not the same line as [[-179, 90], [179, 90]].

One popular solution is to break the rule, and write line X as [[179, 90], [181, 90]]. However, the recommended solution is to break the lines into a MultiLine and have it as [[[179, 90], [180, 90]], [[-180, 90], [-179, 90]]]. The same problem occur for polygons and are solved in the same way.

This software seem to be using the first approach to this problem. I don't know if that is intended behavior from @gabzim or not.

johachi commented 4 years ago

I will close this issue since it is a duplicate of #4 . I have also added #4 to the TODO list hand hope to have it solved for the next version release.