# Troubles with GeoStats/GeoIO coordinates with units

**URL:** <https://discourse.julialang.org/t/troubles-with-geostats-geoio-coordinates-with-units/117766>\
**Category:** Geo\
**Created:** [July 31, 2024, 2:47pm UTC](https://discourse.julialang.org/t/troubles-with-geostats-geoio-coordinates-with-units/117766 "2024-07-31T14:47:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TimG](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimG](https://discourse.julialang.org/u/TimG)\
**Post date:** [July 31, 2024, 2:47pm UTC](https://discourse.julialang.org/t/troubles-with-geostats-geoio-coordinates-with-units/117766/1 "2024-07-31T14:47:58Z")

</div>

Thank you @juliohm! File reads fine now.

New issue - too small to warrant new thread, perhaps.

```julia
bb = boundingbox(gt.geometry)
minx, miny = coordinates(bb.min)[1:2]

```

coordinates function no longer works.

```julia
ERROR: LoadError: UndefVarError: `coordinates` not defined

```

I tried qualifying it as `GeoStats.coordinates` or `GeoIO.coordinates` to no avail.

I’m sure it is obvious but what am I missing?

---

<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:** [July 31, 2024, 3:01pm UTC](https://discourse.julialang.org/t/troubles-with-geostats-geoio-coordinates-with-units/117766/2 "2024-07-31T15:01:13Z")

</div>

The function is called `c = coords(point)` now. It returns a coordinate type with `c.x` and `c.y` if your coordinates are projected or Cartesian. You also have `to(point)` which returns a vector from the origin to the point.

---

<div class="post-metadata">

**Author:** ![TimG](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimG](https://discourse.julialang.org/u/TimG)\
**Post date:** [July 31, 2024, 3:39pm UTC](https://discourse.julialang.org/t/troubles-with-geostats-geoio-coordinates-with-units/117766/3 "2024-07-31T15:39:11Z")

</div>

I’m going to have to work through this a bit. The introduction of units seems to be causing my script issues.

I updated the above to:

```julia
using Unitful
    bb = boundingbox(gt.geometry)
    crd = coords(bb.min)
    minx = ustrip(Float64, u"m", crd.x)
    miny = ustrip(Float64, u"m", crd.y)

```

so it no longer fails.  
Now I’m having issues on the next step.

I’ll leave this here - with thanks - and work through my issues. I’ll start another thread if/when I need more help.

---

<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:** [July 31, 2024, 3:43pm UTC](https://discourse.julialang.org/t/troubles-with-geostats-geoio-coordinates-with-units/117766/4 "2024-07-31T15:43:49Z")

</div>

It takes some time to write units-aware code that is idiomatic. Try to rely on the transforms that we provide in the framework as much as possible to avoid manual operations with coordinates and units. Your code will be more general that way.

---

<div class="post-metadata">

**Author:** ![TimG](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimG](https://discourse.julialang.org/u/TimG)\
**Post date:** [August 1, 2024, 9:48am UTC](https://discourse.julialang.org/t/troubles-with-geostats-geoio-coordinates-with-units/117766/5 "2024-08-01T09:48:47Z")

</div>

So, I changed the way I initialised some dataframe columns from

```julia
df.minx .= 0.0

```

to

```julia
df.minx .= 0.0u"m"

```

and after that, by the miracle that is julia, everything just worked!

It takes me a while, but when I finally get there, simple things like this are so satisfying!

---

<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:** [August 1, 2024, 10:39am UTC](https://discourse.julialang.org/t/troubles-with-geostats-geoio-coordinates-with-units/117766/6 "2024-08-01T10:39:09Z")

</div>

Yes! It is really nice to see units propagating in the code 🙂

Quick tip to make it more readable:

```julia
using Unitful: m

df.minx .= 0.0m

```
