Changes between Initial Version and Version 1 of PostGIS


Ignore:
Timestamp:
Jan 28, 2009, 9:50:03 AM (15 years ago)
Author:
jmckenna
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PostGIS

    v1 v1  
     1= PostGIS Support in MapServer =
     2
     3----
     4The official PostGIS MapServer page is at: http://www.mapserver.org/input/vector/postgis.html
     5----
     6
     7== What is PostGIS? ==
     8
     9See PostGIS home page: http://postgis.refractions.net/
     10
     11== Compiling ==
     12
     13To use MapServer with PostGIS you have to add the --with-postgis switch on the configure script line.
     14
     15== Creating a spatial database ==
     16
     17Asumming the server is correctly installed, configured and programs such as psql,createdb... are accesibles on the path, now is time to create a spatial database.
     18
     19    * Open a shell (for example: cmd.exe or xterm)
     20    * Create the database. Run:
     21{{{
     22          createdb dbname
     23}}}
     24    * Allow the usage of PL pgSQL (used by PostGIS)
     25{{{
     26     createlang plpgsql dbname
     27}}}
     28    * Now, add the GIS extensions to the database. You must locate the files postgis.sql and spatial_ref_sys.sql. They should be on <pgSQL_install_dir>share/contrib/postgis or <pgSQL_install_dir>share/contrib directories.
     29{{{
     30          cd share/contrib
     31          psql -d dbname -f postgis.sql
     32          psql -d dbname -f spatial_ref_sys.sql
     33}}}
     34    * In the PostGIS package there are two programs that allow us convert SHP files to SQL Statements and SQL statements to SHP. This programs are called shp2pgsql and pgsql2shp respectivelly. For example, to add a SHP file to a table we would have to run this two commands:
     35{{{
     36          shp2pgsql fichero.shp table_name > file.sql
     37          psql -U username -d dbname -f file.sql
     38}}}
     39To add a Layer that uses a PostGIS table on our MapFile we would have to add on the layer object these lines:
     40{{{
     41      DATA "the_geom from table_name"
     42      CONNECTION "user=username password=guess dbname=dbname host=localhost port=5432"
     43      CONNECTIONTYPE postgis
     44}}}
     45NOTICE: The SQL keyword "from" has to be written in small case letters!
     46
     47This last step is fully explained in the MapFile Reference Documentation: http://mapserver.gis.umn.edu/doc42/mapfile-reference.html#layer)
     48
     49You have more extended help on PostGIS documentation about MapServer: http://postgis.refractions.net/docs/x558.html
     50
     51== Possible Problems / Debugging ==
     52
     53For basic debugging of the MapServer - PostgreSQL - PostGIS connection, Paul Ramsey offers the following sequential checklist:
     54
     55    * Can you ping the IP address of the host you want to connect to? (If no, you have physical network or routing problems.) Yes?
     56
     57    * Can you ping the named address of the host you want to connect to? (If no, you have name resolution problems.) Yes?
     58
     59    * Can you connect to the service port you want directly? (In the case of PgSQL, telnet <yourhost> 5432"). (If no, your service is not listening on the port. This is the first PgSQL specific possibility. You might have to go into your postgres.conf file and set "tcpip_socket = yes", then restart the database. You should also check your pg_hba.conf file, which has host and user based access controls. The simplest setup is to add a trust line for a trusted subnetwork. If your connections are all local, just ensure that localhost (127.0.0.1) is trusted.). Yes?
     60
     61    * Can you connect to the PgSQL database as the "postgres" user with the "psql" commandline tool ("psql -h yourhost -U postgres template1")? (If no, check that your database is actually running. Check your pg_hba.conf file again for a trust relationship to the host you are connecting from) Yes?
     62
     63    * Can you connect to the PgSQL template1 database as yourself? (If no, you might not have created yourself as a user yet. As postgres, 'CREATE USER yourname CREATEDB CREATEUSER' to make yourself a superuser.) Yes?
     64
     65    * Can you connect to your PgSQL working database as yourself? (If no, have you created a working database? "CREATE DATABASE yourdb") Yes?
     66
     67    * Can you select data out of geometry tables from your working database as yourself? (If no, as postgres GRANT yourself the ability to SELECT). Yes?
     68
     69    * Does your version of mapserver include support for PostGIS at all? Run "mapserv -v" at the commandline and look for "INPUT=POSTGIS". If it's not there, go back and recompile your mapserver binary with --enable-postgis (or --with-postgis=/<path to pg_config> as specified in your version's install docs). Yes?
     70
     71    * Set up your mapserver connection string, check that the parameters you are providing in the connection string work in psql. "user=you dbname=thedb host=thehost port=5432" translates to "psql -h thehost -U you -p 5432 thedb". yes?
     72
     73If problems continue, ask on the MapServer users list :)