Skip to content

Geometry type seems to be silently cast to geography #102

@kanes115

Description

@kanes115

Hey, I have the following definitions:

# Model
  schema "places" do
    field :name, :binary
    field :location, Geo.PostGIS.Geometry
  end

  def changeset(struct \\ %__MODULE__{}, attrs) do
    struct
    |> cast(attrs, @fields)
    |> validate_required(@fields)
  end

My migration:

    create table("places") do
      add :name, :binary
      add :location, :geometry
    end

And I try to use it as follows:

    google_maps_srid = 3857
    location = %Geo.Point{coordinates: {50.091211805442974, 19.89650102357312}, srid: google_maps_srid}
    %{name: "name", location: location}
    |> Place.changeset()
    |> Repo.insert()

I get the following error:

(Postgrex.Error) ERROR 22023 (invalid_parameter_value) Only lon/lat coordinate systems are supported in geography.

And insert log:

21:54:17.882 [debug] QUERY ERROR db=38.5ms queue=4.3ms
     INSERT INTO "places" ("location","name") VALUES ($1,$2) RETURNING "id" [%Geo.Point{coordinates: {50.091211805442974, 19.89650102357312}, properties: %{}, srid: 3857}, "Some name"]

It looks like somewhere along the way the geometry type is treated as geography but I fail at understanding where. Any help would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions