Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

S2CellCreation #11

Open
sivalearn12 opened this issue Dec 13, 2017 · 3 comments
Open

S2CellCreation #11

sivalearn12 opened this issue Dec 13, 2017 · 3 comments

Comments

@sivalearn12
Copy link

Hi,

i want to create the cell using lat and long by mentioning level. Once created, need to loop through the cell to get the nearest cell information. Please guide me for coding

Thanks.

@matthias-mueller
Copy link

Hi,

if you create a new cell from a point, it is always a leaf cell:

S2Cell cell = new S2Cell(S2LatLng.fromDegrees(0.5, 14.3).toPoint());

If you need a particular level, ask for the desired parent cell level (ex: level=5):

S2CellId cellId = cell.id().parent(5);

I am not sure what you mean by "looping".

@sivalearn12
Copy link
Author

sivalearn12 commented Dec 13, 2017 via email

@ryantheleach
Copy link

ryantheleach commented Dec 14, 2017

I'm not a developer on this ticket tracker, but it's widely considered bad etiquette to

  1. Open multiple issues Retrieve cell based on shortest distance #12 Create cell by mentioning level #13

  2. Open issues regarding support, as opposed to bugs.

In addition, Matthias offered a solution above, use parent(n) to get a parent cellid at a given level.

If this were my Repo, and behavior didn't change after being warned, I'd be seriously considering moderation actions against you.

Now to elaborate slightly since I'm not a total asshole.

assuming that S2CellId's are immutable, and that their equality contract is value based, or (their instances are multitons, based on their id)

You could use a Set instead of a list, and use set.add(cell.id().parent(12));

Adding multiple id's to the same set should be ok, as the unique constraint on Sets should ensure you only have 1 level 12 cell if there happens to be duplicates.

Just curious, what application are you using the s2-geometry library for?

More context may provide clues to whether you are using it correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants