Skip to content

Commit

Permalink
Add st_extent query support
Browse files Browse the repository at this point in the history
Since geo/geo_postis doesn't support box2d (see
felt/geo#160) return a geometry object instead
  • Loading branch information
axelson committed Sep 1, 2021
1 parent 80ebb06 commit f408f8b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/geo_postgis.ex
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,8 @@ defmodule Geo.PostGIS do
unquote(seed)
)
end

defmacro st_extent(geometry) do
quote do: fragment("ST_EXTENT(?)::geometry", unquote(geometry))
end
end
10 changes: 10 additions & 0 deletions test/ecto_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit f408f8b

Please sign in to comment.