felt / geo

A collection of GIS functions for Elixir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with encoding/decoding GeometryCollection

nordbit opened this issue · comments

iex(1)> geom = %Geo.GeometryCollection{geometries: [%Geo.Point{ coordinates: {54.1745659, 15.5398456}, srid: 4326 }], srid: 4326 }

%Geo.GeometryCollection{geometries: [%Geo.Point{coordinates: {54.1745659,
    15.5398456}, srid: 4326}], srid: 4326}

iex(2)> Geo.WKB.encode(geom)
"0020000007000010E6000000010000000001404B16582CE7BF97402F1466A479C76C"

iex(3)> geodata = Geo.WKB.decode("0020000007000010E6000000010000000001404B16582CE7BF97402F1466A479C76C")

** (Protocol.UndefinedError) protocol Enumerable not implemented for %Geo.Point{coordinates: {54.1745659, 15.5398456}, srid: nil}
    (elixir) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir) lib/enum.ex:116: Enumerable.reduce/3
    (elixir) lib/enum.ex:1627: Enum.reduce/3
    (elixir) lib/enum.ex:1188: Enum.map/2
       (geo) lib/geo/wkb.ex:171: Geo.WKB.decode/2

I got "srid: nill", what i'm doing wrong when encoding GeometryCollection and why Geo can encode but can not decode?

That's definitely a bug. I will take a look as soon as I can

NO problem with decoding data coded by GeoDjango:

iex(5)> geodata = Geo.WKB.decode("0107000020E61000000500000001030000000100000005000000010000C007282F40F02A773ED1164B40FFFFFFBFE8282F405A3994AAD8154B400000004099342F40ED61E7841A164B400000004012342F4022DDD6DA0A174B40010000C007282F40F02A773ED1164B40010100000000000060E0272F40B0213F89D4164B400101000000000000A0DF332F403E5336800C174B400101000000000000E004292F4039421C05D7154B400101000000FFFFFFDF71342F40E1CD013A17164B40")

%Geo.GeometryCollection{geometries: [%Geo.Polygon{coordinates: [[{15.578184127807619,
      54.17826062029587}, {15.579900741577147, 54.170674631476416},
     {15.602731704711914, 54.172684300403354},
     {15.601701736450195, 54.180018763460126},
     {15.578184127807619, 54.17826062029587}]], srid: 4326},
  %Geo.Point{coordinates: {15.57788372039795, 54.17836108763311}, srid: 4326},
  %Geo.Point{coordinates: {15.60131549835205, 54.18006899502369}, srid: 4326},
  %Geo.Point{coordinates: {15.58011531829834, 54.1706243885023}, srid: 4326},
  %Geo.Point{coordinates: {15.602431297302244, 54.17258381927582}, srid: 4326}],
 srid: 4326}

And where coded are two points in GeometryCollection, not only one, data are coded and decoded correctly:

iex(9)> geom = %Geo.GeometryCollection{geometries: [%Geo.Point{ coordinates: {54.1745659, 15.5398456}, srid: 4326 }, %Geo.Point{coordinates: {15.58011531829834, 54.1706243885023}, srid: 4326}], srid: 4326 }
%Geo.GeometryCollection{geometries: [%Geo.Point{coordinates: {54.1745659,
    15.5398456}, srid: 4326},
  %Geo.Point{coordinates: {15.58011531829834, 54.1706243885023}, srid: 4326}],
 srid: 4326}
iex(10)> Geo.WKB.encode(geom)
"0020000007000010E6000000020000000001404B16582CE7BF97402F1466A479C76C0000000001402F2904E0000000404B15D7051C4239"
iex(11)> geodata = Geo.WKB.decode("0020000007000010E6000000020000000001404B16582CE7BF97402F1466A479C76C0000000001402F2904E0000000404B15D7051C4239")
%Geo.GeometryCollection{geometries: [%Geo.Point{coordinates: {54.1745659,
    15.5398456}, srid: 4326},
  %Geo.Point{coordinates: {15.58011531829834, 54.1706243885023}, srid: 4326}],
 srid: 4326}

so problem exist only when in collection is one point

Fixed and published to hex as 1.1.2
https://hex.pm/packages/geo/1.1.2