def test_tile_children(self): x, y, z = (619, 355, 10) children_calculated = geomath.tile_children(x, y, z) children_known = ((1238, 710, 11), (1238, 711, 11), (1239, 710, 11), (1239, 711, 11)) self.assertTrue(len(children_calculated) == 4) for c in children_known: self.assertTrue(c in children_calculated)
def test_tile_children_str(self): tile = '619,355,10,a' children_calculated = geomath.tile_children(tile) children_known = ((1238, 710, 11), (1238, 711, 11), (1239, 710, 11), (1239, 711, 11)) self.assertTrue(len(children_calculated) == 4) for c in children_known: self.assertTrue(c in children_calculated) # test when return_str = True children_calculated_str = geomath.tile_children(tile, return_str=True) children_known_str = ('1238,710,11,a', '1238,711,11,a', '1239,710,11,a', '1239,711,11,a') self.assertTrue(len(children_calculated_str) == 4) for c in children_known_str: self.assertTrue(c in children_calculated_str)
def test_tile_children(self): x,y,z = (619,355,10) children_calculated = geomath.tile_children(x,y,z) children_known = ( (1238,710,11), (1238,711,11), (1239,710,11), (1239,711,11)) self.assertTrue(len(children_calculated) == 4) for c in children_known: self.assertTrue(c in children_calculated)
def test_tile_children_str(self): tile = '619,355,10,a' children_calculated = geomath.tile_children(tile) children_known = ( (1238,710,11), (1238,711,11), (1239,710,11), (1239,711,11)) self.assertTrue(len(children_calculated) == 4) for c in children_known: self.assertTrue(c in children_calculated) # test when return_str = True children_calculated_str = geomath.tile_children(tile,return_str=True) children_known_str = ( '1238,710,11,a', '1238,711,11,a', '1239,710,11,a', '1239,711,11,a') self.assertTrue(len(children_calculated_str) == 4) for c in children_known_str: self.assertTrue(c in children_calculated_str)
def update_tiles(cls, count=config.COUNT_UPDATE, gt_key_name=None): """Update several tiles and puts them into datastore.""" if not gt_key_name: gt_key_name = cls._GEO_TREE_KEY gt = cls.get_by_key_name(gt_key_name) if gt: # check if the first tile has larger z than min_z, if not - nothing to update logging.debug(gt_key_name) logging.debug(gt.tiles_updated) x,y,z = tile_str_to_tuple(gt.tiles_updated[0]) min_z = get_min_z(gt_key_name) if not (z > min_z): r = '\n\nInfo: updated 0 tiles, nothing to update' return r needs_update = True count_updated = 0 while count_updated < count and needs_update: # get a group of tiles with a common parent (starting with the first) first_tile = gt.tiles_updated[0] p = tile_parent(first_tile,return_str=True) c = tile_children(p,return_str=True) c_in_updated = [first_tile] for t in gt.tiles_updated[1:]: if t in c: c_in_updated.append(t) # update parent, use all children for update t = cls.update_tile(p, c, gt_key_name=gt_key_name) t.put() # remove the group of updated children tiles from tiles_updated tiles_updated = sorted_tiles_set(gt.tiles_updated) tiles_updated.remove(c_in_updated) # insert updated tile tiles_updated.insert(p) gt.tiles_updated = list(tiles_updated) gt.put() # check if the first tile has smaller z than min_z, if not needs_update = False x,y,z = tile_str_to_tuple(tiles_updated[0]) min_z = get_min_z(gt_key_name) if z == min_z: needs_update = False # increase count_updated count_updated += 1 else: return '\n\nError: no GeoTree exists'