felt / geo_postgis Goto Github PK
View Code? Open in Web Editor NEWPostrex Extension for PostGIS
License: MIT License
Postrex Extension for PostGIS
License: MIT License
I'm a bit confused in terms of how pure Postgrex interaction is supposed to work with the PostgrexTypes. The README/docs seem to imply that I should be able to pass an Elixir type as a parameter to a query (per the examples of inserting geometry into a table), e.g. I should be able to pass something like a %Geo.Point
or %Geo.Polygon
directly, without needing to encode it as WKB or WKT. However, it doesn't seem to work for me - I have to encode them for it to work. Example iex session showing this follows.
In the example, I can do this which works (where box1
and box2
are %Geo.Polygon
s:
Postgrex.query!(pid, "SELECT ST_Intersection($1, $2)", [Geo.WKT.encode!(box1), Geo.WKT.encode!(box2)])
But, as the below example shows (at the very end), doing this fails, saying it expected a binary:
Postgrex.query!(pid, "SELECT ST_Intersection($1, $2)", [box1, box2])
Here's the example iex session:
iex(1)> Postgrex.Types.define(MyApp.PostgrexTypes, [Geo.PostGIS.Extension], [])
{:module, MyApp.PostgrexTypes,
# <full result snipped for clarity>
iex(2)> opts = [hostname: "localhost", username: "postgres", database: "osm", types: MyApp.PostgrexTypes ]
[
hostname: "localhost",
username: "postgres",
database: "osm",
types: MyApp.PostgrexTypes
]
iex(3)> {:ok, pid} = Postgrex.start_link(opts)
{:ok, #PID<0.403.0>}
iex(4)> box1 = %Geo.Polygon{coordinates: [[{0, 0}, {2, 0}, {2, 2}, {0,2}, {0,0}]]}
%Geo.Polygon{
coordinates: [[{0, 0}, {2, 0}, {2, 2}, {0, 2}, {0, 0}]],
properties: %{},
srid: nil
}
iex(5)> box2 = %Geo.Polygon{coordinates: [[{1, 1}, {3, 1}, {3, 3}, {1,3}, {1,1}]]}
%Geo.Polygon{
coordinates: [[{1, 1}, {3, 1}, {3, 3}, {1, 3}, {1, 1}]],
properties: %{},
srid: nil
}
iex(6)> Postgrex.query!(pid, "SELECT ST_Intersection($1, $2)", [Geo.WKT.encode!(box1), Geo.WKT.encode!(box2)])
%Postgrex.Result{
columns: ["st_intersection"],
command: :select,
connection_id: 14112,
messages: [],
num_rows: 1,
rows: [
[
%Geo.Polygon{
coordinates: [
[{1.0, 2.0}, {2.0, 2.0}, {2.0, 1.0}, {1.0, 1.0}, {1.0, 2.0}]
],
properties: %{},
srid: nil
}
]
]
}
iex(7)> Postgrex.query!(pid, "SELECT ST_Intersection($1, $2)", [box1, box2])
** (DBConnection.EncodeError) Postgrex expected a binary, got %Geo.Polygon{coordinates: [[{0, 0}, {2, 0}, {2, 2}, {0, 2}, {0, 0}]], properties: %{}, srid: nil}. Please make sure the value you are passing matches the definition in your table or in your query or convert the value accordingly.
deps/postgrex/lib/postgrex/type_module.ex:897: MyApp.PostgrexTypes.encode_params/3
(postgrex) lib/postgrex/query.ex:75: DBConnection.Query.Postgrex.Query.encode/3
(db_connection) lib/db_connection.ex:1148: DBConnection.encode/5
(db_connection) lib/db_connection.ex:1246: DBConnection.run_prepare_execute/5
(db_connection) lib/db_connection.ex:1342: DBConnection.run/6
(db_connection) lib/db_connection.ex:540: DBConnection.parsed_prepare_execute/5
(db_connection) lib/db_connection.ex:533: DBConnection.prepare_execute/4
(postgrex) lib/postgrex.ex:219: Postgrex.query_prepare_execute/4```
I can of course add the encoding calls to all my code, but the README led me to believe that that shouldn't be necessary, so I wanted to see what the expectation is for queries like this, or what I might be not doing right.
I'm following the README and I got this error when I run the migrations
$ mix ecto.migrate
** (MatchError) no match of right hand side value: {:error, {:poison, {'no such file or directory', 'poison.app'}}}
(ecto_sql) lib/mix/ecto_sql.ex:9: Mix.EctoSQL.ensure_started/2
(ecto_sql) lib/mix/tasks/ecto.migrate.ex:103: anonymous fn/4 in Mix.Tasks.Ecto.Migrate.run/2
(elixir) lib/enum.ex:769: Enum."-each/2-lists^foreach/1-0-"/2
(elixir) lib/enum.ex:769: Enum.each/2
(mix) lib/mix/task.ex:331: Mix.Task.run_task/3
(mix) lib/mix/cli.ex:79: Mix.CLI.run_task/2
I think this is an incompatibility in Phoenix 1.4 since they changed from Poison to Jason
I'm getting the following error message for calling st_distance_in_meters()
** (Ecto.Query.CompileError) `st_distance_in_meters(g.geo_point(), ^geo_point)` is not a valid query expression.
with the following snippet:
Repo.all from u in User,
select: %{u | distance: st_distance_in_meters(g.geo_point, ^geo_point)}
While the snippet above fails, it works like a charme for st_distance
.
Repo.all from u in User,
select: %{u | distance: st_distance(g.geo_point, ^geo_point)}
As much as I understood the code, both functions take the same input and therefore it should work. I don't really understand why g.geo_point
is enhanced to a function in the first case, but is taken as a variable in the second call.
Currently, the way the README saids to define a geometry field in migrations is like so:
add(:geom, :geometry)
But what if you wanted to add constraints so that only a type and/or SRID is allowed? You can but you have to like so:
add(:geom, :"geometry(Point, 4326)")
That works, but maybe we can add some helpers so that it feels slightly more natural?
import Geo.PostGIS.Migrations
add(:geom, geometry(Geo.Point, 4326))
I have an project making use of geo_postgis and it works fine using Elixir 1.14.
When changing version to 1.15 the compilation fails:
** (ArgumentError) unknown type Geo.PostGIS.Geometry for field :boundary
(ecto 3.10.3) lib/ecto/schema.ex:2318: Ecto.Schema.check_field_type!/4
(ecto 3.10.3) lib/ecto/schema.ex:1931: Ecto.Schema.__field__/4
lib/ls/gis/schema/municipality_schema.ex:11: (module)
Running mix deps.clean && mix.deps.get
and such doesn't seem to help out.
It's not always 100% easy to reproduce. I guess it's because you might have your files compiled with 1.14 lying around, which makes it work.
I believe this could be related to the code pruning introduced in Elixir 1.15 (https://hexdocs.pm/elixir/1.15/changelog.html)
Due to the code path pruning, if you have an application or dependency that does not specify its dependencies on Erlang and Elixir application, it may no longer compile successfully in Elixir v1.15.
Since geo_postgis doesn't have a hard dependency on ecto ({:ecto_sql, "~> 3.0", optional: true, only: :test}
) I would expect the code pruning to kick in. This matches what I'm seeing because in geometry.ex
the code if Code.ensure_loaded?(Ecto.Type) do
always seems to return false
for me (using Elixir 1.15).
Setting prune_code_paths: false
for the project in mix.exs
does fix the problem for me, which also indicates that this is the issue.
I created a sample phoenix 1.3 project using
`sudo mix phx.new Server --app locationsearch --no-html --no-brunch
Installed this library as dependency
mix.exs
defp deps do
[
{:phoenix, "~> 1.3.0"},
{:phoenix_pubsub, "~> 1.0"},
{:phoenix_ecto, "~> 3.2"},
{:postgrex, ">= 0.0.0"},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"},
{:geo_postgis, "~> 1.0"}
]
end
dev,exs
# Configure your database
config :locationsearch, Locationsearch.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "123456",
database: "locationsearch_dev",
hostname: "localhost",
pool_size: 10,
extensions: [{Geo.PostGIS.Extension, library: Geo}]
`
In My Priv Folder
File 1:
defmodule Locationsearch.Repo.Migrations.EnablePostgis do
use Ecto.Migration
def change do
end
def up do
execute "CREATE EXTENSION IF NOT EXISTS postgis"
end
def down do
execute "DROP EXTENSION IF EXISTS postgis"
end
end
File 2 :`
defmodule Locationsearch.Repo.Migrations.CreateShipData do
use Ecto.Migration
def up do
create table(:test) do
add :name, :string
add :geom, :geometry
end
end
def down do
drop table(:test)
end
end
Dont know where to put this code
Postgrex.Types.define(Locationsearch.PostgresTypes,
[Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
json: Poison)
When i run
mix ecto.migrate
I am getting lots of errors tried different solutons but nothing works
Can you tell me where i am going wrong.
Do you have any idea to build a example phoenix1.3 app with this library if so it would be very helpful for many of us.
Thanks.Your help is much appreciated
Hi
I have a schema:
user Ecto.Schema
schema "events" do
field :coordinates, Geo.PostGIS.Geometry
with a migration:
use Ecto.Migration
def up do
create table(:events) do
...
end
execute("ALTER TABLE events ADD COLUMN coordinates geography(LINESTRING, 4326);")
end
In MyApp.Application.start, I% declared:
Postgrex.Types.define( LiveMap.PostgresTypes, [Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
and in the "config/config.exs", I also declared:
config :my_app, MyApp.Repo,
...
adapter: Ecto.Adapters.Postgres,
types: LiveMap.PostgresTypes
When I just try to seed, the function "geomfromtext' is not known:
MyApp.Repo.insert!(%MYApp.Event{
coordinates: st_geomfromtext('linestring(...)', 4326)
})
I seed "manually":
Ecto.Adapters.SQL.query!(
LiveMap.Repo,
"INSERT INTO events (owner, coordinates, ad1, ad2, date)
SELECT
1,
ST_GeomFromText('LINESTRING(0 40, 0 41)',4326),
'1 ad1',
'1 ad2',
'2021/10/01'
FROM users
ORDER BY id ASC LIMIT 1;",
[]
)
and when I run:
Ecto.Adapters.SQL.query!(LiveMap.Repo, "SELECT * from events", [])
then it seems ok:
%Postgrex.Result{
command: :select,
columns: ["id", "owner", "distance", "ad1", "ad2", "date", "coordinates"],
rows: [
[
1,
1,
nil,
"1 ad1",
"1 ad2",
~D[2021-10-01],
%Geo.LineString{
coordinates: [{0.0, 40.0}, {0.0, 41.0}],
srid: 4326,
properties: %{}
}
],
...
I'm not sure if this issue should be filed in geo
but if I upgrade my dependencies to latest I start getting errors when doing a st_dwithin_in_meters
query. It all works if I stay at 3.3.3 and 3.3.1
I'm unfortunately not very well versed in either Elixir/Phoenix or PostGIS, so it's quite possible I'm doing something silly. I read through the changelogs but still have no clue how to go about fixing this. Once at latest, this is the log with the error:
[debug] QUERY ERROR source="rooms" db=1.7ms queue=1.2ms idle=249.7ms
phoenix_1 | SELECT r0."id", r0."name", r0."category_id", r0."lat", r0."lng", r0."coordinates", r0."radius", r0."description", r0."inserted_at", r0."updated_at" FROM "rooms" AS r0 WHERE (ST_DWithin(r0."coordinates"::geography, $1::geography, r0."radius")) ORDER BY ST_Distance(r0."coordinates"::geography, $2::geography) LIMIT 5 [%Geo.Point{coordinates: {"14.4912463", "46.0700097"}, properties: %{}, srid: 4326}, %Geo.Point{coordinates: {"14.4912463", "46.0700097"}, properties: %{}, srid: 4326}]
phoenix_1 | [info] Sent 500 in 39ms
phoenix_1 | [error] #PID<0.1458.0> running KjerSiWeb.Endpoint (connection #PID<0.1457.0>, stream id 1) terminated
phoenix_1 | Server: 192.168.1.129:4000 (http)
phoenix_1 | Request: GET /api/rooms?lat=46.0700097&lng=14.4912463
phoenix_1 | ** (exit) an exception was raised:
phoenix_1 | ** (ArgumentError) argument error
phoenix_1 | (geo 3.4.2) lib/geo/wkb/encoder.ex:61: Geo.WKB.Encoder.do_encode/2
phoenix_1 | (geo 3.4.2) lib/geo/wkb/encoder.ex:48: Geo.WKB.Encoder.encode!/2
phoenix_1 | (kjer_si 0.1.0) lib/geo_postgis/extension.ex:76: KjerSi.PostgresTypes."Elixir.Geo.PostGIS.Extension"/1
phoenix_1 | (kjer_si 0.1.0) deps/postgrex/lib/postgrex/type_module.ex:897: KjerSi.PostgresTypes.encode_params/3
phoenix_1 | (postgrex 0.15.8) lib/postgrex/query.ex:75: DBConnection.Query.Postgrex.Query.encode/3
phoenix_1 | (db_connection 2.4.0) lib/db_connection.ex:1205: DBConnection.encode/5
phoenix_1 | (db_connection 2.4.0) lib/db_connection.ex:1305: DBConnection.run_prepare_execute/5
phoenix_1 | (db_connection 2.4.0) lib/db_connection.ex:1409: DBConnection.run/6
phoenix_1 | (db_connection 2.4.0) lib/db_connection.ex:574: DBConnection.parsed_prepare_execute/5
phoenix_1 | (db_connection 2.4.0) lib/db_connection.ex:566: DBConnection.prepare_execute/4
phoenix_1 | (ecto_sql 3.6.1) lib/ecto/adapters/sql.ex:690: Ecto.Adapters.SQL.execute!/4
phoenix_1 | (ecto_sql 3.6.1) lib/ecto/adapters/sql.ex:682: Ecto.Adapters.SQL.execute/5
phoenix_1 | (ecto 3.6.1) lib/ecto/repo/queryable.ex:224: Ecto.Repo.Queryable.execute/4
phoenix_1 | (ecto 3.6.1) lib/ecto/repo/queryable.ex:19: Ecto.Repo.Queryable.all/3
phoenix_1 | (kjer_si 0.1.0) lib/kjer_si/rooms.ex:265: KjerSi.Rooms.get_rooms_around_point/1
phoenix_1 | (kjer_si 0.1.0) lib/kjer_si_web/controllers/room_controller.ex:24: KjerSiWeb.RoomController.index/2
phoenix_1 | (kjer_si 0.1.0) lib/kjer_si_web/controllers/room_controller.ex:1: KjerSiWeb.RoomController.action/2
phoenix_1 | (kjer_si 0.1.0) lib/kjer_si_web/controllers/room_controller.ex:1: KjerSiWeb.RoomController.phoenix_controller_pipeline/2
phoenix_1 | (phoenix 1.5.8) lib/phoenix/router.ex:352: Phoenix.Router.__call__/2
phoenix_1 | (kjer_si 0.1.0) lib/kjer_si_web/endpoint.ex:1: KjerSiWeb.Endpoint.plug_builder_call/2
The relevant bits of code seem to be:
room_controller.ex
def index(conn, params) do
changeset = room_index(params)
if changeset.valid? do
point = %Geo.Point{coordinates: {params["lng"], params["lat"]}, srid: 4326}
rooms = Rooms.get_rooms_around_point(point)
render(conn, "index.json", rooms: rooms)
else
{:error, changeset}
end
end
and rooms.exs
def get_rooms_around_point(point) do
query =
from room in Room,
where: st_dwithin_in_meters(room.coordinates, ^point, room.radius),
order_by: [asc: st_distance_in_meters(room.coordinates, ^point)],
limit: 5
query
|> Repo.all()
|> Repo.preload(:users)
end
Please correct me if I'm wrong, but if Elixir's Geo.Point{coordinates: {x, y}, srid: 4326}
builds a Postgis POINT(x, y)
, then %Geo.Point{coordinates: {30, -90}, srid: 4326}
is somewhere in Antarctica. Reversing the coords instead places the point to a more relevant location in New Orleans, America.
I mention this because there aren't actually any docs that formally state the order of the axis, so the easiest thing for me was to quickly google the example point and decipher the order based on the relevance of Antarctica versus New Orleans. Of course that's a pretty unreliable method on my part! In hindsight it seems obvious that Geo.Point
would just defer to Postgis's native ordering, so if I'm right would it be good to note that in the README and reverse the example point?
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.
Added in .ex file.
Postgrex.Types.define(
Core.PostgresTypes,
[Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
json: Jason
)
Model: i have this field
field :location, Geo.PostGIS.Geometry
Migrations:
add :location, :geometry
Postgis extension created:
CREATE EXTENSION IF NOT EXISTS postgis;
config:
types: Core.PostgresTypes,
On my mac its working fine. but On live server(ubuntu) not working.
On mac:
postgis version: 2.4.4
postgresql version: 11.5
Live server:
postgis version: 2.5.2
postgresql version: 11.5
can anyone let me know what is missing, why it is not working on live server.
Hello,
I noticed there is a broken link in README.md
to https://hexdocs.pm/ecto/Ecto.Adapters.Postgres.html#module-extensions
Also wondering if this project is compatible with Ecto 3 or not. Some clarification in the documentation would be really useful. Looking at #15 I note failures, however not entirely convinced if this is an Ecto 3 compatible issue or not.
Thanks
Is there a better solution for this? I just had the `Jason.Encoder pipe to Poison, because I couldn't figure out how to get it to work otherwise. Here is my code:
lib/app_types.ex
Postgrex.Types.define(MyAppName.PostgresTypes,
[Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
json: Jason)
defimpl Jason.Encoder, for: [Geo.MultiPolygon] do
def encode(struct, opts) do
Geo.JSON.encode!(struct) |> Poison.encode!
end
end
config/config.exs
...
config :geo_postgis, json_library: Jason
...
config/dev.exs
config :my_app_name, MyAppName.Repo,
username: "cj",
#password: "postgres",
database: "my_app_name_development",
hostname: "localhost",
show_sensitive_data_on_connection_error: true,
pool_size: 10,
types: MyAppName.PostgresTypes
lib/my_app_name/geo/fence.ex
defmodule MyAppName.Geo.Fence do
use Ecto.Schema
import Ecto.Changeset
@derive {Jason.Encoder, only: [:geom]}
schema "fences" do
field :friendly_name, :string
field :market_type, :string
field :name, :string
field :source_id, :string
field :state, :string
field :geoid, :string
field :code, :string
field :geom, Geo.PostGIS.Geometry
timestamps()
end
@doc false
def changeset(fence, attrs) do
fence
|> cast(attrs, [:name, :source_id, :market_type, :friendly_name, :state])
|> validate_required([:name])
end
end
Something similar in how Plug has the MIME module. Would need a source of srids with their names. We can then make it so we make the module with needed implementations at compile time
I am upgrading Elixir/Phoenix/Ecto and as a result geo_postgis
and geo
, but now I'm getting errors with the schema fields that were using the Geo
types (like Geo.Point
).
** (ArgumentError) invalid or unknown type Geo.Point for field :geocoords
I see that the ecto types were originally in the geo
library and they've been moved to geo_postgis
, but from my understanding it should still work the same on the surface?
Huge fan of the work you've done here :) and I see on main that the latest commit is "prepare for release". I've upgrade to elixir 1.15.2 and noticed I had to turn on warnings in the short term because of the current stable release so I was curious if you might have time this weekend to release the fix I see already out.
Thanks again for all that you do to maintain this library!
I have a query in my app that looks like this
def search_beacons(%{latitude: lat, longitude: lng, range: range}) do
centerpoint = %Geo.Point{coordinates: {lng, lat}, srid: 4326}
from(b in OverallBeacon)
|> where([b], b.is_expired == false)
|> where([b], st_dwithin_in_meters(b.location, ^centerpoint, ^range))
end
when I run repo.all() over this, I get an empty list. however if I run the query directly
select * from overall_beacons b
where b.is_expired = false
and ST_DWithin(b.location, 'SRID=4326;POINT(-122.416 37.779)', 0.2)
I get several results.
I ran logged the output query before being run into ecto
{"SELECT o0.\"id\", o0.\"auto\", o0.\"batch_id\", o0.\"is_expired\", o0.\"personal\", o0.\"property\", o0.\"social\", o0.\"location\", o0.\"inserted_at\", o0.\"updated_at\" FROM \"overall_beacons\" AS o0 WHERE (o0.\"is_expired\" = FALSE) AND (ST_DWithin(o0.\"location\"::geography, $1::geography, $2))",
[%Geo.Point{coordinates: {-122.416, 37.779}, properties: %{}, srid: 4326}, 500]}
here's an example record that comes up when I run the query directly using navicat
id auto property personal batch_id location is_expired inserted_at updated_at social
946012e5-958f-417c-a347-f551e52d8286 55 22 0 87b4db24-5a6f-11e9-9d20-0a0d335f0b74 0101000020E6100000F4FDD478E9925EC0F853E3A59BEC4240 f 2019-04-09 02:31:07 2019-04-09 02:31:07 0
I am using geo_postgis 3.1
I receive the following error after following the installation guide for Ecto.
[error] Postgrex.Protocol (#PID<0.1139.0>) disconnected: ** (Postgrex.QueryError) type `_geometry` can not be handled by the types module GI.PostgresTypes
[info] Sent 500 in 21ms
[error] #PID<0.1401.0> running GIWeb.Endpoint (connection #PID<0.1386.0>, stream id 4) terminated
Server: localhost:4000 (http)
Request: GET /utilities/power
** (exit) an exception was raised:
** (Postgrex.QueryError) type `_geometry` can not be handled by the types module GI.PostgresTypes
(ecto_sql 3.4.5) lib/ecto/adapters/sql.ex:593: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto_sql 3.4.5) lib/ecto/adapters/sql.ex:526: Ecto.Adapters.SQL.execute/5
(ecto 3.4.6) lib/ecto/repo/queryable.ex:192: Ecto.Repo.Queryable.execute/4
(ecto 3.4.6) lib/ecto/repo/queryable.ex:17: Ecto.Repo.Queryable.all/3
(elixir 1.11.1) lib/enum.ex:1399: Enum."-map/2-lists^map/1-0-"/2
.....
Postgrex.Types.define(
GI.PostgresTypes,
[Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
json: Jason
)
config :gi, GI.Repo,
types: GI.PostgresTypes
Not sure why it's trying to use _geometry, and not geometry.
Changing lib/geo_postgis/extension.ex to
def matching(_) do
[type: "geometry", type: "geography", type: "_geometry"]
end
Seems to fix the error.
Getting a new error while testing this library on elixir 1.15.0-rc.0
warning: bitstring specifier "int32" does not exist and is being expanded to "int32()", please use parentheses to remove the ambiguity
(<redacted>) <redacted>/deps/geo_postgis/lib/geo_postgis/extension.ex:77: <REDACTED>.PostgresTypes."Elixir.Geo.PostGIS.Extension"/1
warning: bitstring specifier "int32" does not exist and is being expanded to "int32()", please use parentheses to remove the ambiguity
(<redacted>) <redacted>/deps/geo_postgis/lib/geo_postgis/extension.ex:90: <REDACTED>.PostgresTypes."Elixir.Geo.PostGIS.Extension"/6
warning: bitstring specifier "int32" does not exist and is being expanded to "int32()", please use parentheses to remove the ambiguity
(<redacted>) <redacted>/deps/geo_postgis/lib/geo_postgis/extension.ex:90: <REDACTED>.PostgresTypes."Elixir.Geo.PostGIS.Extension"/2
warning: bitstring specifier "int32" does not exist and is being expanded to "int32()", please use parentheses to remove the ambiguity
(<redacted>) <redacted>/deps/geo_postgis/lib/geo_postgis/extension.ex:90: <REDACTED>.PostgresTypes."Elixir.Geo.PostGIS.Extension"/3
warning: bitstring specifier "int32" does not exist and is being expanded to "int32()", please use parentheses to remove the ambiguity
(<redacted>) <redacted>/deps/geo_postgis/lib/geo_postgis/extension.ex:90: <REDACTED>.PostgresTypes."Elixir.Geo.PostGIS.Extension"/5
I assume that needs to be replaced with integer-size(32)
or follow the warning's advice, but based off the docs: https://hexdocs.pm/elixir/1.14/Kernel.SpecialForms.html#%3C%3C%3E%3E/1-unit-and-size (yes I know that this is 1.14, 1.15 isn't officially released as of this writing)
There is no such thing as int32
as far as bitstring types are concerned
EDIT: In the process of correcting it on local, it appears postgrex used to reference int32 as well, so it may have been a type present in older elixir versions, I don't feel like chasing that down right now however.
Hi!
I saw that there's no support for passing the use_spheroid
parameter in queries.
Maybe we could add it by doing something like this?
defmacro st_dwithin(geometryA, geometryB, float) do
quote do:
fragment("ST_DWithin(?,?,?)", unquote(geometryA), unquote(geometryB), unquote(float))
end
defmacro st_dwithin(geographyA, geographyB, float, use_spheroid) do
quote do:
fragment("ST_DWithin(?,?,?,?)", unquote(geographyA), unquote(geographyB), unquote(float), unquote(use_spheroid))
end
What do you think?
Thanks for the awesome work, by the way!
Getting (but only on my server, not locally)
** (RuntimeError) type `geometry` can not be handled by the types module Ecto.Adapters.Postgres.TypeModule
(ecto) lib/ecto/adapters/postgres/connection.ex:79: Ecto.Adapters.Postgres.Connection.prepare_execute/5
(ecto) lib/ecto/adapters/sql.ex:256: Ecto.Adapters.SQL.sql_call/6
(ecto) lib/ecto/adapters/sql.ex:426: Ecto.Adapters.SQL.execute_and_cache/7
(ecto) lib/ecto/repo/queryable.ex:133: Ecto.Repo.Queryable.execute/5
(ecto) lib/ecto/repo/queryable.ex:37: Ecto.Repo.Queryable.all/4
(ecto) lib/ecto/repo/queryable.ex:70: Ecto.Repo.Queryable.one/4
(come_bike) lib/come_bike/events/search.ex:11: ComeBike.Search.find_by_zip_in_n_miles/1
(come_bike) lib/come_bike/events/events.ex:83: ComeBike.Events.search_rides/1
The app in question can be viewed here. https://github.com/ComeBike/come.bike
I also included links to the files relative to each area.
The issue I'm running into is only an issue on my server, locally I dont have this issue.
Working with:
mix lock
https://github.com/ComeBike/come.bike/blob/master/mix.lock
"geo": {:hex, :geo, "2.1.0", "f9a7a1403dde669c4e3f1885aeb4f3b3fb4e51cd28ada6d9f97463e5da65c04a", [:mix], [{:ecto, "~> 2.1", [hex: :ecto, repo: "hexpm", optional: true]}, {:poison, "~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"},
"geo_postgis": {:hex, :geo_postgis, "1.1.0", "4c9efc082a8b625c335967fec9f5671c2bc8a0a686f9c5130445ebbcca989740", [:mix], [{:geo, "~> 2.0", [hex: :geo, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm"},
"ecto": {:hex, :ecto, "2.2.8", "a4463c0928b970f2cee722cd29aaac154e866a15882c5737e0038bbfcf03ec2c", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
postgres_types.ex
https://github.com/ComeBike/come.bike/blob/master/lib/come_bike/postgres_types.ex
Postgrex.Types.define(
ComeBike.PostgresTypes,
[Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(),
json: Poison
)
Zips model
https://github.com/ComeBike/come.bike/blob/master/lib/come_bike/events/zip.ex
field(:geom, Geo.Point)
defmodule ComeBike.Repo.Migrations.AddGeomToZips do
use Ecto.Migration
def change do
alter table("zips") do
add(:geom, :geometry)
end
create(index("zips", [:geom]))
end
end
Thoughts?
Application.get_env has been softly deprecated (in module body) starting with Elixir 1.14. Still just a warning, but causes issues with "compile without warnings"
Recommend updating 'geo' version to 3.6 as it changes get_env calls to compile_env.
Tested geo update locally. Compiles and tests pass.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.