【问题标题】:How do I fix missing PostGIS SRIDs in PostgreSQL?如何修复 PostgreSQL 中缺少的 PostGIS SRID?
【发布时间】:2013-11-30 15:50:44
【问题描述】:

我在运行我的 Rspec 测试套件时收到以下错误:

PG::InternalError: ERROR:  GetProj4StringSPI: Cannot find SRID (4326) in spatial_ref_sys

我知道我启用了 PostGIS 扩展。我该如何解决这个问题?

【问题讨论】:

    标签: postgresql rspec postgis


    【解决方案1】:

    问题是某些东西从spatial_ref_sys 表中删除了行。

    就我而言,问题出在我的DatabaseCleaner 配置中的spec_helper.rb 中。它被配置为删除/截断表。

    要防止这种行为,请更改配置。对我来说,那是:

    config.before(:suite) do
      DatabaseCleaner.strategy = :deletion, {:except => %w[spatial_ref_sys]}
      DatabaseCleaner.clean_with :truncation, {:except => %w[spatial_ref_sys]}
    end
    

    现在您需要重新生成该表中的行。使用名为 spatial_ref_sys.sql 的脚本来执行此操作。

    我使用 Postgres.app,所以运行该脚本的命令是:

    /Applications/Postgres.app/Contents/MacOS/bin/psql -d database_name -f /Applications/Postgres.app/Contents/MacOS/share/contrib/postgis-2.0/spatial_ref_sys.sql
    

    您的命令可能略有不同。

    【讨论】:

    • macports postgis: /opt/local/share/postgresql93/contrib/postgis-2.1/spatial_ref_sys.sql
    • 我注意到我所要做的就是重新运行 rake db:test:prepare 或 rake spec 来修复 spacial_ref_sys 表。
    • 该死,仍然无法在 v 1.5.1 中使用 - 每次执行套件时都会删除 spatial_ref_sys
    • 这似乎很明显,但是您定义了一个使用删除或截断的单独清理,您还需要在那里添加{:except => %w[spatial_ref_sys]}。这对于 js 功能测试 IE config.before(:each, :js => true) 来说真的很常见。即使特性测试不使用 postgis,如果他的特性测试在其他测试之前运行,那么在运行整个测试套件时你会遇到同样的问题
    • 使用较新版本的 Postgres 应用程序的目录是 /Applications/Postgres.app/Contents/Versions/9.4/share/postgresql/contrib/postgis-2.1/
    【解决方案2】:

    这是因为没有spatial_ref_sys 表。使用以下内容插入此表:

    psql -d country -f /usr/share/postgresql/9.3/contrib/postgis-2.1/spatial_ref_sys.
    

    country 是数据库名称,/usr/share/.../spatial_ref_sys.sql 是我的文件存储路径。这对我有用。

    【讨论】:

    • /usr/local/Cellar/postgis/2.1.4_1/share/postgis/spatial_ref_sys.sql 在我的 Mac 上
    • Ubuntu:/usr/share/postgresql/12/contrib/postgis-2.5/spatial_ref_sys.sql
    • 感谢您的回答!
    【解决方案3】:

    运行rake db:test:prepare 应该会恢复spatial_ref_sys 中的值。

    更新:这已在 1.4.1 版中修复:https://github.com/DatabaseCleaner/database_cleaner/pull/328

    database_cleaner 1.4.0版本有bug,需要指定表异常的schema:

    DatabaseCleaner.strategy = :truncation, { except: ["public.spatial_ref_sys"] }
    DatabaseCleaner.clean_with :truncation, { except: ["public.spatial_ref_sys"] }
    

    在 1.4.0 版中,模式作为表名的一部分返回。见https://github.com/DatabaseCleaner/database_cleaner/pull/282

    【讨论】:

      猜你喜欢
      • 2016-11-05
      • 1970-01-01
      • 2014-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-28
      • 2018-11-12
      • 2015-09-19
      相关资源
      最近更新 更多