[Georuby-devel] Can't load Polygon data into mysql using a fixture

Guilhem Vellut guilhem.vellut at gmail.com
Sat Mar 8 13:59:07 EST 2008


Hello,
Thanks for the report. The answer to the csv error report is quick :
csv fixtures are not supported
by the spatial adapter (if there is a way to encode binary data in csv
fixtures, support could
 be added ; I actually don't know if there is : I will look it up).
For the error in the YAML fixture, it is a bug caused by the fact the
.pack("m")
call used in the MySQL spatial adaper to_fixture_format to encode the
WKB of the geometry
to base64 (to input binary data in a yaml field)
seems to split the binary content in 60-character lines which is a
problem for the YAML parser. I have
added the deletion of these new lines to the current SVN revision and
long geometries like yours should be ok now.
guilhem


On Sat, Mar 8, 2008 at 1:34 PM, Kyusik Chung <kyusik at gmail.com> wrote:
> Hello,
>
> I am having trouble trying to load data into a table that has a polygon
> field.
>
> I am using the Spatial Adapter and mysql (5.0.45), and I have followed the
> documentation on how to use fixtures.  The Polygon.from_coordinates method
> seems to generate a polygon, but it fails to load into the db when I run
> rake db:migrate.  I have tried both yml as well as csv and get 2 different
> errors.
>
> Error with yml:
> a YAML error occurred parsing ./db/migrate/data/cities.yml. Please note that
> YAML must be consistently indented using spaces. Tabs are not allowed.
> Please have a look at http://www.yaml.org/faq.html
> The exact error was:
>   ArgumentError: syntax error on line 7, col 0:
> `go5WtSwrQLqEQ29xG2JAVMN+T6wrK0B4YtaLIRtiQI8YPbfQJStA2IFzRhQb'
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/fixtures.rb:308:in
> `read_fixture_files'
> ...
> NOTE: I have *not* used tabs to indent lines - I have used two spaces at the
> front of each line.
>
> Error with csv:
> Mysql::Error: Cannot get geometry object from data you send to the GEOMETRY
> field: INSERT INTO cities (`boundary`, `id`, `total_businesses`,
> `city_name`, `state`) VALUES ('!binary |
> /////wEDAAAAAQAAACAAAAD7zFmfchtiQE7QJodPMitABWoxeJgbYkC/YaJB', 3153, 0,
> 'Finegayan Station', 'GU')
> /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/connection_adapters/abstract_adapter.rb:128:in
> `log'
> ...
>
> Here is what my yml looks like:
>
>
> one:
>   id:                   3153
>   city_name:            Finegayan Station
>   state:                GU
>   total_businesses:     0
>   boundary:             <%=
> Polygon.from_coordinates([[[144.857742,13.598263],[144.862362,13.589922],[144.865169,13.587336],[144.862927,13.587665],[144.861292,13.587321],[144.857597,13.585299],[144.847845,13.573858],[144.846225,13.571014],[144.843605,13.566047],[144.842157,13.563831],[144.841202,13.561991],[144.838305,13.556465],[144.834645,13.549919],[144.834352,13.549395],[144.833825,13.548454],[144.831839,13.544451],[144.830845,13.54081],[144.821543,13.545695],[144.8097993,13.55186285],[144.814753,13.55755],[144.816744,13.56176944],[144.818862,13.566258],[144.819402,13.568565],[144.822373,13.572223],[144.8242032,13.57381149],[144.82634,13.575666],[144.83416,13.590365],[144.83514,13.595657],[144.834284,13.59652],[144.834024,13.598031],[144.83719,13.598061],[144.857742,13.598263]]]).to_fixture_format
> %>
>
>
> Here is what my csv looks like:
>
> id,city_name,state,total_businesses,boundary
> 3153,"Finegayan Station","GU",0,<%=
> Polygon.from_coordinates([[[144.857742,13.598263],[144.862362,13.589922],[144.865169,13.587336],[144.862927,13.587665],[144.861292,13.587321],[144.857597,13.585299],[144.847845,13.573858],[144.846225,13.571014],[144.843605,13.566047],[144.842157,13.563831],[144.841202,13.561991],[144.838305,13.556465],[144.834645,13.549919],[144.834352,13.549395],[144.833825,13.548454],[144.831839,13.544451],[144.830845,13.54081],[144.821543,13.545695],[144.8097993,13.55186285],[144.814753,13.55755],[144.816744,13.56176944],[144.818862,13.566258],[144.819402,13.568565],[144.822373,13.572223],[144.8242032,13.57381149],[144.82634,13.575666],[144.83416,13.590365],[144.83514,13.595657],[144.834284,13.59652],[144.834024,13.598031],[144.83719,13.598061],[144.857742,13.598263]]]).to_fixture_format
> %>
>
>
> If anyone can shed some light, Id greatly appreciate it.
>
> Thanks
>
>
>
> Kyusik
>
> _______________________________________________
>  Georuby-devel mailing list
>  Georuby-devel at rubyforge.org
>  http://rubyforge.org/mailman/listinfo/georuby-devel
>


More information about the Georuby-devel mailing list