예제 #1
0
 def tile(self):
     z = 11
     x = randint(496,523)
     y = randint(772,797)
     try:
         z,x,y = map(int,[z,x,y])
         tid = "t:%s:%d+%d+%d"%(self.ts.shpfile,z,x,y)
         tile = Tile.get_by_key_name(tid)
         if tile:
             self._tile = tile
             return tile
         else:
             shpfile = memcache.get(self.ts.shpfile.encode('utf8'))
             if not shpfile:
                 shpfile = Shapefile.get_by_key_name(self.ts.shpfile)
                 memcache.set(self.ts.shpfile.encode('utf8'),shpfile)
             typ,dat = shpfile.raw_tile(x,y,z)
             tile = Tile(tid)
             tile.typ = typ 
             tile.dat = str(dat)
             tile.put()
             self._tile = tile
             return tile
     except:
         raise
         return False
     return False
예제 #2
0
 def get_tile(self,z,x,y):
     tid = "t:%s:%d+%d+%d"%(self.ts.name,z,x,y)
     tile = memcache.get(tid)
     if tile is not None:
         self._tile = tile
         return True
     tile = Tile.get_by_key_name(tid)
     if tile:
         #if tile.typ == 'B':
         #    tile.delete()
         #    return False
         #if not memcache.add(tid, tile):
         #    logging.error("Memcache set failed [ %s ]"%tid)
         self._tile = tile
         return True
     return False
예제 #3
0
파일: views.py 프로젝트: GeoDaSandbox/DynTM
 def tile(self):
     if self._tile and not self._get_raw:
         return self._tile
     if not self.ts:
         return False
     get = self.request.REQUEST.get
     x = get('x')
     y = get('y')
     z = get('z')
     b = True
     if get('b',-1) == '0':
         b = False
     if not (x and y and z):
         return False
     try:
         z,x,y = map(int,[z,x,y])
         if self._get_raw:
             shpfile = Shapefile.get_by_key_name(self.ts.shpfile)
             png = shpfile.raw_png(x,y,z,border=b)
             return png
         if b:
             tid = "t:%s:%d+%d+%d"%(self.ts.shpfile,z,x,y)
         else:
             tid = "u:%s:%d+%d+%d"%(self.ts.shpfile,z,x,y)
         tile = Tile.get_by_key_name(tid)
         if tile:
             self._tile = tile
             return tile
         else:
             logger.info("Creating tile x%d,y%d,z%d of %s"%(x,y,z,tid))
             shpfile = memcache.get(self.ts.shpfile.encode('utf8'))
             if not shpfile:
                 shpfile = Shapefile.get_by_key_name(self.ts.shpfile)
                 memcache.set(self.ts.shpfile.encode('utf8'),shpfile)
             typ,dat = shpfile.raw_tile(x,y,z,border=b)
             tile = Tile(tid)
             tile.typ = typ
             tile.dat = str(dat)
             tile.put()
             self._tile = tile
             return tile
     except:
         logger.error("Exception occured while Getting or Creating Tile (x%d,y%d,z%d)"%(x,y,z))
         return False
     return False