From kyusik at gmail.com Sat Mar 8 07:34:05 2008 From: kyusik at gmail.com (Kyusik Chung) Date: Sat, 8 Mar 2008 07:34:05 -0500 Subject: [Georuby-devel] Can't load Polygon data into mysql using a fixture Message-ID: 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/georuby-devel/attachments/20080308/4a87ebaa/attachment-0001.html From guilhem.vellut at gmail.com Sat Mar 8 13:59:07 2008 From: guilhem.vellut at gmail.com (Guilhem Vellut) Date: Sat, 8 Mar 2008 19:59:07 +0100 Subject: [Georuby-devel] Can't load Polygon data into mysql using a fixture In-Reply-To: References: Message-ID: <43f4b6ee0803081059p4b62a16eqf421fbe6fd45b4c9@mail.gmail.com> 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 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 > From jay at zoocasa.com Wed Mar 19 12:35:13 2008 From: jay at zoocasa.com (J Smith) Date: Wed, 19 Mar 2008 12:35:13 -0400 Subject: [Georuby-devel] Spatial adapter and PostgreSQL views Message-ID: <200803191235.13283.jay@zoocasa.com> Hello list. I recently ran into a problem (which I guess is kind of both a Rails problem as well as a spatial adapter problem) where I was unable to get the proper geometry column information for a geometry field in a PostgreSQL view. After hacking ActiveRecord's PostgreSQLAdapter to recognize views properly, I ended up hacking at the PostgreSQLAdapter extensions in GeoRuby to grab the geometry field information from the geometry_columns table rather than pg_constraints. This of course required that I make an entry in the geometry_columns table for my view, which may or may not be considered "proper", but when all is said and done, it works. I don't know if this is all that useful, but I figured I'd send along the patch anyway. Cheers, and thanks for GeoRuby, it's been quite useful on our little venture here. J -------------- next part -------------- A non-text attachment was scrubbed... Name: post_gis_adapter.rb.patch Type: text/x-diff Size: 2959 bytes Desc: not available Url : http://rubyforge.org/pipermail/georuby-devel/attachments/20080319/72db9ad9/attachment.bin From guilhem.vellut at gmail.com Fri Mar 21 04:56:01 2008 From: guilhem.vellut at gmail.com (Guilhem Vellut) Date: Fri, 21 Mar 2008 09:56:01 +0100 Subject: [Georuby-devel] Spatial adapter and PostgreSQL views In-Reply-To: <200803191235.13283.jay@zoocasa.com> References: <200803191235.13283.jay@zoocasa.com> Message-ID: <43f4b6ee0803210156o54806297vfbbf99fa6b8ea027@mail.gmail.com> hello, thanks for the patch. I will apply it as soon as possible. guilhem On Wed, Mar 19, 2008 at 5:35 PM, J Smith wrote: > > Hello list. > > I recently ran into a problem (which I guess is kind of both a Rails problem > as well as a spatial adapter problem) where I was unable to get the proper > geometry column information for a geometry field in a PostgreSQL view. > > After hacking ActiveRecord's PostgreSQLAdapter to recognize views properly, I > ended up hacking at the PostgreSQLAdapter extensions in GeoRuby to grab the > geometry field information from the geometry_columns table rather than > pg_constraints. This of course required that I make an entry in the > geometry_columns table for my view, which may or may not be > considered "proper", but when all is said and done, it works. > > I don't know if this is all that useful, but I figured I'd send along the > patch anyway. > > Cheers, and thanks for GeoRuby, it's been quite useful on our little venture > here. > > J > > _______________________________________________ > Georuby-devel mailing list > Georuby-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/georuby-devel >