geojson2h3 icon indicating copy to clipboard operation
geojson2h3 copied to clipboard

Conversion into Feature Set

Open chninja opened this issue 3 years ago • 4 comments

Hi,

I am doing a small prototype app for a research project of mine. I am running into an issue with h3SetToFeatureCollection where upon further inspection the coordinates are not even near the area of my polygon. I took a screen shot of the output cells of my polygon in h3 index longs and converted one of the hexagons into a lat long to verify that my hexagons where in the right area (New York coordinates). My coordinates once converted to h3SetToFeature are wrong and as a result not showing up on my map. I have a work around of just building my own function along with the h3 api functions. But I am wondering if I am just not doing something right.

Screen Shot 2022-01-22 at 1 33 13 PM

chninja avatar Jan 22 '22 17:01 chninja

Can you paste in the inputs you're using? This is hard to diagnose from the screenshots.

My suspicion, however, is that you're running into this issue - it looks like the polygon arc from 145.56 longitude to -34.76 longitude crosses > 180 degrees of longitude and likely causes H3 to misinterpret the polygon.

I think I could fix this issue in geojson2h3 and h3-js, because we could take an optional param to determine shape based on winding order, but it might take some work, and would likely invoke a slower algorithm.

nrabinowitz avatar Jan 24 '22 17:01 nrabinowitz

Hi,

Yes I can. This my code

      this.hexagons = geojson2h3.featureToH3Set(polygon, 10);
const geojson = geojson2h3.h3SetToFeatureCollection(Object.keys(this.hexagons), hex => ({value: 0.5}));

But I also used this with the same problem const geojson = geojson2h3.h3SetToFeature(this.hexagons[0]);.

Screenshot is the coordinates of the polygon and image of area.

Screen Shot 2022-01-24 at 2 58 25 PM

Screen Shot 2022-01-24 at 2 57 53 PM

The coordinates of my hexagon seem right. Is is the same issue as described above ?

chninja avatar Jan 24 '22 19:01 chninja

const geojson = geojson2h3.h3SetToFeature(this.hexagons[0]) seems wrong, the input should be an array of strings, this looks like just a string.

geojson2h3.h3SetToFeatureCollection(Object.keys(this.hexagons), ...) seems wrong, because this.hexagons is an array of strings, so Object.keys(this.hexagons) is going to be a list of array indexes (as strings): ["0", "1", ...]

nrabinowitz avatar Jan 24 '22 20:01 nrabinowitz

@nrabinowitz Well that was a simple fix! Thanks

chninja avatar Jan 24 '22 20:01 chninja