From 4673657812ae76e0b87e2f75e6a1b79003d55546 Mon Sep 17 00:00:00 2001 From: Jason Axelson Date: Fri, 10 Sep 2021 11:41:11 -0700 Subject: [PATCH 1/6] Handle MultiLineString with empty coordinates Fixes #163 --- lib/geo/wkb/decoder.ex | 13 +++++++++++++ test/geo/wkb_test.exs | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/lib/geo/wkb/decoder.ex b/lib/geo/wkb/decoder.ex index 6fc43fd..96d4ea3 100644 --- a/lib/geo/wkb/decoder.ex +++ b/lib/geo/wkb/decoder.ex @@ -98,6 +98,19 @@ defmodule Geo.WKB.Decoder do {%PointZM{coordinates: {x, y, z, m}, srid: srid}, rest} end + defp do_decode( + @line_string, + <<0::unquote(modifier)-32, "">>, + _srid, + unquote(endian) + ) do + {%Geo.LineString{ + coordinates: [], + properties: %{}, + srid: nil + }, ""} + end + defp do_decode( @line_string, <>, diff --git a/test/geo/wkb_test.exs b/test/geo/wkb_test.exs index ea7d872..b13c6e8 100644 --- a/test/geo/wkb_test.exs +++ b/test/geo/wkb_test.exs @@ -399,6 +399,13 @@ defmodule Geo.WKB.Test do assert(point.srid == 4326) end + test "Decode EWKB of empty MultiLineString" do + multi_line_string = Geo.WKB.decode!("010500000001000000010200000000000000") + assert multi_line_string.coordinates == [[]] + assert multi_line_string.properties == %{} + assert multi_line_string.srid == nil + end + test "Encode MultiLineString to WKB" do geom = %Geo.MultiLineString{coordinates: [[{10, 10}, {20, 20}], [{15, 15}, {30, 15}]]} From c9b14c474b09dbc9b5524690bca1b47e7c9bf725 Mon Sep 17 00:00:00 2001 From: Jason Axelson Date: Fri, 10 Sep 2021 12:48:49 -0700 Subject: [PATCH 2/6] Pass through the srid --- lib/geo/wkb/decoder.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/geo/wkb/decoder.ex b/lib/geo/wkb/decoder.ex index 96d4ea3..a7400a9 100644 --- a/lib/geo/wkb/decoder.ex +++ b/lib/geo/wkb/decoder.ex @@ -101,13 +101,13 @@ defmodule Geo.WKB.Decoder do defp do_decode( @line_string, <<0::unquote(modifier)-32, "">>, - _srid, + srid, unquote(endian) ) do {%Geo.LineString{ coordinates: [], properties: %{}, - srid: nil + srid: srid }, ""} end From dfe665fc0a45a2d7343a74e08046322464600b45 Mon Sep 17 00:00:00 2001 From: Jason Axelson Date: Mon, 13 Sep 2021 10:44:14 -0700 Subject: [PATCH 3/6] Add a test that includes an encoded srid --- test/geo/wkb_test.exs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/geo/wkb_test.exs b/test/geo/wkb_test.exs index b13c6e8..4ba839c 100644 --- a/test/geo/wkb_test.exs +++ b/test/geo/wkb_test.exs @@ -406,6 +406,14 @@ defmodule Geo.WKB.Test do assert multi_line_string.srid == nil end + test "Decode EWKB of empty MultiLineString that has an srid" do + multi_line_string = Geo.WKB.decode!("0020000005000010E600000001000000000200000000") + + assert multi_line_string.coordinates == [[]] + assert multi_line_string.properties == %{} + assert multi_line_string.srid == 4326 + end + test "Encode MultiLineString to WKB" do geom = %Geo.MultiLineString{coordinates: [[{10, 10}, {20, 20}], [{15, 15}, {30, 15}]]} From 047d7b69cfa3b1cc195d5a6082960e3d52c2dc76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 20 Nov 2021 10:26:10 +0100 Subject: [PATCH 4/6] Clarify the base16 aspect vs bytes aspect of WKB --- lib/geo/wkb.ex | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/geo/wkb.ex b/lib/geo/wkb.ex index 2801951..5386b33 100644 --- a/lib/geo/wkb.ex +++ b/lib/geo/wkb.ex @@ -2,6 +2,8 @@ defmodule Geo.WKB do @moduledoc """ Converts to and from WKB and EWKB. + It supports WKB both as base-16 encoded strings or as binaries. + ## Examples iex> {:ok, point} = Geo.WKB.decode("0101000000000000000000F03F000000000000F03F") @@ -18,8 +20,9 @@ defmodule Geo.WKB do alias Geo.WKB.{Encoder, Decoder} @doc """ - Takes a Geometry and returns a WKB string. The endian decides - what the byte order will be. + Takes a Geometry and returns a base-16 encoded WKB string. + + The endian decides what the byte order will be. """ @spec encode!(Geo.geometry(), Geo.endian()) :: binary def encode!(geom, endian \\ :xdr) do @@ -27,7 +30,7 @@ defmodule Geo.WKB do end @doc """ - Takes a Geometry and returns a WKB string. + Takes a Geometry and returns a base-16 encoded WKB string. The endian decides what the byte order will be. """ @@ -40,7 +43,7 @@ defmodule Geo.WKB do end @doc """ - Takes a Geometry and returns a WKB as iodata. + Takes a Geometry and returns WKB as iodata (a sequence of bytes). The endian decides what the byte order will be. """ @@ -50,7 +53,7 @@ defmodule Geo.WKB do end @doc """ - Takes a WKB string and returns a Geometry. + Takes a WKB, either as a base-16 encoded string or a binary, and returns a Geometry. """ @spec decode(binary) :: {:ok, Geo.geometry()} | {:error, Exception.t()} def decode(wkb) do @@ -61,9 +64,9 @@ defmodule Geo.WKB do end @doc """ - Takes a WKB string and returns a Geometry. + Takes a WKB, either as a base-16 encoded string or a binary, and returns a Geometry. """ - @spec decode!(iodata()) :: Geo.geometry() + @spec decode!(binary) :: Geo.geometry() def decode!(wkb) def decode!("00" <> _ = wkb) do From 79aab21140a30e1998f7e7d3e2cb2988086b6910 Mon Sep 17 00:00:00 2001 From: Wojtek Mach Date: Wed, 15 Dec 2021 18:12:38 +0100 Subject: [PATCH 5/6] Remove config/ I'd assume the logger level was to silence out stuff in tests but that doesn't seem to be the case. --- config/config.exs | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 config/config.exs diff --git a/config/config.exs b/config/config.exs deleted file mode 100644 index 28c45b1..0000000 --- a/config/config.exs +++ /dev/null @@ -1,3 +0,0 @@ -use Mix.Config - -config :logger, level: :warn From 7737953f31100a8bdb53e1ad173e7f5af6abd632 Mon Sep 17 00:00:00 2001 From: Bryan Joseph Date: Wed, 15 Dec 2021 19:33:05 -0600 Subject: [PATCH 6/6] Update Changelog and version --- CHANGELOG.md | 5 +++++ mix.exs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a195e7..c446780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## v3.4.3 - 2021-12-15 +- Fix + - [Handle MultiLineString with empty coordinates](https://github.com/bryanjos/geo/pull/164) + - [Clarify whether functions in Geo.WKB accept or return base16 or bytes](https://github.com/bryanjos/geo/pull/166) + ## v3.4.2 - 2021-04-11 - Fix diff --git a/mix.exs b/mix.exs index 210e283..7450699 100644 --- a/mix.exs +++ b/mix.exs @@ -2,7 +2,7 @@ defmodule Geo.Mixfile do use Mix.Project @source_url "https://github.com/bryanjos/geo" - @version "3.4.2" + @version "3.4.3" def project do [