Exemplo n.º 1
0
 def remove_from_geotree_by_key_name(cls, key_name, coord, gt_key_name=None, max_z=None):
     """this method removes mentionings of a point from geotree
     coord is GeoPtProperty
     the points itself is not changed (it may not even exist in datastore)
     """
     #delete from native tile
     if not gt_key_name:
         gt_key_name = cls._GEO_TREE_KEY
     if not max_z:
         max_z = get_max_z(gt_key_name)
     tile_str = tile_tuple_to_str(lat_lon_to_tile(coord.lat, coord.lon, max_z))
     tile_key_name = '%s,%s' % (tile_str,gt_key_name)
     logging.debug(tile_key_name)
     t = Tile.get_by_key_name(tile_key_name)
     points = json.loads(t.points_native)
     for i in range(len(points)):
         if points[i]['key_name'] == key_name:
             del(points[i])
             break
     t.points_native = json.dumps(points)
     t.put()
     #mark this tile updated and update all tiles
     gt = cls.get_by_key_name(gt_key_name)
     tiles_updated = sorted_tiles_set(gt.tiles_updated)
     tiles_updated.insert(tile_key_name)
     gt.tiles_updated = list(tiles_updated)
     #decrease points count
     gt.number_points -= 1
     gt.put()
     gt.update_tiles()
Exemplo n.º 2
0
 def remove_point_by_key_name(cls, key_name, gt_key_name=None, max_z=None):
     #delete from native tile
     if not gt_key_name:
         gt_key_name = cls._GEO_TREE_KEY
     if not max_z:
         max_z = get_max_z(gt_key_name)
     p = Point.get_by_key_name(key_name)
     tile_str = tile_tuple_to_str(lat_lon_to_tile(p.coord.lat, p.coord.lon, max_z))
     tile_key_name = '%s,%s' % (tile_str,gt_key_name)
     t = Tile.get_by_key_name(tile_key_name)
     points = json.loads(t.points_native)
     for i in range(len(points)):
         if points[i]['key_name'] == key_name:
             del(points[i])
             break
     t.points_native = json.dumps(points)
     t.put()
     #mark this tile updated and update all tiles
     gt = cls.get_by_key_name(gt_key_name)
     tiles_updated = sorted_tiles_set(gt.tiles_updated)
     tiles_updated.insert(tile_key_name)
     gt.tiles_updated = list(tiles_updated)
     #decrease points count
     gt.number_points -= 1
     gt.put()
     gt.update_tiles()
     #delete point
     p.delete()
Exemplo n.º 3
0
    def test_lat_lon_to_tile(self):
        """testing convertion of a point to tile
        
        to come up with test cases refer to
        http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/"""

        lat = 48
        lon = 37.7
        z = 10

        tile_calculated = geomath.lat_lon_to_tile(lat,lon,z)
        tile_known = (619,355,10)

        # make sure the tiles are the same
        self.assertEqual(tile_calculated,tile_known)
Exemplo n.º 4
0
    def test_lat_lon_to_tile(self):
        """testing convertion of a point to tile
        
        to come up with test cases refer to
        http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/"""

        lat = 48
        lon = 37.7
        z = 10

        tile_calculated = geomath.lat_lon_to_tile(lat, lon, z)
        tile_known = (619, 355, 10)

        # make sure the tiles are the same
        self.assertEqual(tile_calculated, tile_known)
Exemplo n.º 5
0
 def insert_to_tile(self, gt_key_name=None, max_z=None):
     if not gt_key_name:
         gt_key_name = GeoTree._GEO_TREE_KEY
     if not max_z:
         max_z = get_max_z(gt_key_name)
     x,y,z = lat_lon_to_tile(self.coord.lat, self.coord.lon, max_z)
     tile_key_name = '%d,%d,%d,%s' % (x,y,z,gt_key_name)
     t = Tile.get_by_key_name(tile_key_name)
     if not t:
         t = Tile(x=x, y=y, z=z, key_name=tile_key_name, gt_key_name=gt_key_name)
     point_dict = {'key_name':self.key().name(),'importance':self.importance,'coord':(self.coord.lat,self.coord.lon),'name':self.name}
     if t.points_native:
         # use sorted list because this is used during merging of tiles
         points_native = sorted_points_list(json.loads(t.points_native))
         points_native.insert(point_dict)
         t.points_native = json.dumps(points_native)
     else:
         points_native = [point_dict]
         t.points_native = json.dumps(points_native)
     t.put()
     return tile_key_name
Exemplo n.º 6
0
 def update_importance(self, importance_new, gt_key_name=None, max_z=None):
     """updates importance of the point and the maximum zoom tile, other tiles are not updated"""
     if not gt_key_name:
         gt_key_name = GeoTree._GEO_TREE_KEY
     if not max_z:
         max_z = get_max_z(gt_key_name)
     self.importance = importance_new
     self.put()
     x,y,z = lat_lon_to_tile(self.coord.lat, self.coord.lon, max_z)
     tile_key_name = '%d,%d,%d,%s' % (x,y,z,gt_key_name)
     t = Tile.get_by_key_name(tile_key_name)
     if t:
         if t.points_native:
             points_native = json.loads(t.points_native)
             self_key_name = self.key().name()
             for p in points_native:
                 if p['key_name'] == self_key_name:
                     p['importance'] = importance_new
                     t.points_native = json.dumps(sorted_points_list(points_native))
                     break
             t.put()
     GeoTree.mark_tile_updated(tile_key_name, gt_key_name)