[Georuby-devel] MySQL Point in unit test
Wayne Kao
wayne at waynekao.com
Thu May 11 12:51:57 EDT 2006
Works great! I haven’t checked whether the point in the DB is actually 123.123, 2345.65, but my unit test passes now.
Thanks!
--Wayne
_____
From: Guilhem Vellut [mailto:guilhem.vellut at gmail.com]
Sent: Thursday, May 11, 2006 9:26 AM
To: 'Wayne Kao'; georuby-devel at rubyforge.org
Subject: RE: [Georuby-devel] MySQL Point in unit test
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.
guilhem
_____
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.
--Wayne
_____
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:
Wayne_user_profile:
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.
guilhem
_____
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)\')'
wayne_user_profile:
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.
Thanks,
--Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/georuby-devel/attachments/20060511/460f00ee/attachment.htm
More information about the Georuby-devel
mailing list