繁体   English   中英

如何在PostgreSQL中修复丢失的PostGIS SRID?

[英]How do I fix missing PostGIS SRIDs in PostgreSQL?

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

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

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

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

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

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

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

您的命令可能略有不同。

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

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

database_cleaner 1.4.0版中存在一个错误,因此您需要指定表异常的模式:

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

这是因为没有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是存储文件的路径。 这适合我。

暂无
暂无

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

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