Giter Site home page Giter Site logo

spatial_adapter's Introduction

Spatial Adapter for ActiveRecord

This is the Spatial Adapter for ActiveRecord. It enhances ActiveRecord to handle spatial datatypes in the following databases:

  • PostgreSQL (using PostGIS)

  • MySQL (using Spatial Extensions)

Dependencies

The following gems are required:

  • GeoRuby

  • ActiveRecord (version 2.2.2 and up)

For PostgreSQL:

  • PostGIS version 1.4.0 or higher should be installed in your database

Installation

Choose ONE of the following installation methods. You shouldn’t have to do both.

From RubyGems

This is the preferred method of installation, and will pull in the required dependencies as well.

gem install spatial_adapter

In a Rails 2.x app, you can add a gem dependency in environment.rb:

config.gem 'spatial_adapter'

In a Rails 3 app, add a gem dependency to Gemfile:

gem 'spatial_adapter'

As a Rails Plugin

In your Rails project, run the following:

script/plugin install git://github.com/fragility/spatial_adapter.git

You need to have Git installed first.

Configuration

Choose the database type for which you would like to use spatial_adapter, and load each with

require 'spatial_adapter/[database]'

where [database] should be replaced with one of the following:

  • postgresql

  • mysql

  • mysql2

  • jdbcmysql

For example to use the PostgreSQL spatial adapter:

require 'spatial_adapter/postgresql'

In a Rails app, spatial_adapter will automatically load the adapter for the database specified in your database.yml configuration.

Operations

Geometric columns in your ActiveRecord models now appear just like any other column of other basic data types. They can also be dumped in ruby schema mode and loaded in migrations the same way as columns of basic types.

Migrations

Here is an example of code for the creation of a table with a geometric column in PostGIS, along with the addition of a spatial index on the column:

ActiveRecord::Schema.define do
  create_table :table_points, :force => true do |t|
    t.string :data
    t.point :geom, :null => false, :srid => 123, :with_z => true
  end
  add_index :table_points, :geom, :spatial => true
end

Here is a related statement valid for MySql version <= 5.0.16:

ActiveRecord::Schema.define do
  create_table "table_points", ;options=>"ENGINE=MyISAM", :force => true do |t|
    t.string :data
    t.point :geom, :null => false
  end
  add_index :table_points, :geom, :spatial => true
end

Differences Between Databases

  • On all versions of MySQL, the :srid, :with_z, and :with_m options are ignored, since they are not supported.

  • On MySQL versions <= 5.0.16, you have to add :options => "ENGINE=MyISAM" to the create_table statement, since only MyISAM tables can have spatial columns. In addition, only MyISAM tables may have spatial indexes.

Models

Create your ActiveRecord models normally. Spatial Adapter will automatically handle spatial columns, converting them to the appropriate GeoRuby type.

class TablePoint < ActiveRecord::Base
end

Access

Here is an example of row creation and access, using the model and the table defined above:

pt = TablePoint.new(
  :data => "Hello!", 
  :geom => Point.from_x_y_z(-1.6, 2.8, -3.4, 123))
pt.save
pt = TablePoint.find_first
puts pt.geom.x #access the geom column like any other

Fixtures

If you use fixtures for your unit tests, at some point, you will want to input a geometry. You could transform your geometries to a form suitable for YAML yourself every time but Spatial Adapter provides a method to do it for you: to_fixture_format. You would use it like this, if the geometric column is a point:

fixture:
  id: 1
  data: HELLO
  geom: <%= Point.from_x_y(123.5,321.9).to_fixture_format %>

Finder Enhancements

Enhancements to find_by_* and friends has been removed from this version of Spatial Adapter until a cleaner implementation can be made. (The previous implementation made adapter-specific modifications to ActiveRecord::Base, which prevented multiple adapters from being loaded at once.)

Geometric data types

Ruby geometric datatypes are currently made available only through the GeoRuby library (georuby.rubyforge.org/): This is where the Point.from_x_y in the example above comes from.

