示例#1
0
    def _execute(self, skip_permission_check=False):
        """Overwrite this function in subclasses

        Overwrite this function in subclasses

            - Setup user credentials
            - Setup the storage interface
            - Analyse the process chain
            - Initialize and create the temporal database and mapset
            - Run the modules
            - Export the results
            - Cleanup

        """

        # Setup the user credentials and logger
        self._setup()

        # Create and check the resource directory
        self.storage_interface.setup()

        EphemeralProcessing._execute(self)

        # Export all resources and generate the finish response
        self._export_resources()
    def _execute(self):
        self._setup()

        # Points and where statement are stored in self.request_data
        strds_name = self.map_name
        geojson = self.request_data

        point_file = tempfile.NamedTemporaryFile(dir=self.temp_file_path,
                                                 delete=True)
        result_file = tempfile.NamedTemporaryFile(dir=self.temp_file_path,
                                                  delete=True)

        point_file.write(json_dumps(geojson).encode())
        point_file.flush()

        pc = dict()
        pc["1"] = {
            "module": "v.import",
            "inputs": {
                "input": point_file.name
            },
            "outputs": {
                "output": {
                    "name": "input_points"
                }
            }
        }

        pc["2"] = {
            "module": "t.rast.sample",
            "inputs": {
                "strds": "%s@%s" % (strds_name, self.mapset_name),
                "points": "input_points"
            },
            "outputs": {
                "output": {
                    "name": result_file.name
                }
            },
            "flags": "rn",
            "overwrite": True,
            "verbose": True
        }

        self.request_data = pc

        # Run the process chain
        EphemeralProcessing._execute(self, skip_permission_check=True)

        result = open(result_file.name, "r").readlines()

        output_list = []
        for line in result:
            output_list.append(line.strip().split("|"))

        self.module_results = output_list

        point_file.close()
        result_file.close()
示例#3
0
    def __init__(self, rdc):
        """
        Setup the variables of this class

        Args:
            rdc (ResourceDataContainer): The data container that contains all required variables for processing

        """
        EphemeralProcessing.__init__(self, rdc)
        # Create the storage interface to store the exported resources
        self.storage_interface = rdc.create_storage_interface()
示例#4
0
 def __init__(self, *args, pc):
     EphemeralProcessing.__init__(self, *args)
     self.response_model_class = StringListProcessingResultResponseModel
     self.process_chain = pc
 def __init__(self, *args):
     EphemeralProcessing.__init__(self, *args)
     self.response_model_class = RasterAreaUnivarStatsResponseModel
    def _execute(self):

        self._setup()
        where = None

        # Points and where statement are stored in self.request_data
        strds_name = self.map_name
        points = self.request_data["points"]
        if "where" in self.request_data:
            where = self.request_data["where"]

        if not points or len(points) == 0:
            raise AsyncProcessError("Empty coordinate list")

        point_file = tempfile.NamedTemporaryFile(dir=self.temp_file_path,
                                                 delete=True)
        result_file = tempfile.NamedTemporaryFile(dir=self.temp_file_path,
                                                  delete=True)

        for tuple in points:
            if len(tuple) != 3:
                raise AsyncProcessError("Wrong number of coordinate entries")

            id, x, y = tuple
            row = "%s|%s|%s\n" % (id, x, y)
            point_file.write(row.encode())

        point_file.flush()

        pc = dict()
        pc["1"] = {
            "module": "v.in.ascii",
            "inputs": {
                "input": point_file.name,
                "format": "point",
                "column": "id text, x double precision, y double precision",
                "x": 2,
                "y": 3
            },
            "outputs": {
                "output": {
                    "name": "input_points"
                }
            }
        }

        pc["2"] = {
            "module": "t.rast.sample",
            "inputs": {
                "strds": "%s@%s" % (strds_name, self.mapset_name),
                "points": "input_points",
                "column": "id"
            },
            "outputs": {
                "output": {
                    "name": result_file.name
                }
            },
            "flags": "rn",
            "overwrite": True,
            "verbose": True
        }

        if where is not None:
            pc["2"]["inputs"]["where"] = where

        self.request_data = pc

        # Run the process chain
        EphemeralProcessing._execute(self, skip_permission_check=True)

        result = open(result_file.name, "r").readlines()

        output_list = []
        for line in result:
            output_list.append(line.strip().split("|"))

        self.module_results = output_list

        point_file.close()
        result_file.close()
 def __init__(self, *args):
     EphemeralProcessing.__init__(self, *args)
     self.response_model_class = STRDSSampleResponseModel