viernes, enero 09, 2009

Agregar el template_postgis en PostgreSQL

Después de renegar un poquito con mi instalación de postgis en Ubuntu, puntualmente era que no tenia instalado el template_postgis. Revolví un poco en google y encontre esto (que es literalmente como se dice un COPY & PASTE!! de aquí). Lo único que tuve que modificar fue la ruta a los archivos lwpostgis.sql y spatial_ref_sys.sql

Nota: el archivo lwpostgis.sql también se puede encontrar como: postgis.sql, en mi Ubuntu (Karmic) el directorio donde se encuentran estos archivos es: /usr/share/postgresql/8.4/contrib/postgis-1.5/


# Create a database with UTF encoding
$ createdb -E UTF8 -O postgres -U postgres template_postgis

# Load the required language for PostGIS
$ createlang plpgsql -d template_postgis -U postgres

# Load postgis functions and spatial reference info
# which are sometimes installed in the postgres share directory ($ pg_config --sharedir)
# Also look for lwpostgis.sql and spatial_ref_sys.sql in (/usr/share/ or /usr/local/share/)

# Once you have found the correct location, load the first sql into your template db:
$ psql -d template_postgis -U postgres -f /usr/share/lwpostgis.sql


# Note: ignore any NOTICES, like 'psql:/usr/share/lwpostgis.sql:44: NOTICE: type "histogram2d" is not yet defined'
# You should see output like:
BEGIN
CREATE FUNCTION
CREATE OPERATOR
CREATE TYPE
CREATE AGGREGATE
COMMIT

# Then load the geographic projection tables
$ psql -d template_postgis -U postgres -f /usr/share/spatial_ref_sys.sql

# if you get an error about not being able to find `geos` add /usr/local/lib to /etc/ld.so.conf
# And run:
$ ldconfig # Then restart PostgreSQL