uber / h3-js

h3-js provides a JavaScript version of H3, a hexagon-based geospatial indexing system.
https://uber.github.io/h3
Apache License 2.0
874 stars 79 forks source link

polygonToCells fails for some simple large polygons #191

Open liujun3660105 opened 4 months ago

liujun3660105 commented 4 months ago

when the polygon is very large,and the res is more than 0,then has error as follow:

image
liujun3660105 commented 4 months ago

for example:

const regionBox = {
  xmin: -180,
  ymin: -90,
  xmax: 0,
  ymax: 0
};
const polygon = [
  [regionBox.ymin, regionBox.xmin],
  [regionBox.ymax, regionBox.xmin],
  [regionBox.ymax, regionBox.xmax],
  [regionBox.ymin, regionBox.xmax]
];
const hexagons = h3.polygonToCells(polygon, 2);
nrabinowitz commented 3 months ago

This is currently the expected behavior, and should be better documented - the polygonToCells function will reject polygons with arcs > 180 degrees on longitude, because we do not currently enforce winding order so the area enclosed by the polygon is ambiguous (it could stretch across the antimeridian).

The workaround is to break very large polygons into smaller polygons with < 180 degrees of longitude.