Exemplo n.º 1
0
    def _get_collection_result(self, exec_query_resp):
        """
        Parse the string binary containing data (encoded, unencoded) from rasql to objects which later can be
        translated to numpy array.
        Or returns the list of rasdaman collections in RASBASE.
        :return: ResultArray object
        """
        spatial_domain = get_spatial_domain_from_type_structure(
            exec_query_resp.type_structure)
        band_types = get_type_structure_from_string(
            exec_query_resp.type_structure)

        # concatenate all the binary strings to one string to be decoded as Numpy ndarray buffer
        data_list = self.__get_array_result_mdd()
        data = b''.join(data_list)

        data_type = band_types["type"]
        # NOTE: unencoded result array is nD+ numpy array. If number of bands > 1 then the number of dimensions + 1
        number_of_bands = 1
        if data_type == "struct":
            data_type = band_types["sub_type"]["types"][0]
            number_of_bands = len(band_types["sub_type"]["types"])

        res_array = ResultArray(data_type, spatial_domain, number_of_bands)
        res_array.add_data(data)

        return res_array
Exemplo n.º 2
0
    def _get_element_result(self, exec_query_resp):
        """
        Get the response from rasserver for query which doesn't return array which can be converted to Numpy ndarray
        e.g: select 1 + 2, select {1, 2, 3}
        :return: array of results if server returns multiple elements or just 1 result if only 1 element
        """
        rpcstatus = 0

        band_types = get_type_structure_from_string(
            exec_query_resp.type_structure)
        result_arr = ResultArray(band_types['type'], is_object=False)

        while rpcstatus == 0:
            elemresp = rassrvr_get_next_element(
                self.transaction.database.stub,
                self.transaction.database.connection.session.clientId)
            rpcstatus = elemresp.status
            if rpcstatus == 2:
                raise Exception(
                    "getNextElement - no transfer or empty element")
            # e.g: select 2 + 3, select complex(3, 5)
            result = convert_binary_data_stream(band_types, elemresp.data)
            result_arr.add_data(result)

        return result_arr
Exemplo n.º 3
0
 def _get_list_collection(self):
     """
     Return the list of collection names from RASBASE for query (select c from RAS_COLLECTIONNAMES as c)
     :return: list of string collection names
     """
     result_array = ResultArray("string")
     for r in self.__get_array_result_mdd():
         result_array.add_data(encoded_bytes_to_str(r))
     return result_array