# Making graph with shapefile

**URL:** <https://discourse.julialang.org/t/making-graph-with-shapefile/98768>\
**Category:** Graphs\
**Tags:** graphs, shapefile\
**Created:** [May 12, 2023, 9:44pm UTC](https://discourse.julialang.org/t/making-graph-with-shapefile/98768 "2023-05-12T21:44:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michelle\_Ko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/michelle_ko/32/49746_2.png) [@Michelle\_Ko](https://discourse.julialang.org/u/Michelle_Ko)\
**Post date:** [May 12, 2023, 9:44pm UTC](https://discourse.julialang.org/t/making-graph-with-shapefile/98768/1 "2023-05-12T21:44:34Z")

</div>

Hi, I am new to Julia and need some help regarding construction of graph with shapefile.  
I have shapefile that contains polylines and want to get the shortest path using Dijkstra’s algorithm.  
The thing is, in order to use Dijkstra’s algorithm, I need a graph.  
I am wondering if I can construct a graph with the shapefile that contains polylines?  
Maybe I need to add vertices at the end of each polylines to fix the source and destination points.  
Is there any suggestions or packages that I can refer to?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [May 12, 2023, 9:48pm UTC](https://discourse.julialang.org/t/making-graph-with-shapefile/98768/2 "2023-05-12T21:48:11Z")

</div>

Hi @Michelle_Ko!

I don’t think there is anything ready-baked for you, you might have to combine several packages:

- [Shapefile.jl](https://github.com/JuliaGeo/Shapefile.jl) to read the file
- [SimpleWeightedGraphs.jl](https://github.com/JuliaGraphs/SimpleWeightedGraphs.jl) to construct a weighted graph

Let me know if you need more help!

---

<div class="post-metadata">

**Author:** ![Michelle\_Ko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/michelle_ko/32/49746_2.png) [@Michelle\_Ko](https://discourse.julialang.org/u/Michelle_Ko)\
**Post date:** [May 13, 2023, 10:40pm UTC](https://discourse.julialang.org/t/making-graph-with-shapefile/98768/3 "2023-05-13T22:40:26Z")

</div>

Hi @gdalle

Thanks for the reply but I already imported the shapefile into Julia and I figured out how to make a simple graph and add vertices and edges.

To explain more specifically, I have an electricity network in shapefile and I want to measure the shortest path from starting vertex to destination vertex. In order to do this, I thought I need to construct a graph using the polyline data since ‘dijkstra\_shortest\_paths’ let me measure the shortest path of a graph. For example,

_Polyline(Rect(-7.89573e6, 5.24276e6, -7.89571e6, 5.24284e6), Int32[0], Point[Point(-7.89573e6, 5.24276e6), Point(-7.89571e6, 5.24284e6)])_

is one electricity line that connects two points _Point[Point(-7.89573e6, 5.24276e6)_ and _Point(-7.89571e6, 5.24284e6)])_ and

_Polyline(Rect(-7.89573e6, 5.24276e6, -7.89579e6, 5.24299e6), Int32[0], Point[Point(-7.89573e6, 5.24276e6), Point(-7.89574e6, 5.24294e6), Point(-7.89579e6, 5.24299e6)])_

is another line that connects three points. And the points are in the form of coordinates in wgs84 (spatial reference).

Are there any ways that I can construct a graph that mimic the network of these electricity lines? Thank a lot in advance.

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [May 14, 2023, 8:17am UTC](https://discourse.julialang.org/t/making-graph-with-shapefile/98768/4 "2023-05-14T08:17:45Z")

</div>

I think you have to manually extract the distance between vertex coordinates from the `Polyline` objects, in order to turn it into weights. Does that answer your question?
