Skip to content

Commit

Permalink
Merge pull request #75 from IGNF/develop
Browse files Browse the repository at this point in the history
2.2.4: change(pivot2pgr): do not use clean_graph() procedure
  • Loading branch information
azarz authored Mar 12, 2024
2 parents 8bc09e5 + 008a5e3 commit 884235e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## x.y.z

## 2.2.4

CHANGED:
- Pivot to pgr: Not using clean_grpah method anymore, but a SQL query

## 2.2.3

CHANGED:
Expand Down
2 changes: 1 addition & 1 deletion r2gg/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
__uri_tracker__ = f"{__uri_repository__}issues/"
__uri__ = __uri_repository__

__version__ = "2.2.3"
__version__ = "2.2.4"
__version_info__ = tuple(
[
int(num) if num.isdigit() else num
Expand Down
34 changes: 32 additions & 2 deletions r2gg/_pivot_to_pgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,43 @@ def pivot_to_pgr(source, cost_calculation_file_path, connection_work, connection

for profile_name in profile_names:
logger.info("Cleaning isolated edges for profile {}...".format(profile_name))
clean_graph_query = "SELECT {0}.clean_graph('{1}')".format(schema, profile_name)
clean_graph_query = """
WITH connected_components AS (
SELECT * FROM pgr_connectedComponents(
'SELECT id, source, target, cost_s_{1} as cost, reverse_cost_s_{1} as reverse_cost FROM {0}.ways'
)
),
remove_nodes AS (
SELECT node
FROM
connected_components
WHERE
component = ANY(
SELECT DISTINCT component
FROM
(
SELECT component, count(*) AS nb
FROM
connected_components
GROUP BY component
)
AS components
WHERE nb <= 10
)
)
UPDATE {0}.ways
SET cost_s_{1} = -1,
reverse_cost_s_{1} = -1,
cost_m_{1} = -1,
reverse_cost_m_{1} = -1
WHERE {0}.ways.target = ANY(SELECT * from remove_nodes) OR {0}.ways.source = ANY(SELECT * from remove_nodes);
""".format(schema, profile_name)
logger.info("SQL: {}".format(clean_graph_query))
cursor_isolated.execute(clean_graph_query)
connection_out.commit()

et_execute = time.time()
logger.info("Execution ended. Elapsed time : %s seconds." %(et_execute - st_execute))
connection_out.commit()
cursor_isolated.close()

end_time = time.time()
Expand Down

0 comments on commit 884235e

Please sign in to comment.