Permalink
Browse files

fixed TileGrid.is_subset_of for grids with custom resolutions

same bbox and resolutions can still result in incompatible grids
when origin is different and the resolutions do not align to
bbox and tile_size
  • Loading branch information...
olt committed Dec 5, 2012
1 parent 5c83990 commit a5c28c16542559663fcd4b3d7e7c13f9ab6149e1
Showing with 24 additions and 27 deletions.
  1. +17 −27 mapproxy/grid.py
  2. +7 −0 mapproxy/test/unit/test_grid.py
View
@@ -611,35 +611,25 @@ def is_subset_of(self, other):
if self.tile_size != other.tile_size:
return False
- other_res = list(other.resolutions)
-
- for res in self.resolutions:
- while other_res and other_res[0] != res:
- other_res.pop(0)
- if not other_res:
- return False
+ # check if all level tiles from self align with (affected)
+ # tiles from other
+ for self_level, self_level_res in self.resolutions.iteritems():
+ level_size = (
+ self.grid_sizes[self_level][0] * self.tile_size[0],
+ self.grid_sizes[self_level][1] * self.tile_size[1]
+ )
+ level_bbox = self._tiles_bbox([
+ (0, 0, self_level),
+ (self.grid_sizes[self_level][0] - 1, self.grid_sizes[self_level][1] - 1, self_level)
+ ])
+ bbox, level = other.get_affected_bbox_and_level(level_bbox, level_size)
+ bbox, grid_size, tiles = other.get_affected_level_tiles(level_bbox, level)
- if self.bbox != other.bbox:
- # check if all level tiles from self align with (affected)
- # tiles from other
- for self_level, self_level_res in self.resolutions.iteritems():
- level_size = (
- self.grid_sizes[self_level][0] * self.tile_size[0],
- self.grid_sizes[self_level][1] * self.tile_size[1]
- )
- level_bbox = self._tiles_bbox([
- (0, 0, self_level),
- (self.grid_sizes[self_level][0] - 1, self.grid_sizes[self_level][1] - 1, self_level)
- ])
-
- bbox, level = other.get_affected_bbox_and_level(level_bbox, level_size)
- bbox, grid_size, tiles = other.get_affected_level_tiles(level_bbox, level)
-
- if other.resolution(level) != self_level_res:
- return False
- if not bbox_equals(bbox, level_bbox):
- return False
+ if other.resolution(level) != self_level_res:
+ return False
+ if not bbox_equals(bbox, level_bbox):
+ return False
return True
@@ -1201,3 +1201,10 @@ def test_tile_size(self):
assert not g1.is_subset_of(g2)
+ def test_non_matching_bboxfor_origins(self):
+ g1 = tile_grid(SRS(21781), bbox=[420000, 30000, 900000, 360000],
+ res=[250], origin='nw')
+ g2 = tile_grid(SRS(21781), bbox=[420000, 30000, 900000, 360000],
+ res=[250], origin='sw')
+
+ assert not g1.is_subset_of(g2)

0 comments on commit a5c28c1

Please sign in to comment.