-
Notifications
You must be signed in to change notification settings - Fork 349
Closed
Description
Given a polygon from an s2 cell, and a polygon from an s2 cell union, what methods could be used to check whether the borders of these cells intersect? In the below example, the both red and green cells are contained by the yellow union, but only the green cell's borders intersect the union's borders.
I have tried using S2ShapeIndex but this does not work. I would be grateful for any suggestions!
bool checkIntersection(const std::vector<uint64_t>& cell_union_ids, uint64_t cell_id) {
std::vector<S2CellId> cell_ids;
for (auto id : cell_union_ids) {
cell_ids.push_back(S2CellId(id));
}
S2CellUnion cell_union;
cell_union.Init(cell_ids);
S2Cell cell(S2CellId(cell_id));
S2Polygon cell_polygon(S2Cell(cell));
S2Polygon cell_union_polygon;
cell_union_polygon.InitToCellUnionBorder(cell_union);
S2BooleanOperation::Options options;
S2PolygonLayer::Options poly_options;
S2PolygonLayer result_layer(&cell_polygon, poly_options);
S2ShapeIndex cell_index;
cell_index.Add(absl::make_unique<S2Polygon::Shape>(&cell_polygon));
S2ShapeIndex union_index;
union_index.Add(absl::make_unique<S2Polygon::Shape>(&cell_union_polygon));
S2BooleanOperation op(S2BooleanOperation::OpType::INTERSECT, &result_layer, options);
bool intersected = op.Build(&cell_index, &union_index);
return intersected && !cell_polygon.is_empty();
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels