コード例 #1
0
ファイル: test_views.py プロジェクト: GeoDaSandbox/DynTM
 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
ファイル: views.full.py プロジェクト: GeoDaSandbox/DynTM
 def find_tile(self,z,x,y):
     if z is not None and x is not None and y is not None and self.ts:
         z,x,y = map(int,(z,x,y))
         #logging.info('Find Tile: %d+%d+%d'%(z,x,y))
         if self.get_tile(z,x,y):
             return self._tile
         elif self.valid_tile(z,x,y):
             #logging.info('Tile: %d+%d+%d Not Found, will search'%(z,x,y))
             while z:
                 z-=1
                 x_quad = x&1
                 y_quad = y&1
                 x = x>>1
                 y = y>>1
                 #logging.info('Tile: search %d+%d+%d'%(z,x,y))
                 if self.get_tile(z,x,y):
                     #logging.info('Tile: found %d+%d+%d'%(z,x,y))
                     regionID = query.query(self._tile,qx=x_quad,qy=y_quad)
                     #logging.info('Region ID: %d'%(regionID))
                     #logging.info('Quad x,y: (%d,%d)'%(x_quad,y_quad))
                     t = Tile()
                     t.dat = str(regionID)
                     if regionID == 0:
                         t.typ = 'A'
                     else:
                         t.typ = 'B'
                     self._tile = t
                     return self._tile
         else:
             #logging.info('Tile: %d+%d+%d Is Not Valid'%(z,x,y))
             return False
     else:
         #logging.info('not z,x,y or ts')
         t =Tile()
         t.dat = '0'
         t.typ = 'A'
         self._tile = t
         return self._tile
     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