Geo.PostGIS: “undefined function fragment/3”

I’m having trouble using Geo Elixir package. Here are the steps to reproduce the error.

I added the package to the dependency and iex -S mix to test it out.

iex(1)> import Geo.PostGIS
iex(2)> geo1 = %Geo.Point{coordinates: {49.2769578,-123.1219351}, srid: 4326}
iex(3)> geo2 = %Geo.Point{coordinates: {49.2759393,-123.1215435}, srid: 4326}
iex(4)> st_distance(geo1, geo2)
** (CompileError) iex:4: undefined function fragment/3
    expanding macro: Geo.PostGIS.st_distance/2
    iex:4: (file)

All of the functions in the Geo.PostGIS module, such as st_distance/2, can only be used inside Ecto.Query syntax. So you use it inside queries and not to work directly with the data types. Unfortunately I am not well-versed enough in Geo.PostGIS to tell you if there is a way to do what you want outside of the database.

1 Like

Sorry, that is correct, macros in the Geo.PostGIS module are only for use within Ecto queries. It would be nice to have a separate set of functions to be used with just raw geometries outside of a database, but nothing like those exist in Geo just yet.