# Conflict between Proj and GeoStats in a package

**URL:** <https://discourse.julialang.org/t/conflict-between-proj-and-geostats-in-a-package/121862>\
**Category:** General Usage\
**Tags:** question, geo\
**Created:** [October 28, 2024, 9:56am UTC](https://discourse.julialang.org/t/conflict-between-proj-and-geostats-in-a-package/121862 "2024-10-28T09:56:08Z")\
**Posts on this page:** 9\
**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:** [October 28, 2024, 9:56am UTC](https://discourse.julialang.org/t/conflict-between-proj-and-geostats-in-a-package/121862/1 "2024-10-28T09:56:08Z")

</div>

I am new to creating packages and usually just run scripts.

This script runs fine:

```julia
using CSV
using DataFrames
using Dates
using GeoIO
using GeoStats
using Proj
using ZipArchives
include("mweNLHFmethod.jl")

#using Revise
#using UpdateTerminatedPostcodes

println(UTPfindNewPostcodes(["BT4 3EU", "OX17 2JP", "NW1 5HA", "BT9 5LA"]))

```

and prints `(149890.41568462105, 529224.907298712)`.

However, if I make the include file into a package, and swap the commented `using` sections above, it errors.

```julia
module UpdateTerminatedPostcodes

# imported dependencies
using CSV
using DataFrames
using Dates
using GeoIO
using GeoStats
using Proj
using ZipArchives

# files defining functions, types, etc.
include("mweNLHFmethod.jl")

# names you want to make public
export UTPfindNewPostcodes

end # module UpdateTerminatedPostcodes

```

This is the include file (reduced to MWE)

```julia
function UTPfindNewPostcodes(postcode_list)
    INGtoBNG = Proj.Transformation("EPSG:29903", "EPSG:27700", always_xy=true) # EPSG:29903 is Irish National Grid
    BNGtoING = Proj.Transformation("EPSG:27700", "EPSG:29903", always_xy=true) # EPSG:27700 is British National Grid
    out = INGtoBNG(337492.0, 374065.0) # Convert Irish national grid coordinates to British national grid
    return out
end

```

Now when I run, I get:

```julia
Precompiling UpdateTerminatedPostcodes...
  1 dependency successfully precompiled in 29 seconds. 440 already precompiled.
ERROR: LoadError: UndefVarError: `Proj` not defined in `UpdateTerminatedPostcodes`
Hint: It looks like two or more modules export different bindings with this name, resulting in ambiguity. Try explicitly importing it from a particular module, or qualifying the name with the module it should come from.
Hint: a global variable of this name may be made accessible by importing Meshes in the current active module Main
Hint: a global variable of this name may be made accessible by importing GeoStats in the current active module Main
Hint: Proj is loaded but not imported in the active module Main.
Stacktrace:
 [1] UTPfindNewPostcodes(postcode_list::Vector{String})
   @ UpdateTerminatedPostcodes C:\Users\TGebbels\...\Documents\Julia\Packages\UpdateTerminatedPostcodes\src\mweNLHFmethod.jl:2
 [2] top-level scope
   @ c:\Users\TGebbels\...\Documents\Julia\Julia Experimenting\From NLPU Shared\mwe-Proj - Nov24.jl:18
 [3] include(fname::String)
   @ Main .\sysimg.jl:38
 [4] run(debug_session::VSCodeDebugger.DebugAdapter.DebugSession, error_handler::VSCodeDebugger.var"#3#4"{String})
   @ VSCodeDebugger.DebugAdapter c:\Users\TGebbels\.vscode\extensions\julialang.language-julia-1.127.2\scripts\packages\DebugAdapter\src\packagedef.jl:122
 [5] startdebugger()
   @ VSCodeDebugger c:\Users\TGebbels\.vscode\extensions\julialang.language-julia-1.127.2\scripts\packages\VSCodeDebugger\src\VSCodeDebugger.jl:45
 [6] top-level scope
   @ c:\Users\TGebbels\.vscode\extensions\julialang.language-julia-1.127.2\scripts\debugger\run_debugger.jl:12
 [7] include(mod::Module, _path::String)
   @ Base .\Base.jl:557
 [8] exec_options(opts::Base.JLOptions)
   @ Base .\client.jl:323
 [9] _start()
   @ Base .\client.jl:531
in expression starting at c:\Users\TGebbels\...\Documents\Julia\Julia Experimenting\From NLPU Shared\mwe-Proj - Nov24.jl:18

```

I’m afraid I can’t figure out what the hints are trying to tell me. Can someone give me a stronger hint, please?  
Thanks,  
Tim

---

<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:** [October 28, 2024, 11:12am UTC](https://discourse.julialang.org/t/conflict-between-proj-and-geostats-in-a-package/121862/2 "2024-10-28T11:12:19Z")

</div>

> [@TimG](#):
>
> `Hint: It looks like two or more modules export different bindings with this name, resulting in ambiguity. Try explicitly importing it from a particular module, or qualifying the name with the module it should come from.`

Hi @TimG , the hint above has the information you need.

You are loading the `Proj` module with `using Proj` and also loading the `Proj` transform from GeoStats.jl when you do `using GeoStats`. You need to specify which of the two you want to use with a prefix (e.g., `GeoStats.Proj`).

---

<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:** [October 28, 2024, 11:20am UTC](https://discourse.julialang.org/t/conflict-between-proj-and-geostats-in-a-package/121862/3 "2024-10-28T11:20:02Z")

</div>

If I try

```julia
    INGtoBNG = GeoStats.Proj.Transformation("EPSG:29903", "EPSG:27700", always_xy=true) # EPSG:29903 is Irish National Grid

```

and drop `using Proj`, I get

```julia
ERROR: LoadError: type UnionAll has no field Transformation

```

---

<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:** [October 28, 2024, 11:43am UTC](https://discourse.julialang.org/t/conflict-between-proj-and-geostats-in-a-package/121862/4 "2024-10-28T11:43:54Z")

</div>

The `GeoStats.Proj` is the one documented in our stack:

```julia
  Proj(CRS)
  Proj(code)

  Convert the coordinates of geometry or domain to a given coordinate reference
  system CRS or EPSG/ESRI code.

  Optionally, the transform samples the boundary of polytopes, if this option is
  true, to handle distortions that occur in manifold conversions.

  Examples
  ========

  Proj(Polar)
  Proj(WebMercator)
  Proj(Mercator{WGS84Latest})
  Proj(EPSG{3395})
  Proj(ESRI{54017})

  Notes
  –––––

    • By default, only the vertices of the polytopes are transformed,
       disregarding distortions that occur in manifold conversions. To handle
       this case, use TransformedGeometry.

```

You are trying to use the Proj.jl (package) interface in our `GeoStats.Proj` object.

You need to decide which of the two you want to use, and then use the appropriate interface.

---

<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:** [October 28, 2024, 11:53am UTC](https://discourse.julialang.org/t/conflict-between-proj-and-geostats-in-a-package/121862/5 "2024-10-28T11:53:18Z")

</div>

> [@juliohm](#):
>
> You need to decide which of the two you want to use, and then use the appropriate interface.

I know which one I want to use (Proj.jl), but I don’t know how to invoke it!

It works straightforwardly when I just include the file in a script, but it doesn’t work in a package. I don’t know why.

---

<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:** [October 28, 2024, 12:01pm UTC](https://discourse.julialang.org/t/conflict-between-proj-and-geostats-in-a-package/121862/6 "2024-10-28T12:01:41Z")

</div>

The hint says

```julia
Hint: It looks like two or more modules export different bindings with this name, 
resulting in ambiguity. Try explicitly importing it from a particular module, or 
qualifying the name with the module it should come from.

```

I was `using Proj` so I switched to `import Proj` and now it works.

```julia
module UpdateTerminatedPostcodes

# imported dependencies
using CSV
using DataFrames
using Dates
using GeoIO
using GeoStats
using ZipArchives

import Proj

# files defining functions, types, etc.
include("mweNLHFmethod.jl")

# names you want to make public
export UTPfindNewPostcodes

end # module UpdateTerminatedPostcodes

```

I guess I don’t understand the difference between `import` and `using`.

Tim

---

<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:** [October 28, 2024, 12:05pm UTC](https://discourse.julialang.org/t/conflict-between-proj-and-geostats-in-a-package/121862/7 "2024-10-28T12:05:29Z")

</div>

The Julia manual should have a good section on `import` vs `using`, and on solving name conflicts.

---

<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:** [October 29, 2024, 9:15am UTC](https://discourse.julialang.org/t/conflict-between-proj-and-geostats-in-a-package/121862/8 "2024-10-29T09:15:14Z")

</div>

I have read the manual (multiple times) but I’m still confused because:

- I did use a fully qualified name (`Proj.Transformation`) in my code
- I am not (knowingly) trying to extend an existing `Proj` method.

I’m also not at all clear why `using` works in script while I have to use `import` when I put the same code in a module.

There must be something else (probably many things!) I didn’t understand on my reads through.

(Note to self: Keep studying!)

---

<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:** [October 29, 2024, 12:25pm UTC](https://discourse.julialang.org/t/conflict-between-proj-and-geostats-in-a-package/121862/9 "2024-10-29T12:25:45Z")

</div>

The line `using GeoStats` exports the name `Proj`. The line `using Proj` makes the name `Proj` available as a module. The line `import Proj` doesnt export the names of the module and apparently also overwrites any existing `Proj` name.

Given that youre mainly using GeoStats.jl I recommend that you keep `using GeoStats` and import the Proj.jl package with other name:

```julia
import Proj as CProj

```

That will eliminate any possible conflict.
