def metadata(self, datasetid): query = {'UID': datasetid} ds = dataset.query(self.context, **query) if ds: # we have a generator, let's pick the first result # metadata is extracted by query ds = next(ds, None) if ds is None: raise NotFound(self.context, datasetid, self.request) return ds
def query(self): # TODO: remove some parameters from request? # e.g only matching with catalog indices # only certain indices # remove batching and internal parameters like brains query = self.request.form # TODO: should optimise this. e.g. return generator, objs = [] for item in dataset.query(self.context, **query): objs.append(item) return objs
def queryDataset(self, genre=None, layers=None): params = {'object_provides': IDataset.__identifier__} if genre: if not isinstance(genre, (tuple, list)): genre = (genre, ) params['BCCDataGenre'] = {'query': genre, 'operator': 'or'} if layers: if not isinstance(layers, (tuple, list)): layers = (layers, ) params['BCCEnviroLayer'] = {'query': layers, 'operator': 'and'} result = [] for brain in dataset.query(self.context, True, **params): result.append({'uuid': brain.UID, 'title': brain.Title}) return result
def getRAT(self, datasetid, layer=None): query = {'UID': datasetid} dsbrain = dataset.query(self.context, brains=True, **query) if dsbrain: # get first brain from list dsbrain = next(dsbrain, None) if not dsbrain: raise NotFound(self.context, datasetid, self.request) md = IBCCVLMetadata(dsbrain.getObject()) rat = md.get('layers', {}).get(layer, {}).get('rat') # if we have a rat, let's try and parse it if rat: try: rat = json.loads(unicode(rat)) except Exception as e: LOG.warning("Couldn't decode Raster Attribute Table from metadata. %s: %s", self.context, repr(e)) rat = None return rat