Skip to content

Commit e8bf2cf

Browse files
committed
Fixed bug preventing decoding of geometrycollections with one element
1 parent 5b38781 commit e8bf2cf

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v1.1.2
2+
* Bug Fixes
3+
* WKBs that are GeometryCollections with one element should now properly decode
4+
15
# v1.1.1
26
* Enhancements
37
* Added `Geo.JSON.EncodeError` and `Geo.JSON.DecodeError` thrown whenever `Geo.JSON.encode` or `Geo.JSON.decode` are given invalid data

lib/geo/wkb.ex

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defmodule Geo.WKB do
1414

1515
@moduledoc """
1616
Converts to and from WKB and EWKB
17-
17+
1818
point = Geo.WKB.decode("0101000000000000000000F03F000000000000F03F")
1919
Geo.Point[coordinates: {1, 1}, srid: nil]
2020
@@ -168,7 +168,9 @@ defmodule Geo.WKB do
168168
geometries =
169169
case type do
170170
%Geo.GeometryCollection{} ->
171-
coordinates = Enum.map(coordinates, fn(x) -> %{ x | srid: srid } end)
171+
coordinates = coordinates
172+
|> Enum.map(fn(x) -> %{ x | srid: srid } end)
173+
172174
%{ type | geometries: coordinates, srid: srid }
173175
_ ->
174176
geometries ++ [ %{ type | coordinates: coordinates, srid: srid }]
@@ -224,7 +226,8 @@ defmodule Geo.WKB do
224226

225227
defp decode_coordinates(%GeometryCollection{}, wkb_reader) do
226228
{_number_of_items, wkb_reader} = Reader.read(wkb_reader, 8)
227-
{ decode(Reader.get_wkb(wkb_reader)), Reader.start("00") }
229+
geometries = decode(Reader.get_wkb(wkb_reader))
230+
{ List.wrap(geometries), Reader.start("00") }
228231
end
229232

230233
defp decode_coordinates(_geom, wkb_reader) do

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule Geo.Mixfile do
33

44
def project do
55
[ app: :geo,
6-
version: "1.1.1",
6+
version: "1.1.2",
77
elixir: "~> 1.0",
88
deps: deps,
99
description: description,

test/geo/wkb_test.exs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,22 @@ defmodule Geo.WKB.Test do
156156
{-8.91605728674111, 37.014786050505705}]]])
157157
end
158158

159+
test "Decoding of GeometryCollection with one geometry" do
160+
geom = %Geo.GeometryCollection{geometries: [%Geo.Point{ coordinates: {54.1745659, 15.5398456}, srid: 4326 }], srid: 4326 }
161+
wkb = Geo.WKB.encode(geom)
162+
geodata = Geo.WKB.decode(wkb)
163+
164+
assert wkb == "0020000007000010E6000000010000000001404B16582CE7BF97402F1466A479C76C"
165+
assert geom == geodata
166+
end
167+
168+
test "Decoding of GeometryCollection with two geometries" do
169+
geom = %Geo.GeometryCollection{geometries: [%Geo.Point{ coordinates: {54.1745659, 15.5398456}, srid: 4326 },
170+
%Geo.Point{ coordinates: {54.1745659, 15.5398456}, srid: 4326 }], srid: 4326 }
171+
wkb = Geo.WKB.encode(geom)
172+
geodata = Geo.WKB.decode(wkb)
173+
174+
assert geom == geodata
175+
end
176+
159177
end

0 commit comments

Comments
 (0)