GithubHelp home page GithubHelp logo

Bad indexation using h3Line about h3-js HOT 2 CLOSED

uber avatar uber commented on July 19, 2024
Bad indexation using h3Line

from h3-js.

Comments (2)

dfellis avatar dfellis commented on July 19, 2024

I believe h3Line draws from the centerpoint of the h3Indexes that your own points are located in (as it does its work in an IJ coordinate space). I can't see the other points in your screenshot, but the one I do see if very off-center in the hexagon it is located in.

This effect is minimized the smaller the resolution, but it would still be there.

Also, while I don't think this is important at the zoom level this polygon is at, the hexagons are tracing the polygons via greater circle arcs on a sphere, while you're showing a mercator projection map, so places very far to the north or south will have projection distortion that causes the h3line to appear curved on mercator projections at long distances.

from h3-js.

nrabinowitz avatar nrabinowitz commented on July 19, 2024

This is expected behavior. h3Line gives a grid-based path from the origin to the destination; the only guarantees it offers are:

  • The path will be the shortest grid distance (i.e. the fewest number of cells)
  • Each cell in the sequence will be a neighbor of the previous cell
  • No cell in the sequence will be the neighbor of both of the two previous cells (i.e. no "bunching")

It's not expected to align exactly with either a Cartesian line or a great arc, and as in this example the corresponding polyline may not be covered. If you need to cover the polyline "perfectly" (polyline completely covered, no cells that don't intersect the line), the best option is probably:

  • Create a set of H3 indexes
  • Sample down the line, getting the H3 index for each sample. You could use h3.edgeLength as a possible basis for sampling.
  • Take kRing(sampleIndex, 1) and add that to the set. That's effectively buffering the sample by one cell.
  • Test each cell in the set for line intersection.

You may be able to use h3Line instead of sampling (should be fine for relatively short polylines, where the difference between Cartesian and spherical geometry is negligible), but you need the buffering and intersection check to ensure that you're including cells with only a small amount of intersection.

FWIW this is very similar to the new approach to the polyfill algorithm, and it might eventually be something we'd add to the core library.

from h3-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.