def get_linked_esu_list(self, usrn): """ function that selects all esus for a determined street :param usrn: the unique identifier of a certain street :return: list[esu_ids] all esu ids linked to a certain street or void in case a street does not have any linked esu """ # executing the query esus_query_model = QSqlQueryModel() esus_query_model.setQuery(self.queries[9].format(usrn)) while esus_query_model.canFetchMore(): esus_query_model.fetchMore() n_rows = esus_query_model.rowCount() # skip if no esus are linked if n_rows == 0: return else: i = 0 esus_list = [] # creating a list of ESUs Ids that are linked to the street while i <= n_rows - 1: model_index = esus_query_model.createIndex(i, 0) esu = model_index.data() esus_list.append(esu) i += 1 return esus_list
def check_start_end(self, tol): # set the feature counter to 0 count = 0 # initialises two virtual objects points (start and end point) start_point = self.start_point end_point = self.end_point # uses the qgis python api to access the ESU Graphic Layer esu_layer = self.esu_layer # runs the query number 8 to retrieve all streets from the Database streets_model = QSqlQueryModel() streets_model.setQuery(self.queries[8]) while streets_model.canFetchMore(): streets_model.fetchMore() n_columns = streets_model.columnCount() n_rows = streets_model.rowCount() i = 0 j = 0 # first loop start (for each street): start_end_content = [] while i <= n_rows - 1: self.progress_win.setLabelText("Checking start-end Coordinates...") # initialises the state of the checks booleans both to false start_ok = False end_ok = False col_info = [] while j <= n_columns - 1: model_index = streets_model.createIndex(i, j) if j == 0: data = model_index.data() col_info.append(data) if j == 1: data = model_index.data() col_info.append(data) if j == 2: data = model_index.data() col_info.append(data) if j >= 3: data = model_index.data() col_info.append(data) j += 1 usrn = col_info[0] ref_type = col_info[2] desc = col_info[1] start_point.set(float(col_info[3]), float(col_info[4])) end_point.set(float(col_info[5]), float(col_info[6])) # filter the layer "ESU Graphic" for the ESUs Ids returned from the list # deal just with the arcs part of multi arcs street esus_list = self.get_linked_esu_list(usrn) feat_filter = self.build_layer_filter(esus_list) feat_request = QgsFeatureRequest() feat_request.setFilterExpression(feat_filter) # second loop starts (for each arc (ESU) composing the street) # iterate through all filtered features and their proximity with the start and end of the street features = self.esu_layer.getFeatures(feat_request) features.rewind() # iterates through features for feat in features: # check start end points for each of the only if none of the start end points of # a ESU on each street is not already matched if (start_ok is not True) or (end_ok is not True): result = self.start_end_proximity(start_point, end_point, feat, tol) # both dist are ok if result == 3: start_ok = True end_ok = True # just end dist is ok elif result == 2: end_ok = True # just start dist is ok elif result == 1: start_ok = True else: break # in case of problems if not start_ok or not end_ok: count += 1 start_end_item = [str(col_info[0]) + ","] # handles the creation of the report on a text file if not start_ok and not end_ok: start_end_item.append("(both),") if not start_ok and end_ok: start_end_item.append("(start),") if start_ok and not end_ok: start_end_item.append("(end),") start_end_item.append(str(ref_type) + ",") start_end_item.append(str(desc) + "\n") start_end_content.append(start_end_item) j = 0 i += 1 if count == 0: self.progress_win.setValue(7) return else: start_end_content.insert(0, self.column_names[5]) self.progress_win.setValue(7) return self.content_to_screen(content_list=start_end_content, query_model=None, columns_name_id=None, no_content_id=8)