0

I am trying to insert simple geometry data in mysql database but I am getting some weird symbols instead of numbers in the rows. Does anyone know why?

This is the query that I am running:

SET @g = 'LINESTRING(0 0,1 1,2 2)';
INSERT INTO geom (g) VALUES (GeomFromText(@g));

Thanks!

Moki
  • 199
  • 1
  • 4
  • 15
  • I believe you need to call GeomFromText on each point `Point` of your `LINESTRING`. I haven't played a lot with these functions and I find these a bit of wierd, as you cannot just declare a POINT and use it normally, but some casts like `GeomFromText` are required. – Rolice Aug 07 '14 at 18:13
  • I tried to call GeomFromText also for point creation like this INSERT INTO geom (g) VALUES (GeomFromText('POINT(1 1)'));, but the result is the same. Just simbols without the coordinates. – Moki Aug 07 '14 at 18:22
  • I find solution for my problems like (adapted to yours): `Something like: INSERT INTO geom (g) VALUES(LINESTRING( GeomFromText( astext( POINT(0, 0) ) ), GeomFromText( astext( POINT(1, 1) ) ), GeomFromText( astext( POINT(2, 2) ) ) ) )` – Rolice Aug 07 '14 at 18:24
  • Thanks for your proposal. It is the same situation. I will continue to dig into this problem. – Moki Aug 07 '14 at 18:40
  • Yep, no problem, I spent a lot of time to get solution to my problems. Try GeomFromString(astext(...)) on the whole LINESTRING as well or the same you use but with `POINT(0,0)` instead of `0 0`, `POINT(1,1)`, instead of `1 1`, etc. I don't think `0 0` is interpreted correctly if left like that. – Rolice Aug 07 '14 at 18:48
  • By the way, what do you think about professional usage of mysql for spatial data? – Moki Aug 07 '14 at 19:01
  • It is fine to use it, but as far as I know it lacks a lot of features that are of common use, except you add them by yourself (you can install some extensions to MySQL). For example, I had to write my own distance calculation function to achieve correct result as GLENGTH works assuming that coordinates are in plane (planar projection), but not a sphere or any close to earth shape like geoid. Here is something related http://www.mysqlperformanceblog.com/2013/10/21/using-the-new-spatial-functions-in-mysql-5-6-for-geo-enabled-applications/ I think PostgreSQL is far ahead of MySQL (not only this) – Rolice Aug 07 '14 at 19:09

0 Answers0