From f2dcc1fedc3736cd17abe2e4aa36bc52a4f86674 Mon Sep 17 00:00:00 2001 From: Christopher Varjas Date: Sun, 21 Dec 2025 21:15:15 -0500 Subject: [PATCH 1/5] add st_point_z --- lib/geo_postgis.ex | 8 ++++++++ test/ecto_test.exs | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/geo_postgis.ex b/lib/geo_postgis.ex index f25b496..dc3fa8e 100644 --- a/lib/geo_postgis.ex +++ b/lib/geo_postgis.ex @@ -259,6 +259,14 @@ defmodule Geo.PostGIS do quote do: fragment("ST_Point(?, ?)", unquote(x), unquote(y)) end + defmacro st_point_z(x, y, z) do + quote do: fragment("ST_PointZ(?, ?, ?)", unquote(x), unquote(y), unquote(z)) + end + + defmacro st_point_z(x, y, z, srid) do + quote do: fragment("ST_PointZ(?, ?, ?, ?)", unquote(x), unquote(y), unquote(z), unquote(srid)) + end + defmacro st_exterior_ring(geometry) do quote do: fragment("ST_ExteriorRing(?)", unquote(geometry)) end diff --git a/test/ecto_test.exs b/test/ecto_test.exs index 3c85d39..958b939 100644 --- a/test/ecto_test.exs +++ b/test/ecto_test.exs @@ -1005,4 +1005,24 @@ defmodule Geo.Ecto.Test do assert MapSet.new(polygon_coords) == MapSet.new(result.coordinates) end end + + describe "st_point_z/3 and st_point_z/4" do + test "creates a 3D point without SRID" do + query = from(l in LocationMulti, select: st_point_z(-71.104, 42.315, 3.4), limit: 1) + + result = Repo.one(query) + assert %Geo.PointZ{} = result + assert result.coordinates == {-71.104, 42.315, 3.4} + assert result.srid == nil + end + + test "creates a 3D point with SRID" do + query = from(l in LocationMulti, select: st_point_z(-71.104, 42.315, 3.4, 4326), limit: 1) + + result = Repo.one(query) + assert %Geo.PointZ{} = result + assert result.coordinates == {-71.104, 42.315, 3.4} + assert result.srid == 4326 + end + end end From 5a4875cb77e0a2413beaada5365221a89c589c8e Mon Sep 17 00:00:00 2001 From: Christopher Varjas Date: Sun, 21 Dec 2025 21:39:55 -0500 Subject: [PATCH 2/5] update tests and call syntax --- lib/geo_postgis.ex | 4 ++-- test/ecto_test.exs | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/geo_postgis.ex b/lib/geo_postgis.ex index dc3fa8e..779e307 100644 --- a/lib/geo_postgis.ex +++ b/lib/geo_postgis.ex @@ -260,11 +260,11 @@ defmodule Geo.PostGIS do end defmacro st_point_z(x, y, z) do - quote do: fragment("ST_PointZ(?, ?, ?)", unquote(x), unquote(y), unquote(z)) + quote do: fragment("ST_PointZ(?, ?, ?)::geometry", unquote(x), unquote(y), unquote(z)) end defmacro st_point_z(x, y, z, srid) do - quote do: fragment("ST_PointZ(?, ?, ?, ?)", unquote(x), unquote(y), unquote(z), unquote(srid)) + quote do: fragment("ST_PointZ(?, ?, ?, ?)::geometry", unquote(x), unquote(y), unquote(z), unquote(srid)) end defmacro st_exterior_ring(geometry) do diff --git a/test/ecto_test.exs b/test/ecto_test.exs index 958b939..6dbfec9 100644 --- a/test/ecto_test.exs +++ b/test/ecto_test.exs @@ -1008,6 +1008,9 @@ defmodule Geo.Ecto.Test do describe "st_point_z/3 and st_point_z/4" do test "creates a 3D point without SRID" do + point = %Geo.Point{coordinates: {0, 0}, srid: 4326} + Repo.insert(%LocationMulti{name: "empty", geom: point}) + query = from(l in LocationMulti, select: st_point_z(-71.104, 42.315, 3.4), limit: 1) result = Repo.one(query) @@ -1017,6 +1020,9 @@ defmodule Geo.Ecto.Test do end test "creates a 3D point with SRID" do + point = %Geo.Point{coordinates: {0, 0}, srid: 4326} + Repo.insert(%LocationMulti{name: "empty", geom: point}) + query = from(l in LocationMulti, select: st_point_z(-71.104, 42.315, 3.4, 4326), limit: 1) result = Repo.one(query) From 3c047cd7e25f56805adac6ea5113cfe7f76c8756 Mon Sep 17 00:00:00 2001 From: Christopher Varjas Date: Sun, 21 Dec 2025 21:42:28 -0500 Subject: [PATCH 3/5] add st_point_m --- lib/geo_postgis.ex | 8 ++++++++ test/ecto_test.exs | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/geo_postgis.ex b/lib/geo_postgis.ex index 779e307..2bd61bb 100644 --- a/lib/geo_postgis.ex +++ b/lib/geo_postgis.ex @@ -267,6 +267,14 @@ defmodule Geo.PostGIS do quote do: fragment("ST_PointZ(?, ?, ?, ?)::geometry", unquote(x), unquote(y), unquote(z), unquote(srid)) end + defmacro st_point_m(x, y, m) do + quote do: fragment("ST_PointM(?, ?, ?)", unquote(x), unquote(y), unquote(m)) + end + + defmacro st_point_m(x, y, m, srid) do + quote do: fragment("ST_PointM(?, ?, ?, ?)", unquote(x), unquote(y), unquote(m), unquote(srid)) + end + defmacro st_exterior_ring(geometry) do quote do: fragment("ST_ExteriorRing(?)", unquote(geometry)) end diff --git a/test/ecto_test.exs b/test/ecto_test.exs index 6dbfec9..fc66646 100644 --- a/test/ecto_test.exs +++ b/test/ecto_test.exs @@ -1031,4 +1031,30 @@ defmodule Geo.Ecto.Test do assert result.srid == 4326 end end + + describe "st_point_m/3 and st_point_m/4" do + test "creates a point with M coordinate without SRID" do + point = %Geo.Point{coordinates: {0, 0}, srid: 4326} + Repo.insert(%LocationMulti{name: "empty", geom: point}) + + query = from(l in LocationMulti, select: st_point_m(-71.104, 42.315, 3.4), limit: 1) + + result = Repo.one(query) + assert %Geo.PointM{} = result + assert result.coordinates == {-71.104, 42.315, 3.4} + assert result.srid == nil + end + + test "creates a point with M coordinate with SRID" do + point = %Geo.Point{coordinates: {0, 0}, srid: 4326} + Repo.insert(%LocationMulti{name: "empty", geom: point}) + + query = from(l in LocationMulti, select: st_point_m(-71.104, 42.315, 3.4, 4326), limit: 1) + + result = Repo.one(query) + assert %Geo.PointM{} = result + assert result.coordinates == {-71.104, 42.315, 3.4} + assert result.srid == 4326 + end + end end From bb8f109c5c8a701d41e343c63fd5672d046f860b Mon Sep 17 00:00:00 2001 From: Christopher Varjas Date: Sun, 21 Dec 2025 21:44:31 -0500 Subject: [PATCH 4/5] format --- lib/geo_postgis.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/geo_postgis.ex b/lib/geo_postgis.ex index 2bd61bb..ef26b7c 100644 --- a/lib/geo_postgis.ex +++ b/lib/geo_postgis.ex @@ -264,7 +264,14 @@ defmodule Geo.PostGIS do end defmacro st_point_z(x, y, z, srid) do - quote do: fragment("ST_PointZ(?, ?, ?, ?)::geometry", unquote(x), unquote(y), unquote(z), unquote(srid)) + quote do: + fragment( + "ST_PointZ(?, ?, ?, ?)::geometry", + unquote(x), + unquote(y), + unquote(z), + unquote(srid) + ) end defmacro st_point_m(x, y, m) do From ce1f307cd1e6571e2d58768187d24ca3d98bee40 Mon Sep 17 00:00:00 2001 From: Christopher Varjas Date: Sun, 21 Dec 2025 21:45:34 -0500 Subject: [PATCH 5/5] add st_point_zm --- lib/geo_postgis.ex | 16 ++++++++++++++++ test/ecto_test.exs | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/lib/geo_postgis.ex b/lib/geo_postgis.ex index ef26b7c..8a8832d 100644 --- a/lib/geo_postgis.ex +++ b/lib/geo_postgis.ex @@ -282,6 +282,22 @@ defmodule Geo.PostGIS do quote do: fragment("ST_PointM(?, ?, ?, ?)", unquote(x), unquote(y), unquote(m), unquote(srid)) end + defmacro st_point_zm(x, y, z, m) do + quote do: fragment("ST_PointZM(?, ?, ?, ?)", unquote(x), unquote(y), unquote(z), unquote(m)) + end + + defmacro st_point_zm(x, y, z, m, srid) do + quote do: + fragment( + "ST_PointZM(?, ?, ?, ?, ?)", + unquote(x), + unquote(y), + unquote(z), + unquote(m), + unquote(srid) + ) + end + defmacro st_exterior_ring(geometry) do quote do: fragment("ST_ExteriorRing(?)", unquote(geometry)) end diff --git a/test/ecto_test.exs b/test/ecto_test.exs index fc66646..8a5bc5b 100644 --- a/test/ecto_test.exs +++ b/test/ecto_test.exs @@ -1057,4 +1057,31 @@ defmodule Geo.Ecto.Test do assert result.srid == 4326 end end + + describe "st_point_zm/4 and st_point_zm/5" do + test "creates a 4D point without SRID" do + point = %Geo.Point{coordinates: {0, 0}, srid: 4326} + Repo.insert(%LocationMulti{name: "empty", geom: point}) + + query = from(l in LocationMulti, select: st_point_zm(-71.104, 42.315, 3.4, 4.5), limit: 1) + + result = Repo.one(query) + assert %Geo.PointZM{} = result + assert result.coordinates == {-71.104, 42.315, 3.4, 4.5} + assert result.srid == nil + end + + test "creates a 4D point with SRID" do + point = %Geo.Point{coordinates: {0, 0}, srid: 4326} + Repo.insert(%LocationMulti{name: "empty", geom: point}) + + query = + from(l in LocationMulti, select: st_point_zm(-71.104, 42.315, 3.4, 4.5, 4326), limit: 1) + + result = Repo.one(query) + assert %Geo.PointZM{} = result + assert result.coordinates == {-71.104, 42.315, 3.4, 4.5} + assert result.srid == 4326 + end + end end