diff --git a/src/overpass_api/data/bbox_filter.cc b/src/overpass_api/data/bbox_filter.cc index 4b75a5049..4504dd168 100644 --- a/src/overpass_api/data/bbox_filter.cc +++ b/src/overpass_api/data/bbox_filter.cc @@ -147,6 +147,35 @@ void filter_ways_expensive(const Bbox_Filter& filter, const Way_Geometry_Store& } +/* A way whose index is a single tile (bit 31 clear) has all its nodes in that tile. If + the tile lies inside the bbox, so do all of the way's nodes, and Bbox_Filter::matches + accepts any way with a node inside the bbox (single nodes via contains(), segments via + intersects()). Such ways can be kept without loading their geometry. + + Moves the vectors of those ways from ways to kept. A tile's bounds are the positions + decoded with the lowest and highest ll_lower; every node position in the tile lies + between them. Boxes crossing the antimeridian are left to the exact test. */ +template< typename Way_Skeleton > +void move_ways_in_inner_tiles(const Bbox_Double& bbox, + std::map< Uint31_Index, std::vector< Way_Skeleton > >& ways, + std::map< Uint31_Index, std::vector< Way_Skeleton > >& kept) +{ + if (!(bbox.west <= bbox.east)) + return; + + for (typename std::map< Uint31_Index, std::vector< Way_Skeleton > >::iterator it = ways.begin(); + it != ways.end(); ++it) + { + uint32 idx = it->first.val(); + if ((idx & 0x80000000) || it->second.empty()) + continue; + if (::lat(idx, 0) >= bbox.south && ::lat(idx, 0xffffffff) <= bbox.north + && ::lon(idx, 0) >= bbox.west && ::lon(idx, 0xffffffff) <= bbox.east) + kept[it->first].swap(it->second); + } +} + + template< typename Relation_Skeleton > void filter_relations_expensive(const Bbox_Filter& filter, const std::vector< std::pair< Uint32_Index, const Node_Skeleton* > > node_members_by_id, @@ -203,8 +232,14 @@ void Bbox_Filter::filter(const Statement& query, Resource_Manager& rman, Set& in if (!bbox.valid()) return; - //Process ways - filter_ways_expensive(*this, Way_Geometry_Store(into.ways, query, rman), into.ways); + //Process ways. Ways entirely within inner tiles need no geometry. + { + std::map< Uint31_Index, std::vector< Way_Skeleton > > kept; + move_ways_in_inner_tiles(bbox, into.ways, kept); + filter_ways_expensive(*this, Way_Geometry_Store(into.ways, query, rman), into.ways); + for (std::map< Uint31_Index, std::vector< Way_Skeleton > >::iterator it = kept.begin(); it != kept.end(); ++it) + into.ways[it->first].swap(it->second); + } Request_Context context(&query, rman); {