Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 56 additions & 3 deletions src/overpass_api/statements/around.cc
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,65 @@ Ranges< Uint32_Index > Around_Statement::calc_ranges(const Set& input, Resource_
return expand(calc_children(ranges(ways)), radius);
}
else
{
Ranges< Uint32_Index > relation_node_ranges;
Ranges< Uint31_Index > relation_way_ranges;
member_ranges(input, rman, relation_node_ranges, relation_way_ranges);
return expand(
ranges(input.nodes).union_(ranges(input.attic_nodes)).union_(
ranges(input.nodes).union_(ranges(input.attic_nodes)).union_(relation_node_ranges).union_(
calc_children(
ranges(input.ways).union_(ranges(input.attic_ways)).union_(
ranges(input.relations).union_(ranges(input.attic_relations))))),
ranges(input.ways).union_(ranges(input.attic_ways)).union_(relation_way_ranges))),
radius);
}
}


void Around_Statement::member_ranges(const Set& input, Resource_Manager& rman,
Ranges< Uint32_Index >& node_ranges, Ranges< Uint31_Index >& way_ranges) const
{
std::vector< Relation_Skeleton::Id_Type > relations;
for (auto it = input.relations.begin(); it != input.relations.end(); ++it)
for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
relations.push_back(it2->id);
std::vector< std::pair< Relation_Skeleton::Id_Type, uint64 > > attic_relations;
for (auto it = input.attic_relations.begin(); it != input.attic_relations.end(); ++it)
for (auto it2 = it->second.begin(); it2 != it->second.end(); ++it2)
attic_relations.push_back(std::make_pair(it2->id, it2->timestamp));

if (!member_ranges_known || member_ranges_timestamp != rman.get_desired_timestamp()
|| member_ranges_relations != relations || member_ranges_attic_relations != attic_relations)
{
// The geometry of a relation is that of its direct node and way members (see
// calc_lat_lons), so take the ranges from their indexes. A relation's own index
// covers its whole extent, which for a long route or a boundary is a large area.
Ranges< Uint32_Index > new_node_ranges;
Ranges< Uint31_Index > new_way_ranges;
if (!input.relations.empty())
{
Request_Context context(this, rman);
new_node_ranges = ranges(relation_node_members(
context, input.relations, {}, Ranges< Uint32_Index >::global(), {}, true).current);
new_way_ranges = ranges(relation_way_members(
context, input.relations, {}, Ranges< Uint31_Index >::global(), {}, true).current);
}
// The same for relations at a past date, with the members calc_lat_lons uses for them.
if (!input.attic_relations.empty())
{
Request_Context context(this, rman);
new_node_ranges = new_node_ranges.union_(ranges(relation_node_members(
context, input.attic_relations, relation_node_member_indices({}, input.attic_relations))));
new_way_ranges = new_way_ranges.union_(ranges(relation_way_members(
context, input.attic_relations, Ranges< Uint31_Index >::global())));
}
member_node_ranges.swap(new_node_ranges);
member_way_ranges.swap(new_way_ranges);
member_ranges_relations.swap(relations);
member_ranges_attic_relations.swap(attic_relations);
member_ranges_timestamp = rman.get_desired_timestamp();
member_ranges_known = true;
}
node_ranges = member_node_ranges;
way_ranges = member_way_ranges;
}


Expand Down
16 changes: 16 additions & 0 deletions src/overpass_api/statements/around.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ class Around_Statement : public Output_Statement

Ranges< Uint32_Index > calc_ranges(const Set& input_nodes, Resource_Manager& rman) const;

private:
// The index ranges of the input relations' members, which calc_ranges needs. It runs
// several times per execution, so they are kept, together with what they depend on:
// the date, the ids of the current relations, and the ids and timestamps of the
// relations at a past date.
void member_ranges(const Set& input, Resource_Manager& rman,
Ranges< Uint32_Index >& node_ranges, Ranges< Uint31_Index >& way_ranges) const;
mutable bool member_ranges_known = false;
mutable uint64 member_ranges_timestamp = 0;
mutable std::vector< Relation_Skeleton::Id_Type > member_ranges_relations;
mutable std::vector< std::pair< Relation_Skeleton::Id_Type, uint64 > > member_ranges_attic_relations;
mutable Ranges< Uint32_Index > member_node_ranges;
mutable Ranges< Uint31_Index > member_way_ranges;

public:

void calc_lat_lons(const Set& input_nodes, Statement& query, Resource_Manager& rman);

bool is_inside(double lat, double lon) const;
Expand Down