Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
topupopt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pmag
topupopt
Commits
88cb2040
Commit
88cb2040
authored
May 6, 2024
by
Pedro L. Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
Added a method for creating edge geometries.
parent
112a6490
Branches
Branches containing commit
No related tags found
1 merge request
!6
Stats
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/topupopt/data/gis/utils.py
+13
-1
13 additions, 1 deletion
src/topupopt/data/gis/utils.py
src/topupopt/problems/esipp/utils.py
+0
-41
0 additions, 41 deletions
src/topupopt/problems/esipp/utils.py
tests/test_gis_utils.py
+19
-1
19 additions, 1 deletion
tests/test_gis_utils.py
with
32 additions
and
43 deletions
src/topupopt/data/gis/utils.py
+
13
−
1
View file @
88cb2040
...
...
@@ -11,7 +11,7 @@ from networkx import MultiDiGraph, MultiGraph
from
pandas
import
MultiIndex
,
Series
from
numpy
import
float64
,
int64
from
geopandas
import
GeoDataFrame
,
read_file
from
shapely.geometry
import
Point
from
shapely.geometry
import
Point
,
LineString
import
contextily
as
cx
# local, internal
...
...
@@ -1229,6 +1229,18 @@ def convert_edge_path(
# return statement
return
node_path
# *****************************************************************************
# *****************************************************************************
def
create_edge_geometry
(
network
:
MultiDiGraph
,
edge_key
)
->
LineString
:
"
Returns a newly-created geometry for a given edge.
"
return
LineString
(
[(
network
.
nodes
[
edge_key
[
0
]][
osm
.
KEY_OSMNX_X
],
network
.
nodes
[
edge_key
[
0
]][
osm
.
KEY_OSMNX_Y
]),
(
network
.
nodes
[
edge_key
[
1
]][
osm
.
KEY_OSMNX_X
],
network
.
nodes
[
edge_key
[
1
]][
osm
.
KEY_OSMNX_Y
])]
)
# *****************************************************************************
# *****************************************************************************
This diff is collapsed.
Click to expand it.
src/topupopt/problems/esipp/utils.py
+
0
−
41
View file @
88cb2040
...
...
@@ -18,47 +18,6 @@ from .network import Network
# *****************************************************************************
# *****************************************************************************
def
review_final_network
(
network
:
Network
):
# check that the network topology is a tree
if
network
.
has_tree_topology
():
print
(
"
The network has a tree topology.
"
)
else
:
print
(
"
The network does not have a tree topology.
"
)
# check the existence of forward and reverse arcs between the same nodes
has_forward_reverse_arcs
(
network
,
print_result
=
True
)
# *****************************************************************************
# *****************************************************************************
def
has_forward_reverse_arcs
(
network
:
Network
,
print_result
:
bool
=
True
)
->
bool
:
"""
Returns True if there are simultaneous forward and reverse arcs.
"""
# check the existence of forward and reverse arcs in the same segment
forward_reverse_arcs
=
[
# get the arcs selected
arc_key
[
0
:
2
]
for
arc_key
in
network
.
edges
(
keys
=
True
)
if
True
in
network
.
edges
[
arc_key
][
Network
.
KEY_ARC_TECH
].
options_selected
]
forward_reverse_arcs
=
[
# get the selected arcs that exist both ways
arc_key
for
arc_key
in
forward_reverse_arcs
if
(
arc_key
[
1
],
arc_key
[
0
])
in
forward_reverse_arcs
]
if
print_result
:
if
len
(
forward_reverse_arcs
)
==
0
:
print
(
"
The network has no forward and reverse arcs in
"
+
"
the same segment.
"
)
else
:
print
(
"
The network has forward and reverse arcs in
"
+
"
the same segment.
"
)
# *****************************************************************************
# *****************************************************************************
def
run_mvesipp_analysis
(
problem
:
InfrastructurePlanningProblem
=
None
,
...
...
This diff is collapsed.
Click to expand it.
tests/test_gis_utils.py
+
19
−
1
View file @
88cb2040
...
...
@@ -12,6 +12,7 @@ from pandas import concat, MultiIndex, Series
import
networkx
as
nx
import
osmnx
as
ox
from
shapely.geometry
import
Point
,
LineString
from
shapely
import
intersects
# local, internal
...
...
@@ -2643,6 +2644,23 @@ class TestGisUtils:
# *************************************************************************
# *************************************************************************
def
test_create_edge_geometry
(
self
):
G
=
nx
.
MultiDiGraph
()
edge_key
=
(
0
,
1
)
G
.
add_node
(
0
,
x
=
0
,
y
=
0
)
G
.
add_node
(
1
,
x
=
1
,
y
=
1
)
G
.
add_edge
(
0
,
1
,
length
=
2
**
0.5
)
first_geo
=
gis_utils
.
create_edge_geometry
(
G
,
edge_key
)
edge_key
=
(
2
,
3
)
G
.
add_node
(
2
,
x
=
0
,
y
=
1
)
G
.
add_node
(
3
,
x
=
1
,
y
=
0
)
G
.
add_edge
(
2
,
3
,
length
=
2
**
0.5
)
second_geo
=
gis_utils
.
create_edge_geometry
(
G
,
edge_key
)
assert
intersects
(
first_geo
,
second_geo
)
# *************************************************************************
# *************************************************************************
# *****************************************************************************
# *****************************************************************************
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment