Skip to content

Commit

Permalink
Add support for LineStringZM (#160)
Browse files Browse the repository at this point in the history
* Add support for LineStringZM

* Add support for LineStringZM

* Add currently failing test, pending Geo.LineStringZM support upstream

---------

Co-authored-by: Tyler Young <tyler@tylerayoung.com>
  • Loading branch information
versilov and s3cur3 authored Oct 23, 2023
1 parent c220d2d commit b09d20b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
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

0 comments on commit b09d20b

Please sign in to comment.