def encode(fp, feature_layers, bounds_merc): tile = mvt_encode( feature_layers, quantize_bounds=bounds_merc, on_invalid_geometry=on_invalid_geometry_make_valid, round_fn=round, ) fp.write(tile)
def encode(fp, feature_layers, bounds_merc, extents=4096): tile = mvt_encode( feature_layers, quantize_bounds=bounds_merc, on_invalid_geometry=on_invalid_geometry_make_valid, round_fn=round, extents=extents, ) fp.write(tile)
def __call__(self, func, **defaults): """ func @callable : A function that returns a dictionary with a mandatory 'features' key and an optional 'name' key Returns a wrapper function, it's intended as a decorator. """ kwargs = self.parse_request(func, **defaults) name = self._hash(func, **kwargs) self.filename = f"{name}{self.EXT}" wrapper = lambda : mvt_encode(WebWrapper.__call__(self, f2f(func), **defaults)()) return wrapper
def __call__(self, func, app_name='', stream_public=False, **defaults): get_stream = lambda: io.BytesIO( mvt_encode(WebWrapper.__call__(self, f2f(func), **defaults)())) def wrapper(): kwargs = self.parse_request(func, **defaults) name = self._hash(func, **dict(kwargs, **self.params)) self.filename = f"{name}{self.EXT}" rec = db.fcache(name=name) commit = False if rec is None: stream = get_stream() if settings.CACHE_NEW: try: newid = db.fcache.insert(name=name, file=db.fcache.file.store( stream, self.filename)) except AttributeError: raise self.time_expire = settings.CACHE_EXPIRE - ( self.now - now()).seconds return stream.read() else: rec = db.fcache[newid] commit = True else: self.time_expire = settings.CACHE_EXPIRE - (self.now - now()).seconds return stream.read() elif (self.now - rec.modified_on).seconds > ( rec.timeout or settings.CACHE_EXPIRE): stream = get_stream() rec.update(file=db.fcache.file.store(stream, self.filename)) commit = True self.time_expire = (rec.timeout or settings.CACHE_EXPIRE) - ( self.now - rec.modified_on).seconds if commit: db.commit() if self.public and not stream_public: _, path_to_img = db.fcache.file.retrieve(rec.file, nameonly=True) rpath = path_to_img[path_to_img.index('static'):] redirect(f'/{app_name}/{rpath}') else: _, stream = db.fcache.file.retrieve(rec.file, nameonly=False) return stream.read() return wrapper
def encode(fp, feature_layers, coord, bounds_merc): tile = mvt_encode(feature_layers, quantize_bounds=bounds_merc, on_invalid_geometry=on_invalid_geometry_make_valid) fp.write(tile)