-
Notifications
You must be signed in to change notification settings - Fork 67
Add geometry types #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
hi! are there any plans to support this? because the mysql driver is now deprecated but we can't upgrade to myxql without geometry support :/ |
Yes, we definitely want to have it before v1.0. It’s valuable feedback that it’s a blocker for you, in that case it’s definitely higher priority for us. It’d be great if community stepped in to implement this feature so PRs are definitely welcome.
|
alright this is welcome news! thanks! |
@wojtekmach @byronpc I started on this to give it a go. If anyone is interested in collaborating, please let me know. My progress will be slow, but hey, yesterday I managed to parse a Point! |
@jeroenbourgois I would love to contribute can you share your fork lets work on that fork :) |
@m13m great news! I will give you access to the repo. I will also open a ticket to discuss next steps, so we do not get in each others way :) |
@jeroenbourgois Thanks for the invite. |
@wojtekmach @byronpc tiny update from our side: we can already parse something. This is the output from
But when actually using it inside our app, there is a problem decoding other fields, which is strange and we have not found the root cause yet. Progress is slow because everything is quite new for us. We think in the decoding part of the geometry structures, we are doing something to disturb the rest bits, which then, of course, causes issues further down the road. Any help is still very welcome :) |
If you have a script (or ideally an integration test) I could run in your fork I'm happy to take a look.
yeah that might be it that you read too few or too many bits. I believe geometry types are encoded as You probably have something like this already, but what I'd try is
|
@jeroenbourgois I pushed a branch where I was able to do some basic decoding for POINT and MULTIPOINT for the binary protocol: d0771b8 hope that helps. We can probably learn a lot from https://github.com/xerions/mariaex/pull/191/files too. To really push this forward I think it would be extremely helpful to find the specification (if one exists) how exactly mysql represents geometry types on the wire instead of trying to reverse engineer it. If there's no such specification perhaps we could use some existing implementation as a reference. |
Btw, I found out there's a geo [1] package (used by e.g. geo_postgis [2] for Postgrex) which is interesting. It's too early to make a decision on this but something to have in mind is potentially using this package (fortunately it has 0 deps) so that we use the same structs and thus provide interoperability. [1] https://hex.pm/packages/geo |
I've updated the branch with encoding support: https://github.com/elixir-ecto/myxql/compare/wm-geometry |
@wojtekmach thanks! I checked out the branch you created, good work. As for decoding, for point and polygon we are pretty solid, I think we figured out the same things you did about the srid, the endianness and so on. Maybe it's a good idea to work on the fork too? We added the geom structs there already, and some decode functions, it is rather confusing having multiple implementations to look at.
UPDATE: sorry, I see you also saw that header thing, you handled it with the Or otherwise, if you prefer to work on this branch, on this repo, maybe you can add me as contributor? I just think it might be favorable to both work on the same code, since I have a lot to learn and it is not that easy to mix and match and understand everything that is going on :P More work will be for next week. Thanks already. |
You mentioned you saw the header in geo and other libs - could you send links to relevant pieces of code? If your fork is public can you send a link too? the Yup, feel free to continue working on this on the fork but I’d appreciate a PR upstream when you’re done :) |
https://github.com/jackjoe/myxql I found out how the length-encoded integers work thanks to the MySQL docs, I never heard of it. Did not know it was for strings as wel. But what really interests me is what the value inside that ‘header’ represents. Now we just shave it off. I will look up the libs and mention them here. On the road now. |
@jeroenbourgois I think I got it, still don't know where the <<0, 0, 0, 0>> in front comes from (maybe srid?) but the Geo library handles decoding of the rest of the packet very well. I've updated the branch. You should be able to easily handle polygons and multi polygons there, let me know! |
@wojtekmach pure awesome 😎 I pulled you branch in our fork, I will add a couple of more tests and update the docs regarding the geo dep. In an actual app (using Phoenix/Ecto) it does require to have some setup with also the geo dep, and a custom Ecto type. Not too hard, but where could I put that information? Maybe this readme is not the best place, but there could be a page in the docs? I will submit the PR from the updated |
Thanks @jeroenbourgois sounds good!
We could make Regarding a custom Ecto type, I'm a bit torn because on one hand myxql is completely independent from Ecto, but on the other hand it seems practical to put this information here. The only other place I could think would be this: https://hexdocs.pm/ecto_sql/Ecto.Adapters.MyXQL.html. Btw, custom ecto type isn't required, this should work out of the box: # migration.exs
add :point, :point
# schema.ex
field :point, :map
# code
Repo.insert!(%User{point: %Geo.Point{coordinates: {1, 1}}}) but with this we can't really handle user input. In your application, how are you getting the data into the system by the users? |
@wojtekmach well, users are able to create polygons and put points on the map client side, with javascript, and we then send a comma separated string of {x,y} coords to the server. There it is parsed to a struct (using the custom ecto type, the But it is good to know it can be done without too. |
Right, so there are different ways of accepting user input, the one you described, the GeoJSON approach that geo_postgis uses, I could imagine someone using WKT representation too. For this reason, I think I lean towards not elaborating much on ecto type in myxql docs, maybe just dropping a link to https://hexdocs.pm/ecto/Ecto.Type.html <https://hexdocs.pm/ecto/Ecto.Type.html> and that’s it. What do you think? Nothing to worry about right now, we’ll figure it out on the PR. :)
|
@wojtekmach ok, I just submitted the PR (#88) If more work is needed, let us know. |
Closing in favour of the PR! |
No description provided.
The text was updated successfully, but these errors were encountered: