uber / h3-js

h3-js provides a JavaScript version of H3, a hexagon-based geospatial indexing system.

Home Page:https://uber.github.io/h3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inverted coordinates

khamaileon opened this issue · comments

In h3 v4.1.0, when using the cellsToMultiPolygon or cellToBoundary functions, the lat and lng values are inverted. It should be (lat, lng) or (lng, lat) in GeoJSON (+ closed loop). Here some sample code that demonstrates the issue:

h3.cellToBoundary("897aa51638bffff", false);
[[2.3280407513160553,48.866418508809375],[2.329773332319682,48.8663663022913],[2.330738889182863,48.86486741339661],[2.329971873027045,48.8634206938187],[2.328239263114671,48.863472879713],[2.32727369826657,48.86497180580943]]
h3.cellsToMultiPolygon(["897aa51638bffff", "897aa51630fffff"], false);

[[[[2.32727369826657,48.86497180580943],[2.3280407513160553,48.866418508809375],[2.329773332319682,48.8663663022913],[2.330738889182863,48.86486741339661],[2.329971873027045,48.8634206938187],[2.328239263114671,48.863472879713]]],[[[2.3353681533087616,48.860318488859306],[2.336135095678257,48.86176524158633],[2.3378675867113197,48.86171306944098],[2.3388331642716147,48.860214165193305],[2.338066258794801,48.8587673958951],[2.3363337388653007,48.85881954741529]]]]

h3.cellToBoundary("897aa51638bffff", true);
[[48.866418508809375,2.3280407513160553],[48.8663663022913,2.329773332319682],[48.86486741339661,2.330738889182863],[48.8634206938187,2.329971873027045],[48.863472879713,2.328239263114671],[48.86497180580943,2.32727369826657],[48.866418508809375,2.3280407513160553]]

h3.cellsToMultiPolygon(["897aa51638bffff", "897aa51630fffff"], true);
[[[[48.86497180580943,2.32727369826657],[48.866418508809375,2.3280407513160553],[48.8663663022913,2.329773332319682],[48.86486741339661,2.330738889182863],[48.8634206938187,2.329971873027045],[48.863472879713,2.328239263114671],[48.86497180580943,2.32727369826657]]],[[[48.860318488859306,2.3353681533087616],[48.86176524158633,2.336135095678257],[48.86171306944098,2.3378675867113197],[48.860214165193305,2.3388331642716147],[48.8587673958951,2.338066258794801],[48.85881954741529,2.3363337388653007],[48.860318488859306,2.3353681533087616]]]]

Ok my bad I didn't specify that polygonToCells should be also in geojson.

const cells = h3.polygonToCells(
  bboxPolygon.geometry.coordinates,
  maxResolution,
  true
);