Warning

  • Since ActiveRecord seems to keep only the string values directly returned from the database, it translates from these to the correct types everytime an attribute is read, which is probably ok for simple types, but might be less than efficient for geometries, since the EWKB string has to be parsed everytime. Also it means you cannot modify the geometry object returned from an attribute directly:

    place = Place.find_first
    place.the_geom.y=123456.7 # this doesn't work
    

    Since the translation to a geometry is performed every time the_geom is read, the change to y will not be saved! You would have to do something like this:

    place = Place.find_first
    the_geom = place.the_geom
    the_geom.y=123456.7
    place.the_geom = the_geom
    

License

The Spatial Adapter for ActiveRecord is released under the MIT license.

Latest Changes

Spatial Adapter has been refactored and is now available as a Ruby gem. The dependency on Rails has been removed. Unfortunately, the current version is without some of the previous functionality, until a cleaner implementation is made.

The previous release is available on the “legacy” branch.

Removed Features in 0.2.0

  • Compatibility with ActiveRecord/Rails older than version 2.2.2

  • enhancements to find_by_* for spatial columns

  • to_fixture_format extension to the GeoRuby types

These will hopefully be added back in the near future.

Support

Any questions, enhancement proposals, bug notifications or corrections can be made via the project page at github.com/fragility/spatial_adapter

Running Tests

The gem depdencencies can be installed with ‘bundle install`.

You will need to set up an empty database named ‘spatial_adapter` for each adapter you want to test.

Tests are partitioned by adapter and can be run using separate rake task.

bundle exec rake spec:[adapter]

spatial_adapter's People

Contributors

aubreyinanod avatar codebutler avatar cwise avatar johnsmall avatar panthomakos avatar rjft197 avatar sabman avatar sd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spatial_adapter's Issues

Rails 3.0 compatiblity

The should be fairly self-explanatory. I'm looking to move some projects to Rails 3.0 code base and I guess others are. The ActiveRecord internals have changed significantly since 2.3.

sanitize_sql_hash_for_conditions issue w/ join on 2.3.2

It looks like get_rails2_conditions (called here)
#For Rails >= 2
def self.sanitize_sql_hash_for_conditions(attrs)
conditions = get_rails2_conditions(attrs)
replace_bind_variables(conditions, expand_range_bind_variables(attrs.values))
end
Doesn't fully replicate the 2.3.2 base.rb code in the case where value.is_a?(Hash)

Unfortunately I'm new to rails to haven't yet figured out what aspects are missing, but I get a bind error when doing a join even if the table has no spatial columns (and the error goes away if I comment out overriding sanitize_sql_hash_for_conditions in the spatial_adapter code).

Any help is appreciated.

Conflict with redhillonrails_core schema dumper

The redhillonrails_core plugin uses alias_method_chain to add foreign key indexes to the schema dump. However, these methods fail to get called when spatial_adapter is also installed. I haven't worked out the exact reason but the problem can be avoided if you make sure spatial_adapter is loaded first. One way to do this is to rename it to 0_spatial_adapter.

Improve dependency management by splitting into multiple plugins

Back in the old days (before I was involved) the spatial_adapter was actually two plugins, one for PostgreSQL and one for MySQL. Then it was merged a while before I took over maintenance. However, the merged plugin has some serious dependency problems that cause me to question that decision.

  1. I can't add the necessary gem dependencies (the pg or mysql gems) because few (or none) of the plugin's users will want to install both of them.
  2. Adding more database adapters only makes the problem worse.

Despite a little bit of common code, I'm inclined to split into postgresql_spatial_adapter and mysql_spatial_adapter once more. Suggestions for reducing duplication, or alternate solutions, are welcome.

SQL Syntax error when using YAML fixtures unless srid is present

I have a fixture defined like so:

one:
  long_name: Long Name
  short_name: LN
  bounds: !ruby/object:Polygon
    rings:
    - !ruby/object:LinearRing
      points:
      - !ruby/object:Point {x: 0, y: 0}
      - !ruby/object:Point {x: 20, y: 0}
      - !ruby/object:Point {x: 20, y: 20}
      - !ruby/object:Point {x: 0, y: 20}
      - !ruby/object:Point {x: 0, y: 0}

But trying to use it in a test suite results in the following error:

Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '), 400743110)' at line 1: INSERT INTO `locations` (`long_name`, `short_name`, `bounds`, `id`) VALUES ('Positive Location', 'PL', GeomFromWKB(0x010300000001000000050000000000000000000000000000000000000000000000000034400000000000000000000000000000344000000000000034400000000000000000000000000000344000000000000000000000000000000000,), 400743110)

The key part of the problem is:

GeomFromWKB(0x01030000[...]0000,),

Where there is an extra comma inside the GeomFromWKB function call. Looking through the source, at lib/spatial_adapter/mysql2.rb:20 it looks like if value.srid is nil, then it would cause the erroneous SQL statement to be returned. I'm not sure how or why the srid isn't being set to DEFAULT_SRID when the object is being created, but if I manually set it in the YAML like so:

one:
  long_name: Long Name
  short_name: LN
  bounds: !ruby/object:Polygon
    srid: -1
    rings:
    - !ruby/object:LinearRing
      points:
      - !ruby/object:Point {x: 0, y: 0}
      - !ruby/object:Point {x: 20, y: 0}
      - !ruby/object:Point {x: 20, y: 20}
      - !ruby/object:Point {x: 0, y: 20}
      - !ruby/object:Point {x: 0, y: 0}

Then it works fine. Also, it doesn't need to be set in the child objects, since the GeoRuby srid= method takes care of propagating srid changes down through the tree.

This isn't the end of the world because of the simple workaround, but it does seem to go against the expected behavior.

as_kml can produce google maps unreadable coordinates

..if lan or lon are saved out of the +180.0 and -180.0 degrees boundaries.

I patched it like this:

class GeoRuby::SimpleFeatures::Geometry
alias :old_as_kml :as_kml

fixing google_earth not displaying coordinates properly if out of

-180 <> 180

def as_kml
old_as_kml.gsub(/[-+]?[0-9].?[0-9]/) do |s|
next '' if s.empty?
f = s.to_f
next (f - 360.0).to_s if f > 180.0
next (f + 360.0).to_s if f < -180.0
f.to_s
end
end
end

remove_column in migrations

I'm getting this:

undefined method spatial?' for #<ActiveRecord::ConnectionAdapters::PostgreSQLColumn:0x104c284e0> in .../gems/spatial_adapter-1.1.0/lib/spatial_adapter/postgresql.rb:102:inremove_column'

when I try to remove a column in a migration under spatial_adapter 1.1.1:

remove_column :people, :website_one

Specifically, I was running rake db:migrate:redo at the time.

I also get this error under spatial_adapter 1.1.0.
Under spatial_adapter 1.0.0, the migration runs fine.

This is on Rails 2.3.5 with PostgreSQL & PostGIS 1.5.0, and GeoRuby 1.3.4.

Is there any additional info I can send along to help diagnose or fix this?

gemspec disallows ActiveRecord v3.1.0

The docs say that spatial_adapter supports ActiveRecord v2.2 and higher, but the spatial_adapter.gemspec also prohibits 3.1.0 and higher ('activerecord', '>= 2.2.2', '< 3.1.0'). I'll clone and modify the version to see if anything breaks under 3.1. Just wanted to first ask if this might be as simple as updating the gemspec or if there's known issues with the spatial_adapter and AR 3.1.0?

Thanks,
Andrew

Geom field not converted to hex_ewkb when using Model.create in Rails 3.1.0

Creating a new record using

Foo.create(:geom => Point.from_x_y_z(-1.6, 2.8, -3.4, 4326))

Doesn't work, but this does:

f = Foo.create
f.geom = Point.from_x_y_z(-1.6, 2.8, -3.4, 4326)
f.save

With some debugging it appears that the PostgreSQLAdapter#quote method inside lib/spatial_adapter/postgresql.rb wasn't hit when using 'create', but was when updating. This was true even for non-geom fields.

Here is the output using the example provided in the README:

>> pt = TablePoint.new(
?>   :data => "Hello!", 
?>   :geom => Point.from_x_y_z(-1.6, 2.8, -3.4, 123))
   (0.5ms)  SELECT * FROM geometry_columns WHERE f_table_name = 'table_points'
=> #<TablePoint id: nil, data: "Hello!", geom: #<GeoRuby::SimpleFeatures::Point:0x104d5c988 @m=0.0, @x=-1.6, @with_m=false, @z=-3.4, @with_z=true, @srid=123, @y=2.8>>
>> pt.save
   (0.1ms)  BEGIN
  SQL (1.2ms)  INSERT INTO "table_points" ("data", "geom") VALUES ($1, $2) RETURNING "id"  [["data", "Hello!"], ["geom", #<GeoRuby::SimpleFeatures::Point:0x104d5c988 @m=0.0, @x=-1.6, @with_m=false, @z=-3.4, @with_z=true, @srid=123, @y=2.8>]]
   (0.2ms)  ROLLBACK
ActiveRecord::StatementInvalid: PGError: ERROR:  parse error - invalid geometry
HINT:  You must specify a valid OGC WKT geometry type such as POINT, LINESTRING or POLYGON
: INSERT INTO "table_points" ("data", "geom") VALUES ($1, $2) RETURNING "id"
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:976:in `get_last_result'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:976:in `exec_cache'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:548:in `exec_query'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract_adapter.rb:222:in `log'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0.rc4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract_adapter.rb:217:in `log'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:546:in `exec_query'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/database_statements.rb:54:in `exec_insert'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/database_statements.rb:81:in `insert'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/relation.rb:68:in `insert'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/persistence.rb:306:in `create'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/timestamp.rb:51:in `create'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/callbacks.rb:268:in `create'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0.rc4/lib/active_support/callbacks.rb:390:in `_run_create_callbacks'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0.rc4/lib/active_support/callbacks.rb:81:in `send'
... 4 levels...
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0.rc4/lib/active_support/callbacks.rb:390:in `_run_save_callbacks'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0.rc4/lib/active_support/callbacks.rb:81:in `send'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.0.rc4/lib/active_support/callbacks.rb:81:in `run_callbacks'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/callbacks.rb:264:in `create_or_update'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/persistence.rb:37:in `save'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/validations.rb:50:in `save'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/attribute_methods/dirty.rb:22:in `save'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/transactions.rb:241:in `save'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/transactions.rb:295:in `with_transaction_returning_status'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/database_statements.rb:183:in `transaction'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/transactions.rb:208:in `transaction'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/transactions.rb:241:in `save'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
    from /Library/Ruby/Gems/1.8/gems/activerecord-3.1.0.rc4/lib/active_record/transactions.rb:240:in `save'
    from (irb):25>> 

Rails 3 deprecation notice on require 'activerecord'

In the unit test files, require 'activerecord' triggers a deprecation notice since Rails 2.3.5. These can easily be solved by changing the require to require 'active_record'.

It occurs in the following files:

  • test/common/common_mysql.rb
  • test/common/common_postgis.rb

IndexDefinition overload breaks constructor in rails 3.0.10

spatial_adapter/common/schema_definitions.rb overloads ActiveRecord::ConnectionAdapters::IndexDefinition with a new constructor to add a spatial parameter, however fails to preserve the "lengths" parameter.

This can cause a crash in certain db migration scripts using add_index.

Rails 3.0.10
IndexDefinition < Struct.new(:table, :name, :unique, :columns, :lengths)
https://github.com/rails/rails/blob/4f15f392601d4504fab850f3bf659c43f0cb51ec/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb

It appears the lengths attribute was added on May 09, 2010 during the rails 2.3 series
rails/rails@8d2f6c1
Looks like any fix will need to accomodate both constructor signatures given support for AR >=2.2.2

Aggregate queries?

A hello and a question. I'm using spatial_adapter in http://github.com/opengovernment/opengovernment/
It's been super helpful for us -- so thank you!

One thing I'd love to be able to do is an aggregate spatial query like this:

District.all(:select => "state_id, st_extent(geom) as geo", :group => :state_id)

Or even use find_by_sql.
But is there any way to get a spatial_adapter object back?
Right now I'm just getting raw text, eg:

District.all(:select => "state_id, st_extent(geom) as geo", :group => :state_id).first.geo
=> "BOX(-106.645646 25.837377,-93.5164072637683 36.500704)"

Maybe I'm not casting correctly in my query?

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

superclass mismatch for SpatialPostgreSQLColumn

Hi,

Rails 2.3.4, Ruby 1.8.7, spatial_adapter 1.1.2

I added spatial_adapter to environment.rb file, fired up script/console and got this:

/usr/local/lib/ruby/gems/1.8/gems/spatial_adapter-1.1.2/lib/spatial_adapter/postgresql.rb:328:TypeError: superclass mismatch for class SpatialPostgreSQLColumn

Any ideas?

Regards,

Dan

Should not require MySQL or PG gems

Most of us will be using either MySQL or PG, but not both. I happen to use MySQL. But spatial_adapter wants me to have the PG gem installed. It raises if I don't.

Installing an unneeded MySQL or PG gem is a huge hassle just to make this gem happy. Both require compiling C against installed libraries. If you don't happen to have the exact flavor of MySQL or PG library that the gem requires, you're in for a long night.

I was able to patch this for my own purposes by commenting out require 'spatial_adapter/adapters/postgis' in lib/spatial_adapter.rb. I realize, of course, that that's not a workable solution for you.

I think the gem needs to be configurable so that it only requires the database adapter that you're actually going to use.

What have other people been doing? I'm surprised this issue hasn't been raised before. It seems like it would affect a lot of people. (I doubt that most people have both PG and MySQL gems installed.)

Clean up Rails version conditions

The adapters currently have quite a lot of conditions to handle various versions of Rails. I'm inclined to drop support for anything before Rails 2.0, but others might have differing opinions. Regardless, there is probably a cleaner way to implement.

Unable to connect to postgres without postGIS installed

My app connects to multiple databases via activerecord, some of which have postGIS and some do not.

When I use an AR class which connects to a db without postGIS,
I get a PG::Error (relation "geometry_columns" does not exist)
at spatial_adapter/postgresql.rb:216 in column_spatial_info.

I've been getting past this by including the following module in my AR objects, but would prefer a real fix.

module SupressSpatialCalculation # Since we dont have postGIS installed on this DB def column_spatial_info(column_name) {} end end

Would it make sense to handle this error within the adapter? (and maybe even disable the extra GIS features for that class when it's encountered)

PostGIS adapter not handling :null option properly

The PostGIS adapter is currently initialising the column with super(base, name, type, limit, default, null). It should actually be super(base, name, type, limit, nil, nil, default, null) because the fifth and sixth arguments are actually for :precision and :scale. Consequently the :null option is not getting handled properly. I'm guessing this was due to a change in Rails? I'm using the 2-3-stable branch.

Broken in Rails 2.3.3

spatial_adapter breaks ActiveRecord in Rails 2.3.3

ArgumentError: wrong number of arguments (2 for 1)
from vendor/rails/activerecord/lib/active_record/base.rb:2231:in sanitize_sql_hash_for_conditions' from vendor/rails/activerecord/lib/active_record/base.rb:2231:insanitize_sql'
from vendor/rails/activerecord/lib/active_record/base.rb:1494:in merge_conditions' from vendor/rails/activerecord/lib/active_record/base.rb:1492:ineach'
from vendor/rails/activerecord/lib/active_record/base.rb:1492:in merge_conditions' from vendor/rails/activerecord/lib/active_record/base.rb:1804:inadd_conditions!'
from vendor/rails/activerecord/lib/active_record/base.rb:1687:in construct_finder_sql' from vendor/rails/activerecord/lib/active_record/base.rb:1548:infind_every'
from vendor/rails/activerecord/lib/active_record/base.rb:1505:in find_initial' from vendor/rails/activerecord/lib/active_record/base.rb:613:infind'
from (irb):1

Unable to add index on MySQL InnoDB

in first migration I do:

def self.up
create_table :locations, :force => true do |t|
t.string :name
t.text :description
t.string :link
t.point :geom, :null => false

  t.timestamps
end

and in one after that:

add_index :locations, :geom, :spatial => true

which doesn't succeed and shows error:

Mysql2::Error: The used table type doesn't support SPATIAL indexes: CREATE SPATIAL INDEX index_locations_on_geom ON locations (geom)

Using Rails 3.0.3, MySQL (Ver 14.14 Distrib 5.1.39, for apple-darwin10.0.0 (i386)), InnoDB. Shouldn't InnoDB support indexes? Can't figure what I'm doing wrong. Any ideas? Do have GeoRuby and spatial_adapter in gemfile.

Thanks in advance.

Jan

type cast with JRuby

I am using PostgreSQL(jdbc adapter) and JRuby. The problem is when I load data from DB, the type cast doesn't work. So I only got a string like "010100002....".

Bring back find_by_* enhancements

Version 0.2.0 removed the find_by_* enhancements for spatial columns. The reason was that ActiveRecord::Base was being modified with database-specific SQL, which prevented one from using both MySQL and PostgreSQL at the same time. That resulted in all sorts of Rails dependencies and the inability to package a gem.

Failure in ActiveRecord

I got following failure when starting up my local server.

module:ConnectionAdapters': uninitialized constant ActiveRecord::ConnectionAdapters::Mysql2Column (NameError)

Following gems are installed:

GeoRuby 1.3.4
activerecord 3.2.1
spatial_adapter 1.2.0

I am using MySQL Server 5.5.28 and InnoDB.

Shouldnt it be working with InnoDB already?

Compatibility with mysql2 driver

I think this should be fairly simple to implement, I'm just hitting some nil.downcase on line 171 in mysql_spatial_adapter.rb

Why test RAILS_ENV in init.rb

I'm not really sure why we're looking at RAILS_ENV and the current ActiveRecord connection in init.rb. Why not just patch both PostgreSQL and MySQL all the time? This would give the ability to use ActiveRecord and the spatial_adapter outside of Rails.

to_fixture_format not supported?

The docs imply that to_fixture_format is a supported method, but it doesn't seem to be available. A look through the README indicates support might've been dropped for that at one point. What are the issues in restoring that?

Unit testing with rspec

I'm trying to get my code using PostGIS and this plugin under unit test using rspec

I'm having trouble getting tables with spatial columns loaded in the test db with the rake db:test:load rake task.

rake db:schema:dump is giving me this

create_table "room_geometries", :force => true do |t|
  t.column "room_id", :integer
  t.column "created_at", :timestamp
  t.column "updated_at", :timestamp
  t.column "the_geom", :multi_polygon
end

DB Test load is giving me all the columns except for 'the_geom'.

Is there instructions out there on what I need to do to get this testable? (I've not seen much with the google searches I've done)

Mysql2: uninitialized constant ActiveRecord::ConnectionAdapters::Mysql2Column

Unfortunately, it appears that the newest versions of ActiveRecord (3.2.0.rc1, at least) use:
ActiveRecord::ConnectionAdapters::Mysql2Adapter::Column

gems/spatial_adapter-1.2.0/lib/spatial_adapter/mysql2.rb:83:in <module:ConnectionAdapters>': uninitialized constant ActiveRecord::ConnectionAdapters::Mysql2Column (NameError) from gems/spatial_adapter-1.2.0/lib/spatial_adapter/mysql2.rb:82:inmodule:ActiveRecord'
from gems/spatial_adapter-1.2.0/lib/spatial_adapter/mysql2.rb:81:in <top (required)>' from gems/bundler-1.0.21/lib/bundler/runtime.rb:68:inrequire'

1.3.0 causes invalid mysql ddl type string instead of varchar on Ruby 1.8.7

Using a clean rails 3.0.10 app with mysql 5.0.90
Add to Gemfile:
gem 'mysql', '2.8.1'
gem 'spatial_adapter', '1.3.0'

When spatial_adapter 1.3.0 is present:
rake db:migrate
SQL (0.2ms) CREATE TABLE schema_migrations (version string NOT NULL) ENGINE=InnoDB
Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'string NOT NULL) ENGINE=InnoDB' at line 1: CREATE TABLE schema_migrations (version string NOT NULL) ENGINE=InnoDB

If you comment out spatial_adapter in Gemfile, this is generated instead.
rake db:migrate
SQL (48.3ms) CREATE TABLE schema_migrations (version varchar(255) NOT NULL) ENGINE=InnoDB

Failure when database does not contain PostGIS functions

I need to connect to another database in one of my models, and that database doesn't have PostGIS installed. If I have spatial_adapter installed, I get an ERROR: relation "geometry_columns" does not exist. I think spatial_adapter should look for the table and silently disable itself if it doesn't exist.

support for rails 3.2.2

trying to do bundle:

Bundler could not find compatible versions for gem "activerecord":
In Gemfile:
spatial_adapter (>= 0) java depends on
activerecord (< 3.1.0, >= 2.2.2) java

rails (= 3.2.2) java depends on
  activerecord (3.2.2)

I guess just updating the gemspec should suffice, I've not encountered any issue when using it under rails 3.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.