Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for LineStringZM #160

Merged
merged 6 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/geo_postgis/extension.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ defmodule Geo.PostGIS.Extension do
Geo.GeometryCollection,
Geo.LineString,
Geo.LineStringZ,
Geo.LineStringZM,
Geo.MultiLineString,
Geo.MultiLineStringZ,
Geo.MultiPoint,
Expand Down
3 changes: 3 additions & 0 deletions lib/geo_postgis/geometry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if Code.ensure_loaded?(Ecto.Type) do
PointZM,
LineString,
LineStringZ,
LineStringZM,
Polygon,
PolygonZ,
MultiPoint,
Expand All @@ -29,6 +30,7 @@ if Code.ensure_loaded?(Ecto.Type) do
"PointZM",
"LineString",
"LineStringZ",
"LineStringZM",
"Polygon",
"PolygonZ",
"MultiPoint",
Expand All @@ -46,6 +48,7 @@ if Code.ensure_loaded?(Ecto.Type) do
PointZM,
LineString,
LineStringZ,
LineStringZM,
Polygon,
PolygonZ,
MultiPoint,
Expand Down
38 changes: 37 additions & 1 deletion test/geo_postgis_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Geo.PostGIS.Test do
{:ok, _result} =
Postgrex.query(
pid,
"DROP TABLE IF EXISTS text_test, point_test, linestring_test, polygon_test, multipoint_test, multilinestring_test, multipolygon_test, geometrycollection_test",
"DROP TABLE IF EXISTS text_test, point_test, linestring_test, linestringz_test, linestringzm_test, polygon_test, multipoint_test, multilinestring_test, multipolygon_test, geometrycollection_test",
[]
)

Expand Down Expand Up @@ -76,6 +76,42 @@ defmodule Geo.PostGIS.Test do
assert(result.rows == [[42, geo]])
end

test "insert LineStringZ", context do
pid = context[:pid]
geo = %Geo.LineStringZ{srid: 4326, coordinates: [{30, 10, 20}, {10, 30, 2}, {40, 40, 50}]}

{:ok, _} =
Postgrex.query(
pid,
"CREATE TABLE linestringz_test (id int, geom geometry(LineStringZ, 4326))",
[]
)

{:ok, _} = Postgrex.query(pid, "INSERT INTO linestringz_test VALUES ($1, $2)", [42, geo])
{:ok, result} = Postgrex.query(pid, "SELECT * FROM linestringz_test", [])
assert result.rows == [[42, geo]]
end

test "insert LineStringZM", context do
pid = context[:pid]

geo = %Geo.LineStringZM{
srid: 4326,
coordinates: [{30, 10, 20, 40}, {10, 30, 2, -10}, {40, 40, 50, 100}]
}

{:ok, _} =
Postgrex.query(
pid,
"CREATE TABLE linestringzm_test (id int, geom geometry(LineStringZM, 4326))",
[]
)

{:ok, _} = Postgrex.query(pid, "INSERT INTO linestringzm_test VALUES ($1, $2)", [42, geo])
{:ok, result} = Postgrex.query(pid, "SELECT * FROM linestringzm_test", [])
assert result.rows == [[42, geo]]
end

test "insert polygon", context do
pid = context[:pid]

Expand Down
Loading