コード例 #1
0
ファイル: views.py プロジェクト: GeoDaSandbox/DynTM
 def cs(self):
     if self._cs:
         return self._cs
     if self.csid:
         csid = self.csid
     else:
         csName = self.request.REQUEST.get('cs')
         if csName:
             self.csid = csid = csName
         else:
             return False
     cs = memcache.get(csid.encode('utf8'))
     if cs is None:
         cs = ColorScheme.get_by_key_name(csid)
         if cs:
             cs.alphas = '\x00'
             if not memcache.add(csid.encode('utf8'), cs):
                 logger.error("Memcache set failed [ %s ]"%csid)
             self._cs = cs
     #logger.info(self._cs)
     if cs is not None:
         if cs.public or cs.owner == self.request.user.username:
             self._cs = cs
             return self._cs
     return False
コード例 #2
0
ファイル: views.py プロジェクト: GeoDaSandbox/DynTM
 def cl(self):
     if self._cl:
         return self._cl
     if self.clid:
         clid = self.clid
     else:
         clName = self.request.REQUEST.get('cl')
         if clName:
             self.clid = clid = clName
         else:
             return False
     cl = memcache.get(clid.encode('utf8'))
     if cl is None:
         if clid.isdigit() and len(clid)<4:
             logger.warn("User requested a random classification, not fully implemented")
             cl = classification.random(self.ts.numregions,min(int(clid)+2,MAX_n))
             self._cl = cl
             return cl
         else:
             cl = Classification.get_by_key_name(clid)
             if cl is not None and not memcache.add(clid.encode('utf8'), cl):
                 logger.error("Memcache set failed [ %s ]"%clid)
     if cl is not None:
         if cl.public or cl.owner == self.request.user.username:
             self._cl = cl
             return self._cl
     return False
コード例 #3
0
ファイル: dtm.py プロジェクト: GeoDaSandbox/DynTM
 def cs(self):
     """ Search for the Color Scheme Name in the Request and try and load it from Memcache or DataStore, return True or False """
     if self._cs:
         return self._cs
     colorSchemeName = self.request.get('cs','DEFAULT')
     self.csid = csid = "cs:"+colorSchemeName
     cs = memcache.get(csid)
     if cs is not None:
         self._cs = cs
     else:
         if csid:
             cs = ColorScheme.get_by_key_name(csid)
             if cs:
                 #logging.info('found colorScheme(%s)'%csid)
                 #CHECK URL FOR BANGGROUND OPTIONS...
                 background = self.request.get('transparentBackground')
                 if background == 'OFF':
                     cs.alphas = ''
                 self._cs = cs
         if self.cl:
             if cs and cs.n==self.cl.n:
                 pass
             else:
                 N = min(self.cl.n-2,MAX_N)
                 if csid[:9] == 'cs:random':
                     rid = 'ts:%s&cl:%s&cs:%s'%(self.request.get('ts'),self.request.get('cl'),self.request.get('cs'))
                     cs = memcache.get(rid)
                     if not cs:
                         cs = colors.random(N,borders=(60,60,60))
                         memcache.add(rid, cs)
                     self._cs = cs
                     return cs
                 else:
                     if self.cl.n == 3:
                         cs = colors.ColorScheme([(0,0,1),(0,0,0)]+[(255,90,0)]*N)
                     else:
                         cs = colors.fade(self.cl.n-2)
         self._cs = cs
     if cs is not None:
         return cs
     else:
         return False
コード例 #4
0
ファイル: dtm.py プロジェクト: GeoDaSandbox/DynTM
 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
コード例 #5
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
コード例 #6
0
ファイル: dtm.py プロジェクト: GeoDaSandbox/DynTM
 def cl(self):
     """ Search for the Classification Name in the Request and try and load it from Memcache or DataStore, return True or False """
     if self._cl:
         return self._cl
     classificationName = self.request.get('cl','DEFAULT')
     if classificationName == 'random':
         self.clid = clid = "cl:random"
     elif classificationName.isdigit():
         self.clid = clid = "cl:__digit:"+self.ts.name+":"+classificationName
     elif self.ts:
         self.clid = clid = "cl:"+self.ts.name+":"+classificationName
     else:
         return False
     cl = memcache.get(clid)
     if cl is not None:
         self._cl = cl
     else:
         cl = None
         if self.ts:
             N = self.ts.idlen
             if clid == 'cl:random':
                 cl = classification.random(N,min(N,MAX_n))
             elif clid.startswith('cl:__digit:'):
                 cl = classification.random(N,min(int(classificationName)+2,MAX_n))
             elif clid.startswith('cl:key_'):
                 C = Classification.get(classificationName[4:])
                 if C:
                     cl = classification.Classification(C.a)
             elif clid:
                 C = Classification.get_by_key_name(clid)
                 if C:
                     cl = classification.Classification(C.a)
             #if cl and clid != 'cl:random':
                 #if not memcache.add(clid, cl, 60):
                 #    logging.error("Memcache set failed [ %s ]"%clid)
             if not cl:
                 cl = classification.random(N,3)
         self._cl = cl
     if cl is not None:
         return cl
     else:
         return False
コード例 #7
0
ファイル: views.py プロジェクト: GeoDaSandbox/DynTM
 def ts(self):
     """ Search for the TileSetName in the Request and try and load it from Memcache or DataStore, return TileSet or False """
     if self._ts:
         return self._ts
     if self.tsid:
         tsid = self.tsid
     else:
         tileSetName = self.request.REQUEST.get('ts')
         if tileSetName:
             self.tsid = tsid = tileSetName
         else:
             return False
     ts = memcache.get(tsid.encode('utf8'))
     if ts is None:
         ts = TileSet.get_by_key_name(tsid)
         if ts is not None and not memcache.set(tsid.encode('utf8'),ts):
             logger.error("Memcache set failed [ %s ]"%tsid)
     if ts is not None:
         if ts.public or ts.owner == self.request.user.username:
             self._ts = ts
             return ts
     return False
コード例 #8
0
ファイル: dtm.py プロジェクト: GeoDaSandbox/DynTM
 def ts(self):
     """ Search for the TileSetName in the Request and try and load it from Memcache or DataStore, return True or False """
     if self._ts:
         return self._ts
     tileSetName = self.request.get('ts')
     if tileSetName:
         self.tsid = tsid = 'ts:'+tileSetName
     else:
         return False
     ts = memcache.get(tsid)
     if ts is not None:
         self._ts = ts
     else:
         ts = TileSet.get_by_key_name(tsid)
         #if ts is not None and not memcache.add(tsid, ts):
         #    logging.error("Memcache set failed [ %s ]"%tsid)
         self._ts = ts
     #logging.info(self._ts)
     if ts is not None:
         return self._ts
     else:
         return False