# How to create a geotiff in Julia?

**URL:** <https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270>\
**Category:** New to Julia\
**Tags:** geo, gmt\
**Created:** [June 29, 2020, 9:21pm UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270 "2020-06-29T21:21:14Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [June 29, 2020, 9:21pm UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/1 "2020-06-29T21:21:14Z")

</div>

Hi,

I have a array of values in Julia that I would like to export as a geotiff. Right now I am using osgeo in python to make them seperately, which is a pain. Does anyone have an example of how to do this? I can’t find one, but feel like there probably is a Julia package that can do this.

Thanks

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [June 29, 2020, 10:11pm UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/2 "2020-06-29T22:11:59Z")

</div>

I don’t know the answer to your question about Julia packages, but if necessary you can call the Python package from Julia using PyCall.jl.

---

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [June 29, 2020, 10:23pm UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/3 "2020-06-29T22:23:31Z")

</div>

Thanks for the response. That was my first impulse, but I was having trouble importing the packages. I use:

from osgeo import gdal  
from osgeo import osr  
import numpy as np  
import os, sys

In Julia, when I try:

```julia
julia> osg = pyimport("osgeo")
ERROR: PyError (PyImport_ImportModule

The Python package osgeo could not be found by pyimport. Usually this means
that you did not install osgeo in the Python version being used by PyCall.

PyCall is currently configured to use the Python version at:

/usr/bin/python3

and you should use whatever mechanism you usually use (apt-get, pip, conda,
etcetera) to install the Python package containing the osgeo module.

One alternative is to re-configure PyCall to use a different Python
version on your system: set ENV["PYTHON"] to the path/name of the python
executable you want to use, run Pkg.build("PyCall"), and re-launch Julia.

Another alternative is to configure PyCall to use a Julia-specific Python
distribution via the Conda.jl package (which installs a private Anaconda
Python distribution), which has the advantage that packages can be installed
and kept up-to-date via Julia. As explained in the PyCall documentation,
set ENV["PYTHON"]="", run Pkg.build("PyCall"), and re-launch Julia. Then,
To install the osgeo module, you can use `pyimport_conda("osgeo", PKG)`,
where PKG is the Anaconda package the contains the module osgeo,
or alternatively you can use the Conda package directly (via
`using Conda` followed by `Conda.add` etcetera).

) <class 'ImportError'>
ImportError("/home/efurtak/julia-1.4.2/bin/../lib/julia/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /lib64/libgdal.so.20)")
  File "/usr/lib64/python3.7/site-packages/osgeo/ __init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "/usr/lib64/python3.7/site-packages/osgeo/ __init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
  File "/usr/lib64/python3.7/imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib64/python3.7/imp.py", line 342, in load_dynamic
    return _load(spec)

```

That is the right python installation, and when I use python3 from the terminal there are no issues importing osgeo (I am using fedora, maybe that is the issue). Also, numpy imports with pycall fine for some reason.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [June 29, 2020, 11:12pm UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/4 "2020-06-29T23:12:00Z")

</div>

Is that Python version that is listed the one what gets called when you run Python?

---

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [June 29, 2020, 11:31pm UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/5 "2020-06-29T23:31:41Z")

</div>

Yes, when I call “python” it is version 3.3.7, and osgeo works. “which python” gives the same path that PyCall is picking up.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [June 29, 2020, 11:37pm UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/6 "2020-06-29T23:37:02Z")

</div>

does

```julia
py"""
from osgeo import gdal
from osgeo import osr
"""

```

work?

---

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [June 29, 2020, 11:37pm UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/7 "2020-06-29T23:37:43Z")

</div>

> [@jling](#):
>
> ```julia
> from osgeo import gdal
> from osgeo import osr
> 
> ```

Yes

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [June 29, 2020, 11:40pm UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/8 "2020-06-29T23:40:07Z")

</div>

just to make sure, you mean it works when running this in Julia right? `py``` ` is a `PyCall` thing

---

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [June 29, 2020, 11:40pm UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/9 "2020-06-29T23:40:29Z")

</div>

This really seems to be a problem that is specific to osgeo. I get numpy, scipy, and matplotlib to work with PyCall in Julia without issue.

---

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [June 29, 2020, 11:42pm UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/10 "2020-06-29T23:42:03Z")

</div>

Ahh, sorry I misunderstood. That does not work in Julia.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [June 29, 2020, 11:46pm UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/11 "2020-06-29T23:46:30Z")

</div>

Can you use `Conda.jl` to install `osgeo`?

---

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [June 29, 2020, 11:51pm UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/12 "2020-06-29T23:51:12Z")

</div>

I am not sure if I am doing this correctly, but I get:

```julia
[ Info: Running `conda install -y OSGeo` in root environment
/bin/sh: module: line 1: syntax error: unexpected end of file
/bin/sh: error importing function definition for `module'
/bin/sh: switchml: line 1: syntax error: unexpected end of file
/bin/sh: error importing function definition for `switchml'
/bin/sh: scl: line 1: syntax error: unexpected end of file
/bin/sh: error importing function definition for `scl'
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  - osgeo

Current channels:

  - https://repo.anaconda.com/pkgs/main/linux-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/linux-64
  - https://repo.anaconda.com/pkgs/r/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.

```

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [June 30, 2020, 12:20am UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/13 "2020-06-30T00:20:01Z")

</div>

You can do it with GMT. What kind of images do you want to plot?  
A toy example.

```julia
using GMT

G = gmt("grdmath -R0/30/0/30 -I0.1 X Y MUL"); # A dummy grid
I = grdimage(G, img_out=true); # Convert it to a dummy image
I.proj4 = "+proj=latlong +datum=WGS84"; # Assign it a fake CRS

gmtwrite("lixo.tif", I, driver=:GTiff)
GMT [WARNING]: gmtapi_change_imagelayout: reordering function for case TRPa -> BRP not yet written. Doing nothing.

```

But I need to commit one one small fix in step 2

---

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [June 30, 2020, 12:28am UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/14 "2020-06-30T00:28:02Z")

</div>

That seems to be the solution I am looking for, but I still can’t get your package working on Fedora! We tried, here: [How to make a wind rose in Julia - #23 by joa-quim](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/23) I have another machine running pop\_os, so maybe I will give it a shot with that a little later.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [June 30, 2020, 12:33am UTC](https://discourse.julialang.org/t/how-to-create-a-geotiff-in-julia/42270/15 "2020-06-30T00:33:15Z")

</div>

Ah, yes. Maybe you could try to build GMT from source. We have instructions for that in GMT home page. And a new version (6.1) should probably be released this week.
