jeroenbourgois

jeroenbourgois

Erlang bit syntax help for myxql geo support

For a project we work on we need geo support in myxql. Instead of waiting and complaining why it is not there, we decided to step in and try to add it. Having little to no understanding of bit syntax, this has already been quite a journey for me. I started out with the Mariaex code as a basis, got into the MySQL and PostGIS documenation, and with a lot of trial and error, now already able to parse a Point and a Polygon. The big goal for our own project is to get MultiPolygon support.

I am trying to figure out this line, that concerns itself with parsing the rings inside a polygon, more specifically the value of the ‘points’ variable, how I should interpret the ‘binary-size’ and ‘unit’ keywords. The actual value is the amount of points inside a polygon. It is needed to extract the correct amount of bits from the binary. I am trying to decode a MultiPolygon and used this as a reference:

<<num_points::32-little, points::binary-size(num_points)-unit(128), rest::bits>>

I found some IBM documentation as well to explain the 32 bit ‘num_points’:

wkbMultiPolygon {
  byte              byteOrder;
  uint32            wkbType;     // 6=wkbMultiPolygon
  uint32            num_wkbPolygons;
  WKBPolygon        wkbPolygons[num_wkbPolygons];
};

In order to decode the multipolygon, I guess I also have to read out the ‘num polygons’ from the binary. Getting hold of the amount of polygons works, but the next step is thus unclear, knowing how far to read.

Other documenation about the actual internal bit format is hard to find so it seems. Any help is appreciated!

PS: if you are interested and have knack for bit syntax stuff, feel free to join the fork! We already have one volunteer which is great!

Marked As Solved

jeroenbourgois

jeroenbourgois

@OvermindDL1 thanks to work from our side and @wojtekmach we managed to land a version of myxql with geo support. Just wanted to let you and the topic know :slight_smile:

Also Liked

OvermindDL1

OvermindDL1

binary means that points will be a binary, size(...) means that the binary will have the size of num_points worth of bytes (8-bits) (where num_points was parsed previously as a 32-bit integer of little-endian order), and the unit(...) will redefine the unit size of size(...) to instead of being 8-bits will instead be 128-bits, so points will be a binary of num_points amount of points where each point is 128 bits in size (maybe some other internal structure?). The rest is just whatever’s left over unparsed as a bitstring.

For note, all documented at: Kernel.SpecialForms — Elixir v1.16.0

jeroenbourgois

jeroenbourgois

Thanks, this already helps! The 128 bits will be the size of one point, which is {x,y} where each element is a 64-bit float. Thanks to point to the docs too.

I will ping the topic once we get further.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New

We're in Beta

About us Mission Statement