简体   繁体   English

无法访问Postgis的方法

[英]Can't access methods of postgis

I try to build my rails env with postgis. 我尝试用postgis构建我的rails env。 The following is the extension of my db: 以下是我的数据库的扩展名:

                                        List of installed extensions
       Name       | Version |   Schema   |                             Description                             
------------------+---------+------------+---------------------------------------------------------------------

 plpgsql          | 1.0     | pg_catalog | PL/pgSQL procedural language

 postgis          | 2.1.3   | public     | PostGIS geometry, geography, and raster spatial types and functions

 postgis_topology | 2.1.3   | topology   | PostGIS topology spatial types and functions
(3 rows)

And I also can see the " t.spatial "location", limit: {:srid=>0, :type=>"geometry"}" in my schema.rb after add column and migration the database. 在添加列并迁移数据库后,我还可以在自己的schema.rb中看到“ t.spatial“位置”,限制:{:srid => 0,:type =>“ geometry”}“。

While in the console and rb file, I can't access the postgis method like: 在控制台和rb文件中时,我无法访问postgis方法,例如:

> e.location = ST_GeomFromText('POINT(121.04238 24.777656)', 4326)
NoMethodError: undefined method `ST_GeomFromText' for main:Object
    from (irb):2
    from /usr/local/rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/console.rb:90:in `start'
    from /usr/local/rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/console.rb:9:in `start'
    from /usr/local/rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /usr/local/rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /usr/local/rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands.rb:17:in `<top (required)>' 

Or in ruby file: 或在红宝石文件中:

@data.location = ST_GeomFromText('POINT(' + params[:longitude] +' ' + params[:latitude] + ')', 4326)

get the server error: 得到服务器错误:

NoMethodError (undefined method `ST_GeomFromText' for #<DataController:0x000000053ee388>):

I try some idea from internet, but can't figure it out. 我尝试从互联网上获取一些想法,但无法解决。

PostGIS' methods are supposed to be used in SQLs, rather than Ruby code. 应该将PostGIS的方法用于SQL,而不是Ruby代码。 See examples in the official document 查看官方文件中的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM