[Georuby-devel] MySQL Point in unit test

Guilhem Vellut guilhem.vellut at gmail.com
Thu May 11 12:25:56 EDT 2006

I have read part of the YAML documentation. There is a !binary instruction to input binary data (http://yaml.org/type/binary.html). It must be followed with the binary data encoded in base64.

So here is what I did:


geom: <%= "!binary #{ [ (255.chr * 4) + Point.from_x_y(123.123,2345.65).as_wkb].pack('m') }" %>


The .pack(‘m’) is to instruct to encode in base64.


If you could confirm that it works for you too, I will add a method which directly outputs this in the mysql adapter.









From: Wayne Kao [mailto:wayne at waynekao.com] 
Sent: 11 May 2006 20:11
To: 'Guilhem Vellut'; georuby-devel at rubyforge.org
Subject: RE: [Georuby-devel] MySQL Point in unit test


Thanks for the suggestion, but that didn’t work, unfortunately, since it prints out a bunch of non-visible characters (code 255 for instance) that MySQL doesn’t like.  E.g.


INSERT INTO blah ('    ☺☺', ‘1’, '2002-12-30', '2002-12-30');

ActiveRecord::StatementInvalid: Mysql::Error: #22003Cannot get geometry object from data you send to the GEOMETRY field


Is that what it’s supposed to look like?


The GeomFromText method seems to be the only way I can reliably get data in, but YML’s quoting makes using that impossible.





From: Guilhem Vellut [mailto:guilhem.vellut at gmail.com] 
Sent: Thursday, May 11, 2006 3:14 AM
To: 'Wayne Kao'; georuby-devel at rubyforge.org
Subject: RE: [Georuby-devel] MySQL Point in unit test


This would indeed be devastating.

You can try to use the MySQL canonical form for geometries. It works when you try to insert a string in this form in a geometric column. 

The canonical form is as follows: 4 characters of code 255 followed by the strict WKB form of the geometry.

In the context of your test, you could do:


Id: 1

 Some_point: <%=  (255.chr * 4) + Geometry.from_ewkt( “POINT(0 0)”).as_wkb %>


Note that I haven’t tried myself yet. If it works, I will update the adapter tonight with a method which can do it for you. In the meantime, you will have to do it manually.





From: georuby-devel-bounces at rubyforge.org [mailto:georuby-devel-bounces at rubyforge.org] On Behalf Of Wayne Kao
Sent: 11 May 2006 13:15
To: georuby-devel at rubyforge.org
Subject: [Georuby-devel] MySQL Point in unit test


Is there a way to express a MySQL Point in Rails YML for a model unit test?


I’ve been trying something like this but it doesn’t work since it becomes quoted and turns into 'GeomFromText(\'POINT(0 0)\')'



  id: 1

  some_point: GeomFromText('POINT(0 0)')

  created_on: 2002-12-30

  updated_on: 2002-12-30


I can’t make it NULL either since MySQL enforces that geospatial columns be non-NULL.  So unless someone has an idea, my only option would be to not have a unit test for this model, which would be devastating.





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/georuby-devel/attachments/20060511/e11eead9/attachment-0001.htm 

More information about the Georuby-devel mailing list