예제 #1
0
    def _create_new_dataset(self,
                            old_dataset,
                            dataset_name=None,
                            dataset_metadata=None,
                            geometry=None,
                            catalog_entry_metadata=None,
                            ext=''):
        """Helper method for creating a new dataset and catalog entry based off of another dataset

        Args:
            dataset_name:

        Returns:

        """
        from ...api import get_metadata, update_metadata, new_dataset, new_catalog_entry, active_db

        orig_metadata = get_metadata(old_dataset)[old_dataset]
        collection = orig_metadata['collection']

        geom_type = geom_coords = None
        if geometry is None:
            orig_catalog_entry = orig_metadata['catalog_entry']
            geometry = get_metadata(
                orig_catalog_entry)[orig_catalog_entry]['geometry']
        elif isinstance(geometry, (list, tuple)):
            geom_type, geom_coords = geometry
            geometry = None

        catalog_entry = new_catalog_entry(
            geometry=geometry,
            geom_type=geom_type,
            geom_coords=geom_coords,
            metadata=catalog_entry_metadata,
        )

        dataset_name = dataset_name or self._create_new_dataset_name()
        display_name = '{}-{}'.format(self._name, dataset_name[:7])
        description = 'Created by tool {}'.format(self.name)

        # generate new dataset file path
        project_path = os.path.dirname(active_db())
        file_path = os.path.join(project_path, collection, dataset_name + ext)

        dataset_name = new_dataset(
            catalog_entry=catalog_entry,
            collection=collection,
            source=DatasetSource.DERIVED,
            name=dataset_name,
            display_name=display_name,
            description=description,
            file_path=file_path,
        )

        if dataset_metadata is not None:
            update_metadata(dataset_name, quest_metadata=dataset_metadata)

        return dataset_name, file_path, catalog_entry
예제 #2
0
파일: tool_base.py 프로젝트: dloney/quest
    def run_tool(self, **options):
        from quest.api.metadata import update_metadata
        """Function that applies tools"""
        options.pop('name', None)
        self.set_param(**options)

        self._set_options = options or dict(self.get_param_values())
        result = self._run_tool()
        datasets = listify(result.get('datasets', []))
        catalog_entries = listify(result.get('catalog_entries', []))
        for dataset in datasets:
            update_metadata(dataset, quest_metadata={
                'options': self.set_options,
                'status': DatasetStatus.DERIVED
            })

        result.update(datasets=datasets, catalog_entries=catalog_entries)

        return result