diff --git a/lib/geo_postgis.ex b/lib/geo_postgis.ex index 228ebff..66ae85f 100644 --- a/lib/geo_postgis.ex +++ b/lib/geo_postgis.ex @@ -401,6 +401,9 @@ defmodule Geo.PostGIS do ) end + defmacro st_extent(geometry) do + quote do: fragment("ST_EXTENT(?)::geometry", unquote(geometry)) + defmacro st_build_area(geometryA) do quote do: fragment("ST_BuildArea(?)", unquote(geometryA)) end diff --git a/test/ecto_test.exs b/test/ecto_test.exs index c64a536..b449197 100644 --- a/test/ecto_test.exs +++ b/test/ecto_test.exs @@ -123,6 +123,16 @@ defmodule Geo.Ecto.Test do assert results == 0 end + test "st_extent" do + geom = Geo.WKB.decode!(@multipoint_wkb) + + Repo.insert(%Location{name: "hello", geom: geom}) + + query = from(location in Location, select: st_extent(location.geom)) + assert [%Geo.Polygon{coordinates: [coordinates]}] = Repo.all(query) + assert length(coordinates) == 5 + end + test "example" do geom = Geo.WKB.decode!(@multipoint_wkb) Repo.insert(%Location{name: "hello", geom: geom})