# Extracting coordinates from Shape File

**URL:** <https://discourse.julialang.org/t/extracting-coordinates-from-shape-file/67799>\
**Category:** Geo\
**Tags:** tables, shapefile\
**Created:** [September 7, 2021, 10:35am UTC](https://discourse.julialang.org/t/extracting-coordinates-from-shape-file/67799 "2021-09-07T10:35:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dieter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dieter/32/29860_2.png) [@Dieter](https://discourse.julialang.org/u/Dieter)\
**Post date:** [September 7, 2021, 10:35am UTC](https://discourse.julialang.org/t/extracting-coordinates-from-shape-file/67799/1 "2021-09-07T10:35:54Z")

</div>

Hi Community

I tried to read in a Shape File with Austrian Boarders typing

```julia
julia> A=Shapefile.Table(Path_Shapefile)
Shapefile.Table{Union{Missing, Shapefile.Polygon}} with 1 rows and the following 16 columns:

geometry, ID, LANGUAGE, NAME, PARENT_ID, ADMN_LEVEL, ADM_LEV_DE, ADM_LEV_EN, ADM_LEV, MAPS_LEVEL, MapLev_min, MapLev_max, ID_ORIG, FEATTYP, TZID, UTC_OFFSET

julia> B=A.geometry
1-element Vector{Union{Missing, Shapefile.Polygon}}:
 Polygon(5890 Points)

```

How is it now possible to get the Polygon values stored in variable B ?

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 7, 2021, 10:51am UTC](https://discourse.julialang.org/t/extracting-coordinates-from-shape-file/67799/2 "2021-09-07T10:51:44Z")

</div>

You accessed the geometry column of the table. You can access any other column with similar syntax. I am assuming that is how Shapefile.Table works. If it doesn´t work that way, you can also try GeoTables.jl to load the shapefile with pure Julia geometries:

```julia
using GeoTables

table = GeoTables.load("myfile.shp")

table.geometry
table.ADMN_LEVEL
...

```

Notice that GeoTables.jl will recognize any file format, not just Shapefile. It works with Geopackage or any other file format supported by GDAL.

---

<div class="post-metadata">

**Author:** ![fabiangans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabiangans/32/2624_2.png) [@fabiangans](https://discourse.julialang.org/u/fabiangans)\
**Post date:** [September 7, 2021, 11:19am UTC](https://discourse.julialang.org/t/extracting-coordinates-from-shape-file/67799/3 "2021-09-07T11:19:44Z")

</div>

The data types in Shapefile.jl are defined here: [https://github.com/JuliaGeo/Shapefile.jl/blob/master/src/Shapefile.jl#L58](https://github.com/JuliaGeo/Shapefile.jl/blob/master/src/Shapefile.jl#L58) , so `B.points` gives you a vector of Points while `B.parts` denotes the indices at which a new polygon starts.

---

<div class="post-metadata">

**Author:** ![Dieter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dieter/32/29860_2.png) [@Dieter](https://discourse.julialang.org/u/Dieter)\
**Post date:** [September 7, 2021, 11:27am UTC](https://discourse.julialang.org/t/extracting-coordinates-from-shape-file/67799/4 "2021-09-07T11:27:44Z")

</div>

Thanks fabiangans and juliohm,

GeoTables is able to open the shapefile

```julia
julia> using GeoTables

julia> table = GeoTables.load(Path_Shapefile)
1 GeoTable{2,Float64}
  variables
    └─ADMN_LEVEL (Int64)
    └─ADM_LEV (String)
    └─ADM_LEV_DE (String)
    └─ADM_LEV_EN (String)
    └─FEATTYP (Int64)
    └─ID (String)
    └─ID_ORIG (String)
    └─LANGUAGE (String)
    └─MAPS_LEVEL (Int64)
    └─MapLev_max (Int64)
    └─MapLev_min (Int64)
    └─NAME (String)
    └─PARENT_ID (String)
    └─TZID (String)
    └─UTC_OFFSET (String)
  domain: 1 GeometrySet{2,Float64}

julia> Geo = table.table.geometry
1-element Vector{Union{Missing, Shapefile.Polygon}}:
 Polygon(5890 Points)

```

But here is the same question how to receive the coordinates of the 5980 points stored in Geo.

---

<div class="post-metadata">

**Author:** ![Dieter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dieter/32/29860_2.png) [@Dieter](https://discourse.julialang.org/u/Dieter)\
**Post date:** [September 7, 2021, 11:32am UTC](https://discourse.julialang.org/t/extracting-coordinates-from-shape-file/67799/5 "2021-09-07T11:32:20Z")

</div>

Hi fabiangans,

Unfortunately I receive this error message when trying your suggestion:

```julia
julia> B
1-element Vector{Union{Missing, Shapefile.Polygon}}:
 Polygon(5890 Points)

julia> B.points
ERROR: type Array has no field points
Stacktrace:
 [1] getproperty(x::Vector{Union{Missing, Shapefile.Polygon}}, f::Symbol)
   @ Base ./Base.jl:33
 [2] top-level scope
   @ none:1

```

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 7, 2021, 11:35am UTC](https://discourse.julialang.org/t/extracting-coordinates-from-shape-file/67799/6 "2021-09-07T11:35:23Z")

</div>

@Dieter take a look at the Meshes.jl documentation which is where all these geometries are defined. You can collect the vector of geometries, pick any geometry in the vector and collect its vertices:

```julia
# column of geometries
geoms = table.geometry

# first geometry
g = geoms[1]

# list of vertices
vs = vertices(g)

# list of coordinates
xs = coordinates.(vs)

```

---

<div class="post-metadata">

**Author:** ![fabiangans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabiangans/32/2624_2.png) [@fabiangans](https://discourse.julialang.org/u/fabiangans)\
**Post date:** [September 7, 2021, 11:54am UTC](https://discourse.julialang.org/t/extracting-coordinates-from-shape-file/67799/7 "2021-09-07T11:54:44Z")

</div>

Sorry for the error, B.points is a vector of length one, so `B[1].points` should access the `points` field of the first element.

---

<div class="post-metadata">

**Author:** ![Dieter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dieter/32/29860_2.png) [@Dieter](https://discourse.julialang.org/u/Dieter)\
**Post date:** [September 7, 2021, 12:03pm UTC](https://discourse.julialang.org/t/extracting-coordinates-from-shape-file/67799/8 "2021-09-07T12:03:38Z")

</div>

Thanks @fabiangans, now it works!

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [February 28, 2024, 12:54pm UTC](https://discourse.julialang.org/t/extracting-coordinates-from-shape-file/67799/9 "2024-02-28T12:54:05Z")

</div>

Update for those coming late here:

Please replace `GeoTables.load` by `GeoIO.load`.

GeoIO.jl is the new home of the `load` and `save` functions.
