# How to extract raster values at coordinate locations?

**URL:** https://discourse.julialang.org/t/how-to-extract-raster-values-at-coordinate-locations/69752
**Category:** New to Julia
**Tags:** geo
**Created:** [October 14, 2021, 12:53pm UTC](https://discourse.julialang.org/t/how-to-extract-raster-values-at-coordinate-locations/69752 "2021-10-14T12:53:25Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![CompulsoryCoffee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compulsorycoffee/32/30434_2.png) [@CompulsoryCoffee](https://discourse.julialang.org/u/CompulsoryCoffee)
#### Post date: [October 14, 2021, 12:53pm UTC](https://discourse.julialang.org/t/how-to-extract-raster-values-at-coordinate-locations/69752/1 "2021-10-14T12:53:25Z")

</div>

Hi,

I have a (long) csv file with X, Y coordinates and a (long) list of rasters.  
I would like to loop through the rasters, extract the values of the raster at the X, Y locations and write the results in a new CSV each time.

Any chance I can do that using Julia?

Thanks

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [October 14, 2021, 1:37pm UTC](https://discourse.julialang.org/t/how-to-extract-raster-values-at-coordinate-locations/69752/2 "2021-10-14T13:37:54Z")

</div>

Check [this thread](https://discourse.julialang.org/t/reading-satellite-data/20231) for geotiff rasters reading.

---

<div class="post-metadata">

### Author: ![CompulsoryCoffee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compulsorycoffee/32/30434_2.png) [@CompulsoryCoffee](https://discourse.julialang.org/u/CompulsoryCoffee)
#### Post date: [October 14, 2021, 1:45pm UTC](https://discourse.julialang.org/t/how-to-extract-raster-values-at-coordinate-locations/69752/3 "2021-10-14T13:45:42Z")

</div>

Thanks,

I found this:

```julia
using GeoData, CSV, GBIF
st = GeoStack(WorldClim{BioClim})[Band(1)] |> replace_missing
obs = GBIF.occurrences("scientificName" => "Burramys parvus", "limit" => 300)
# Read all the occurrences
read!(obs)
# use `extract` to get that values for all layers for each observation.
vals = extract(st, map(o -> o.longitude, obs), map(o -> o.latitude, obs))
# output

```

I will try to see how far i go 🙂

---

<div class="post-metadata">

### Author: ![CompulsoryCoffee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compulsorycoffee/32/30434_2.png) [@CompulsoryCoffee](https://discourse.julialang.org/u/CompulsoryCoffee)
#### Post date: [October 14, 2021, 3:09pm UTC](https://discourse.julialang.org/t/how-to-extract-raster-values-at-coordinate-locations/69752/4 "2021-10-14T15:09:49Z")

</div>

I tried this (below) but the output is tricky to understand / manipulate - not sure what to make out of it

```julia
vals = extract(A, 380706.9107400000, 3098724.2625000002)

```

outputs:

1-element GeoArray{UInt32,1} with dimensions:  
Band: 1:1 Categorical: Ordered  
and reference dimensions:  
X: 380700.13223046553 Projected: Ordered Regular Intervals crs: WellKnownText,  
Y: 3.098722533405694e6 Projected: Ordered Regular Intervals crs: WellKnownText  
0x00003de4

I tried this:  
julia\> vals[1]  
0x00003de4

and this give me the correct value  
julia\> println(vals[1])  
15844

How can I access this value as a varibale then? … might be for another thread

---

<div class="post-metadata">

### Author: ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)
#### Post date: [October 14, 2021, 6:56pm UTC](https://discourse.julialang.org/t/how-to-extract-raster-values-at-coordinate-locations/69752/5 "2021-10-14T18:56:34Z")

</div>

vals[1] must be of an unsigned type which defaults to show as hex. If you prefer to have it as a signed value do `v = Int(vals[1])`. If unsigned works for you, then simply `v=vals[1]`.

---

<div class="post-metadata">

### Author: ![CompulsoryCoffee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compulsorycoffee/32/30434_2.png) [@CompulsoryCoffee](https://discourse.julialang.org/u/CompulsoryCoffee)
#### Post date: [October 15, 2021, 10:32am UTC](https://discourse.julialang.org/t/how-to-extract-raster-values-at-coordinate-locations/69752/6 "2021-10-15T10:32:31Z")

</div>

It worked ! thanks
