-
Notifications
You must be signed in to change notification settings - Fork 229
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
Comments
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". |
Hi,
Thanks for quick response.
double fromLat = -37.79954720;
double fromLng = 144.76014430;
double fromLat1 = -37.69772770;
double fromLng1 = 144.85909800;
double fromLat2 = -37.69772786;
double fromLng2 = 144.85909800;
double fromLat3 = -37.69772776;
double fromLng3 = 144.85909800;
Map<Double,Double> latLon = new HashMap<Double, Double>();
latLon.put(fromLat, fromLng);
latLon.put(fromLat1, fromLng1);
latLon.put(fromLat2, fromLng2);
latLon.put(fromLat3, fromLng3);
List<S2CellId> s2CellIdList = new ArrayList<S2CellId>();
List<S2CellId> s2CellIdListNew = new ArrayList<S2CellId>();
S2CellId s2CellId = null;
Set<Map.Entry<Double, Double>> set = latLon.entrySet();
//creation of cell
for (Map.Entry<Double, Double> me : set) {
S2LatLng s2LatLng = S2LatLng.fromDegrees(me.getKey(), me.getValue());
s2CellId = S2CellId.fromLatLng(s2LatLng);
System.out.println("Level -->" + s2CellId.level()); // level always coming as 30. i want to set the level to 12
System.out.println("Id -->" + s2CellId.id());
s2CellIdList.add(s2CellId);
}
//get only the cellid within 5km.
for (S2CellId tempCellId : s2CellIdList) {
tempCellId.getAllNeighbors(1, s2CellIdListNew);
for (S2CellId tempNearCellId : s2CellIdListNew) {
System.out.println("tempNearCellId-->"+ tempNearCellId.id());
if(tempNearCellId.isValid())
System.out.println("valid -->"+ tempNearCellId.isValid());
}
s2CellIdListNew.clear();
System.out.println("Completed for cell id -->"+tempCellId.id() );
}
I want to get only cellid’s within 5km.
|
I'm not a developer on this ticket tracker, but it's widely considered bad etiquette to
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. |
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.
The text was updated successfully, but these errors were encountered: