Store geojson polygons in jsonb

Hi everyone! I’m trying to create a CRUD of geoJSON polygons. I want to store coordinates inside jsonb field.

What’s the correct way to do this?

    [100.0, 0.0],
    [101.0, 0.0],
    [101.0, 1.0],
    [100.0, 1.0],
    [100.0, 0.0]

Can I use embeds_many for nested arrays? Or should I use something like

field :coordinates, {:array, {:array, {:array, :float}}}

If the shape is predictable perhaps you can create an embedded schema to store as json.

You may want to have a look at a PostGIS extension for Ecto.

1 Like