带有 PostGIS 的轨道

发布于 2024-10-21 20:32:41 字数 1427 浏览 3 评论 0原文

首先,我使用 Rails3 和 Ruby 1.9.2。

我在使用 PostgreSQL 和 PostGIS 时遇到问题。我尝试过两种宝石:

问题是,第一个nofxx 中的一个运行良好,但它不提供 rake 任务,因此 postgis.sql 和 Spatial_ref_sys.sql 被插入到数据库中。我需要这个,因为使用测试(自动创建数据库,插入 postgis sql 并在运行“rake test”时执行迁移)是舒适且必要的。奇怪的是,在 github 上的 README 中,作者写了一些关于 PostGIS 助手和 rake 任务的内容。但它们没有实现(或者我是盲目的)。

上面列出的第二个 gem 完美地为 rake 提供了此功能!但我遇到了一个无法解决的问题。我按照自述文件中的说明进行操作,但是每次当我尝试在空间列上设置位置时,我都会得到以下输出:

ruby-1.9.2-p136 :010 > v = Venue.new :location => "POINT(102.0, 47.2)"
=> #<Venue id: nil, last_updated: nil, created_at: nil, updated_at: nil, location: nil>
ruby-1.9.2-p136 :011 > v.location
=> nil 

如您所见,我使用 WKT (众所周知的文本)设置位置,但它始终为零。我也尝试将其保存到数据库中,但它也是零。 我发现,当我尝试使用 RGeo 提供的对象时

RGeo::Geos.factory.point(-122, 47)

,它说工厂为零。所以,创建RGeo提供的工厂肯定有问题。正如 activerecord-postgis-adapter 的自述文件中提到的,我在 Venue 模型中使用了以下行来提供此支持:

self.rgeo_factory_generator = RGeo::Geos.factory_generator

但它不起作用。

因此要找到解决方案,有两种方法:找到一种方法将 rake 任务放入 nofxx 的 georuby gem 中,或者使用 activerecord-postgis-adapter 的工厂解决问题。

希望有人能帮助我, 谢谢!

First of all, I'm using Rails3 with Ruby 1.9.2.

I have a problem using PostgreSQL with PostGIS. I've tried two gems:

The problem is, that the first one from nofxx works well, but it doesn't provide rake tasks, so that the postgis.sql and spatial_ref_sys.sql get inserted into the database. I need this, because it's comfortable and essential using tests (create automatically the database, insert the postgis sql and perform the migrations when running "rake test"). The strange thing is, that in the README on github the author writes something about PostGIS helpers and rake tasks. But they are not implemented (or I'm blind).

The second gem listed above provides this functionality for rake perfectly! But I ran into an issue that I can't solve. I followed the instructions in the README, but everytime when I try to set a position on a spatial column, i get the following output:

ruby-1.9.2-p136 :010 > v = Venue.new :location => "POINT(102.0, 47.2)"
=> #<Venue id: nil, last_updated: nil, created_at: nil, updated_at: nil, location: nil>
ruby-1.9.2-p136 :011 > v.location
=> nil 

As you can see, I set a location using WKT (well known text), but it's always nil. I also tried to save it to the database, but it's also nil.
I figured out, that when I try to use the Objects provided by RGeo

RGeo::Geos.factory.point(-122, 47)

it says, that the factory is nil. So, there must be a problem by creating the factory provided by RGeo. As mentioned in the README of the activerecord-postgis-adapter I used the following line in my Venue model to provide this support:

self.rgeo_factory_generator = RGeo::Geos.factory_generator

but it doesn't work.

So to find a solution, there are two ways: Finding a way to get the rake tasks into the georuby gem of nofxx, or solve the problem with the factory of the activerecord-postgis-adapter.

Hope someone can help me,
thx!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢欲 2024-10-28 20:32:41

我花了大约 4 个小时用“activerecord-postgis-adapter”解决同样的问题。答案很简单:“切勿在 WKT 中使用 COMAS”。在您的情况下,它必须是 v = Venue.new :location => "POINT(102.0 47.2)" 然后一切正常!

I'v spent about 4 hours on solving the same problem with "activerecord-postgis-adapter". The answer is simple : "NEVER USER COMAS IN WKT". In your situation it must be v = Venue.new :location => "POINT(102.0 47.2)" Then everything works just fine!

尐籹人 2024-10-28 20:32:41

最后我自己解决了。我在玩 rake 任务时遇到了一些让我恼火的问题(例如,您无法使用 psql 从脚本提供密码...)。
但我发现,您可以为database.yml 文件提供一个模板选项。所以,我只是写道:

development:
  adapter: postgresql
  pool: 5
  encoding: unicode
  database: myDatabase
  username: root
  password: *****
  su_username: root
  su_password: *****
  port: 5432
  template: template_postgis

test:
  adapter: postgresql
  pool: 5
  encoding: unicode
  database: myDatabase_test
  username: root
  password: *****
  su_username: root
  su_password: *****
  port: 5432
  template: template_postgis

production:
  adapter: postgresql
  pool: 5
  encoding: unicode
  database: myDatabase_production
  username: root
  password: *****
  su_username: root
  su_password: *****
  port: 5432
  template: template_postgis

现在每次我创建数据库时(在测试等过程中),所有 PostGIS 内容都会被添加!是的!

Finally I solved it on my own. I was playing around with rake tasks and I ran into some issues (like, you can't provide a password from script with psql...) that anoyed me.
But i found out, that you can provide a template option to the database.yml file. So, I just wrote:

development:
  adapter: postgresql
  pool: 5
  encoding: unicode
  database: myDatabase
  username: root
  password: *****
  su_username: root
  su_password: *****
  port: 5432
  template: template_postgis

test:
  adapter: postgresql
  pool: 5
  encoding: unicode
  database: myDatabase_test
  username: root
  password: *****
  su_username: root
  su_password: *****
  port: 5432
  template: template_postgis

production:
  adapter: postgresql
  pool: 5
  encoding: unicode
  database: myDatabase_production
  username: root
  password: *****
  su_username: root
  su_password: *****
  port: 5432
  template: template_postgis

Now every time I create my database (during tests and so on) all the PostGIS stuff gets added! Yeah!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文