From a06ff6f837f18d1b6f5d8d02de5de9f129abb1e4 Mon Sep 17 00:00:00 2001 From: Ilya Zverev Date: Mon, 28 May 2018 15:32:49 +0300 Subject: [PATCH] Extract bbox calculation in the downloader --- conflate/conflator.py | 3 ++- conflate/osm.py | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/conflate/conflator.py b/conflate/conflator.py index f099555..df7585e 100644 --- a/conflate/conflator.py +++ b/conflate/conflator.py @@ -40,7 +40,8 @@ class OsmConflator: 'dataset_id', required='A fairly unique id of the dataset to query OSM') def download_osm(self): - self.osmdata = self.downloader.download(self.dataset.values()) + bboxes = self.downloader.calc_boxes(self.dataset.values()) + self.osmdata = self.downloader.download(bboxes) def parse_osm(self, fileobj): self.osmdata = self.downloader.parse_xml(fileobj) diff --git a/conflate/osm.py b/conflate/osm.py index 454c9dc..4392eb0 100644 --- a/conflate/osm.py +++ b/conflate/osm.py @@ -247,9 +247,7 @@ class OsmDownloader: return result - def download(self, dataset_points): - """Constructs an Overpass API query and requests objects - to match from a server.""" + def calc_boxes(self, dataset_points): profile_bbox = self.profile.get('bbox', True) if not profile_bbox: bboxes = [None] @@ -257,6 +255,17 @@ class OsmDownloader: bboxes = [profile_bbox] else: bboxes = self.split_into_bboxes(dataset_points) + return bboxes + + def download(self, bboxes=None): + """Constructs an Overpass API query and requests objects + to match from a server.""" + if not bboxes: + pbbox = self.profile.get('bbox', True) + if pbbox and hasattr(pbbox, '__len__') and len(pbbox) == 4: + bboxes = [pbbox] + else: + bboxes = [None] query = self.construct_overpass_query(bboxes) logging.debug('Overpass query: %s', query)