Skip to content

Commit

Permalink
Merge pull request #3 from Jefersonnnn/fix_tracing_pipelines
Browse files Browse the repository at this point in the history
Selects only open valves to close
  • Loading branch information
Jeferson Machado authored Sep 23, 2020
2 parents 408d8fd + 23cda9c commit bf9a69c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion core/find_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, qpipelines, description='FindHds', debug=False):

def find_hds_by_nearest_neighbor(self, points_vertex):
hds_nearest = self.idx_hds.nearestNeighbor(point=QgsPointXY(points_vertex), neighbors=10,
maxDistance=15)
maxDistance=25)

if len(hds_nearest) > 0:
for hd in hds_nearest:
Expand Down
3 changes: 2 additions & 1 deletion core/task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def __init__(self, task_manager, pipelines, valves):
self.__tm = task_manager

def start(self):
tracing_task = TracingPipelines(self.__pipelines, self.__valves, onfinish=self.select_hidrometers)
#tracing_task = TracingPipelines(self.__pipelines, self.__valves, onfinish=self.select_hidrometers)
tracing_task = TracingPipelines(self.__pipelines, self.__valves)
self.__tm.addTask(tracing_task)

def select_hidrometers(self):
Expand Down
21 changes: 15 additions & 6 deletions core/tracing_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def run(self):
# Busca por redes selecionadas (necessário ser apenas uma)
if self.debug:
self._pipelines_features.selectByIds([4343])
#self._pipelines_features.getFeatures(16)
# self._pipelines_features.getFeatures(16)

selected_pipeline = self._pipelines_features.selectedFeatures()

Expand Down Expand Up @@ -117,16 +117,26 @@ def __create_spatial_index(self):
flags=QgsSpatialIndex.FlagStoreFeatureGeometries)

def __find_neighbors(self, point_vertex):
reg_isvisivel = None
reg_status = None

# Busca pelo registro mais próximo, dentro do raio maxDistance=user_distance
reg_nearest = self.__idx_valves.nearestNeighbor(point=QgsPointXY(point_vertex), neighbors=1,
maxDistance=self.__user_distance)

if len(reg_nearest) > 0:
isvisivel = str(list(self._valves_features.getFeatures(reg_nearest))[0]['visivel'])
if isvisivel.upper() != 'NÃO':
# visivel = 'sim' = registro visível | visivel = 'não' = registro não visível
reg_isvisivel = str(list(self._valves_features.getFeatures(reg_nearest))[0]['visivel'])
# status = 0 = 'Aberto' | status = 1 = 'Fechado'
reg_status = str(list(self._valves_features.getFeatures(reg_nearest))[0]['status'])

if len(reg_nearest) > 0:
if reg_isvisivel.upper() != 'NÃO' and reg_status == '0':
self.__list_valves.append(reg_nearest[0])
else:
pipelines_nearest = self.__idx_pipelines.nearestNeighbor(point=QgsPointXY(point_vertex), neighbors=3,
# Busca pelas 4 redes mais próximas dentro do raio maxDistance=user_distance
pipelines_nearest = self.__idx_pipelines.nearestNeighbor(point=QgsPointXY(point_vertex), neighbors=4,
maxDistance=self.__user_distance)
# pipelines_nearest = idx_rede_agua.intersects(QgsRectangle(QgsPointXY(pointVertex), QgsPointXY(pointVertex)))
if len(pipelines_nearest) > 0:
for pipeline_id in pipelines_nearest:
pipeline_geometry = self.__idx_pipelines.geometry(pipeline_id)
Expand All @@ -152,4 +162,3 @@ def __find_neighbors(self, point_vertex):

tracing = TracingPipelines(pipe_features, valves_features, debug=True)
tracing.run()

0 comments on commit bf9a69c

Please sign in to comment.