【环境配置】postgis导入shapefile数据乱码解决方案

创建控件数据库的参考:

createdb yourdatabase

createlang plpgsql yourdatabase

psql -d yourdatabase -f postgis.sql

psql -d yourdatabase -f postgis_comments.sql

psql -d yourdatabase -f spatial_ref_sys.sql

------------------------------------------------

2.5. Create a spatially-enabled database

The first step in creating a PostGIS database is to create a simple PostgreSQL database.

createdb [yourdatabase]

Many of the PostGIS functions are written in the PL/pgSQL procedural  language. As such, the next step to create a PostGIS database is to  enable the PL/pgSQL language in your new database. This is accomplish by  the command

createlang plpgsql [yourdatabase]

Now load the PostGIS object and function definitions into your database by loading the postgis.sql definitions file (located in [prefix]/share/contrib as specified during the configuration step).

psql -d [yourdatabase] -f postgis.sql

For a complete set of EPSG coordinate system definition identifiers, you can also load the spatial_ref_sys.sql definitions file and populate the spatial_ref_sys table. This will permit you to perform ST_Transform() operations on geometries.

psql -d [yourdatabase] -f spatial_ref_sys.sql

If you wish to add comments to the PostGIS functions, the final step is to load the postgis_comments.sql into your spatial database. The comments can be viewed by simply typing \dd [function_name] from a psql terminal window.

psql -d [yourdatabase] -f postgis_comments.sql

2.6. Create a spatially-enabled database from a template

Some packaged distributions of PostGIS (in particular the Win32  installers for PostGIS >= 1.1.5) load the PostGIS functions into a  template database called template_postgis. If the template_postgis  database exists in your PostgreSQL installation then it is possible for  users and/or applications to create spatially-enabled databases using a  single command.  Note that in both cases, the database user must have been granted the  privilege to create new databases.

From the shell:

# createdb -T template_postgis my_spatial_db

From SQL:

postgres=# CREATE DATABASE my_spatial_db TEMPLATE=template_postgis

 

--------------------------------------------------------------

Creating a PostGIS template

The following is adapted from Rob Braswell’s instructions.  This allows non-superusers to create spatial databases using a template.

  • Connect to the template database
       $ psql template1

  • Execute the following commands:
       template1=# create database template_postgis with template = template1;
       template1=# UPDATE pg_database SET datistemplate = TRUE where datname = 'template_postgis';

  • Connect to the new template_postgis database:
       template1=# \c template_postgis

  • Add PostGIS extensions and grant access to everyone to spatial tables:
       template_postgis=# CREATE LANGUAGE plpgsql;
       template_postgis=# \i /opt/local/share/postgis/lwpostgis.sql;(路径为全局路径,lwpostgis改为postgis)
       template_postgis=# \i /opt/local/share/postgis/spatial_ref_sys.sql;
       template_postgis=# GRANT ALL ON geometry_columns TO PUBLIC;
       template_postgis=# GRANT ALL ON spatial_ref_sys TO PUBLIC;

  • Prevent further modifications to the template_postgis database:
       template_postgis=# VACUUM FREEZE;

  • Quit out of psql (^D or \q)

  • Create a test database using the new template_postgis template…
       $ createdb test_gis_db -T template_postgis
       …and drop it again.
       $ dropdb test_gis_db

对于用户,即可创建数据库

createdb test_gis_db -T template_postgis

dropdb test_gis_db


你可能感兴趣的:(【环境配置】postgis导入shapefile数据乱码解决方案)