Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix missing PostGIS SRIDs in PostgreSQL?

I received the following error while running my Rspec test suite:

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

I know that I enabled the PostGIS extension. How do I fix this?

like image 452
barelyknown Avatar asked Nov 17 '13 14:11

barelyknown


People also ask

Where can I find Srid in PostgreSQL?

The syntax is find_srid(<db/schema>, <table>, <column>) and the function returns the integer SRID of the specified column by searching through the GEOMETRY_COLUMNS table. If the geometry column has not been properly added with the AddGeometryColumns() function, this function will not work either.

What is Srid PostGIS?

Basically, PostGIS opens up the ability to store your data in a single coordinate system such as WGS84 (SRID 4326), and when you need something like Area, Distance, or Length, you use a function to create that column from your data in a projected coordinate system that will give you a local interpretation of your data ...

What does Srid 0 mean?

SRID of 0 doesn't technically exist, it just means no SRID — ie, the default if you forget to set it. Zero is a valid SRID, your PostGIS configurations will set for some default value, that in a fresh installation will be WGS84, srid 4326 .


1 Answers

The problem is that something removed the rows from the spatial_ref_sys table.

In my case, the problem was in my DatabaseCleaner configuration in my spec_helper.rb. It was configured to delete/truncate the table.

To prevent that behavior, change the configuration. For me, that was:

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

Now you'll need to regenerate the rows in that table. Use the script named spatial_ref_sys.sql to do that.

I use Postgres.app, so the command to run that script was:

/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

Your command may be slightly different.

like image 160
barelyknown Avatar answered Sep 22 '22 01:09

barelyknown