Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Functionality for adjacent tiles / quadkeys #118

Closed
daniel-j-h opened this issue Nov 5, 2020 · 4 comments
Closed

Functionality for adjacent tiles / quadkeys #118

daniel-j-h opened this issue Nov 5, 2020 · 4 comments
Milestone

Comments

@daniel-j-h
Copy link
Contributor

There is a parent and a children function to go up or down the tile hierarchy, respectively.

But there is no function right now to go "sideways" to get a tile's siblings on the same zoom level.

Use cases are e.g. buffering a tile with its eight adjacent tiles. I'm finding myself writing small utility functions for this every now and then again and can imagine other people do, too. It would be great to have it in mercantile 🤗

What do you think the api should look like? Something as simple as

mercantile.adjacent_tile(tile)

or more advanced e.g. with a generator returning neighboring tiles and the level they are on (as in breadth-first-search)?

The latter would allow users to re-use this function when they not only want to get one level of adjacent tiles. 🌐

Thoughts? 🤔

@sgillies
Copy link
Contributor

sgillies commented Nov 6, 2020

@daniel-j-h I agree, adjacent tiles would be a nice addition to the API, even without being very advanced. Let's say you have an irregular blob of tiles: a combination of adjacent_tiles() and Python's set could let you build up an irregular buffer quite nicely.

Can you say more about generalizing to the Z dimension? Would the parent's neighbors be included? Would the neighbors of every child be included?

@daniel-j-h
Copy link
Contributor Author

Exactly! Adjacent tiles and set is what I'm using to buffer tiles and then do de-duplication! 🌐

I think I was not clear about the generalization. I don't want to generalize adjacent tiles for different zoom levels.

What I was suggestion instead was generalizing on how many levels of adjacency we want to return.

See this beautifully manually drawn diagram depicting a tile x and its closest friends 👨‍👧‍👦

o o o o o o o
o z z z z z o
o z y y y z o
o z y x y z o
o z y y y z o
o z z z z z o
o o o o o o o

My questions are

  1. Should we provide a simple adjacent_tiles(x) returning [y, ...] (one level of adjacency)
  2. Should we prodive a more advanced adjacent_tiles(x, 2) returning [(x, 0), (y, 1)..., (z, 2)...]
  3. Should we provice 2 as a generator and provide two generators, one to walk in depth-first [(x,0), (y, 1), (z, 1), ...] and one in breadth first order [(x, 0), (y, 1), (y, 1), ...]?
  4. Should x be included in the returned tiles (maybe not because neither parent not children does this)?

Happy Weekend folks ✌️

@dnomadb
Copy link
Contributor

dnomadb commented Nov 6, 2020

@daniel-j-h I was working on a command like this a while back: mapbox/supermercado#19

@daniel-j-h
Copy link
Contributor Author

Coolio! 🙌 Should we consider this then as advanced functionality and it should go in the supermercado project? And only have the adjacent tile function here, returning directly neighboring tiles?

daniel-j-h added a commit to daniel-j-h/mercantile that referenced this issue Mar 1, 2021
@sgillies sgillies added this to the 1.2.0 milestone Mar 8, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants