Skip to content

rethink tiling geojson #464

Closed
Closed

Description

@ansis

This isn't important right now because the current approach works.

Currently geojson is tiled. If we use 2x32bits per position, we should have enough precision for the entire world without tiling. What would be the performance hit of using the extra space for vector tile features? Could we have different precision for different sources? Would we need to bump up to highp precision in shaders?

Activity

  1. incanus commented on Jun 17, 2014

    @incanus
    Contributor

    Starting to think about this on the native side again, too: mapbox/mapbox-gl-native#328 Original attempt was the same tiling as on WebGL: mapbox/mapbox-gl-native#170

  2. incanus commented on Jun 19, 2014

    @incanus
    Contributor

    @ansis Could you elaborate a bit more on your thoughts here? I'd like to get cracking on the native side, eventually to the extent of allowing arbitrary features that aren't necessarily backed by GeoJSON.

    i.e. should we be thinking about a more generalized data store for non-VT features that GeoJSON or on-the-fly APIs could tap into?

  3. added this to the milestone on Jun 24, 2014
  4. mourner commented on Aug 27, 2014

    @mourner
    Member

    @ansis would love further thoughts on this too. Tiling GeoJSON is currently a problem. #694

  5. mourner commented on Dec 1, 2014

    @mourner
    Member

    Looking at this now... Another way to approach this problem that seems more feasible to me right now is rewriting the tiling algorithm instead of going the precision route. The latter won't solve the problem of loading relatively large GeoJSON data (think 100k OSRM car route across Eurasia), because you'd have to render out-of-view data on higher zoom levels (well pointed out by @kkaefer) and unnecessary precise geometry on lower zoom levels.

    So here are 3 things I want to look at:

    • a more efficient tiling algorithm — the current one doesn't scale well, see GeoJSON-triggered Chrome crash test case #790 (comment) for how fast it fails
    • possibly figuring out the proper zooms levels (instead of hardcoded 1-5-9-13) based on original data precision
    • simplifying geometry on each tiling zoom level
  6. mourner commented on Dec 1, 2014

    @mourner
    Member

    Another idea to explore: tile on demand. Don't cut GeoJSON tiles until you actually zoom to a corresponding zoom / area.

  7. incanus commented on Dec 1, 2014

    @incanus
    Contributor

    The related umbrella issue on the native side is mapbox/mapbox-gl-native#507. With that in mind, and the fact that we'll want to keep the renderers working similarly, the on-demand approach likely won't work as there cannot be a delay between pan/zoom activity and display of overlay data (GeoJSON or otherwise).

  8. mourner commented on Dec 1, 2014

    @mourner
    Member

    there cannot be a delay between pan/zoom activity and display of overlay data (GeoJSON or otherwise)

    Why? There's a delay when displaying vector tile data while it is loaded/processed, so a similar (maybe smalllish) delay for GeoJSON when panning and zooming wouldn't look out of place.

  9. incanus commented on Dec 1, 2014

    @incanus
    Contributor

    so a similar (maybe smalllish) delay for GeoJSON when panning and zooming wouldn't look out of place.

    It would on native mobile. There is a delay for the basemap, but never for the point/polyline data on top of it. I'll try to work up a demo.

  10. mourner commented on Dec 1, 2014

    @mourner
    Member

    OK. I'm currently thinking of an adaptive tiling approach that wouldn't make a delay: split the GeoJSON data top-down in a Quadtree-like fashion, keeping track of the number of vertices in each tile, and stop splitting when we reach a certain number. This way we could minimize the number of actual tiles unlike here, making tiling adaptive based on data density instead of a hardcoded zoom range.

    The only problem with this approach (which looks kinda cool) is that we would need to rethink tile loading logic as well, because getting the covering GeoJSON tiles for a particular map view would involve messaging the worker. @jfirebaugh what do you think? Is this feasible?

  11. mourner commented on Dec 1, 2014

    @mourner
    Member

    @jfirebaugh ha, just realized that all GeoJSON tiles are sent back to the main thread after parsing the data. This is very inefficient — instead we should keep the data in the workers just like we do for vector data, and load on demand.

    @incanus would it be acceptable to have a delay, but a very tiny one, just for loading the tile from another thread (without any tiling/processing work)? The delay would be similar to cached VT and probably not noticeable much.

  12. mourner commented on Dec 1, 2014

    @mourner
    Member

    @jfirebaugh or, for the tile loading, we could return the resulting tile cover (which shouldn't be too big), but not the data itself, so that it's loaded on demand. This way we can keep the tile loading logic but change the way GeoJSON tiles are loaded (so that data is loaded asynchronously when corresponding tile is requested, just like VT).

  13. incanus commented on Dec 1, 2014

    @incanus
    Contributor

    Based on some load testing, actually I think a tiny delay is ok. Parse delay is naturally acceptable, but in testing 1,000 and 3,000 points in Apple's MapKit on an iPhone 5s, I do sometimes see a slight pan/display delay for the 3,000.

    Sample project: https://github.com/incanus/PointTest

    1,000 points: https://dl.dropboxusercontent.com/u/575564/1000points.mov
    3,000 points: https://dl.dropboxusercontent.com/u/575564/3000points.mov

  14. jfirebaugh commented on Dec 2, 2014

    @jfirebaugh
    Contributor

    _getCoveringTiles is called only by _updateTiles, and both of those are private implementation details of Source. The only public interface is update (which is inherently asynchronous), and if necessary GeoJSONSource can override that to do something special.

    Do you have a candidate fast tiling/clipping algorithm that can do tile buffering (which rendering depends on for polygon outlines and cross-tile labeling) and handle the complete range of GeoJSON?

    Agreed that a small delay is fine.

  15. 6 remaining items

  16. mourner commented on Dec 3, 2014

    @mourner
    Member

    Here are some further ideas that seem simple enough and worth implementing:

    • run through all coordinates of all features; for each point, calculate and save the first zoom at which the margin of error for the point encoded into 4096 integers goes below some small threshold; when considering a tile for cutting, we can determine whether to cut or not by looking at the maximum of calculated zooms for each point in the tile. This way we don't compromise precision while not doing unnecessary tiling
    • don't simplify features for each tile; instead run Douglas-Peucker algorithm (fast O(n log n)) once for all features before tiling, saving the deviation of each coord instead of throwing out points; then for each zoom, simplification will be a matter of picking out points less then a particular threshold, making it fast and enabling easier simplification-based heuristics
  17. mourner commented on Dec 3, 2014

    @mourner
    Member

    A work-in-progress repo here: https://github.com/mapbox/tilegeojson
    Making this a separate repo because adaptive GeoJSON slicing can be useful outside the GL land.

  18. mourner commented on Dec 3, 2014

    @mourner
    Member

    Can't believe I didn't think of the following super-simple idea earlier. @jfirebaugh @incanus

    We want to do all the expensive CPU work by preprocessing GeoJSON on load, and then display it at any area/zoom without noticeable delay. But tiling up to z14 to keep precision usually produces too many tiles and is often too slow (imagine the use case of low-coordinate shapes covering most of the world).

    A solution to both problems (load delay & too many tiles): tile the data until we did most of the work; stop tiling when further tiling of a particular tile is cheap. Cheap usually means that the number of coordinates in a tile is low enough. If it's cheap, we can tile further on-demand almost instantly, without delay. Awesome!

  19. mourner commented on Dec 6, 2014

    @mourner
    Member

    The current algorithm in GL JS crashes on 250Kb GeoJSON, but I thought it wouldn't be unreasonable to eventually make it work with a 100Mb file (zip codes, not simplified) that has 33k features with 5.4 million points. Not that it's very practical to load files like this in a web app, but it's a good stress test:

    geojsonvt2

    These are all clipped and simplified 4096 vector tiles (with tiny features filtering), initially sliced to z4 but with on-demand slicing of higher zoom tiles (the viz is a simple canvas app to help debugging). Integrating into GL JS should be easy now. cc @springmeyer @yhahn @tmcw

    update: noticed a bug in the drilldown code, it should be 3 times faster now:

    image

  20. mourner commented on Dec 7, 2014

    @mourner
    Member

    Made it a bit faster since the last comment (in parallel to cooking a dinner):

    image

  21. added a commit that references this issue on Dec 8, 2014
    43260ce
  22. mourner commented on Dec 9, 2014

    @mourner
    Member

    Done, w00t!

  23. mourner commented on Dec 9, 2014

    @mourner
    Member

    Watch that 100Mb zip code file:

    geojson-gl-js-2

  24. kkaefer commented on Dec 9, 2014

    @kkaefer
    Member

    Wow, impressive work!

  25. bFlood commented on Dec 10, 2014

    @bFlood

    that is really impressive, great work mourner

  26. wboykinm commented on Dec 10, 2014

    @wboykinm

    👍 👍

  27. added a commit that references this issue on Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions