# Extract subnetwork/graph within a given distance from a vertex

**URL:** <https://igraph.discourse.group/t/extract-subnetwork-graph-within-a-given-distance-from-a-vertex/1664>\
**Category:** Usage\
**Tags:** R\
**Created:** [5 September 2023 13:16 UTC](https://igraph.discourse.group/t/extract-subnetwork-graph-within-a-given-distance-from-a-vertex/1664 "2023-09-05T13:16:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johannes](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/johannes/32/995_2.png) [@Johannes](https://igraph.discourse.group/u/Johannes)\
**Post date:** [5 September 2023 13:16 UTC](https://igraph.discourse.group/t/extract-subnetwork-graph-within-a-given-distance-from-a-vertex/1664/1 "2023-09-05T13:16:46Z")

</div>

I am looking for a feature of igraph to extract a subnetwork based on distances from a known vertex. Basically, I have a route-able river network available as an igraph object. The river network comprises of stream segments and nodes (i.e. confluences). Now, I have the ID of a specific vertex node which is very central in my network. Starting from that vertex, I’d like extract a sub-network that is within a distance from that node. There is a column “LE” in my edge-layer which represents the length of each edge and which could/should be used as weight.

I tried “shortest\_paths”, which generally works but I’m not sure if this is the way to go for my task:

```auto
sp1 <- shortest_paths(
   g,
   from= 1099, # the vertex of interest
   to = V(g),
   mode = "all",
   weights = E(g)$LE # length of each edge in real world
)

```

What would be the correct function to extract such a subnetwork which is all edges within a distance of e.g. 5000 meters from my starting vertex? I could imagine that there is a specific function in the igraph package that exactly performs such tasks(?)

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [5 September 2023 15:19 UTC](https://igraph.discourse.group/t/extract-subnetwork-graph-within-a-given-distance-from-a-vertex/1664/2 "2023-09-05T15:19:54Z")

</div>

`neighborhood()` (combined with `induced_subgraph()`) does this, but does not support weights yet. I’ll put in a feature request for weight support.

For now you will need to use `shortest_paths()` for weighted graphs.
