Personal tools
You are here: Home Documentation References

15. PostGIS/PostgreSQL

Document Actions
Up one level

PostGIS is supported directly by MapServer and must be compiled into MapServer to work.

In most cases, PostgreSQL and PostGIS libraries (.dll or .so) must be present in the system's path environment for functionality to be present. This includes the libpq and libpostgis libraries.

Map File Example Specify:

CONNECTIONTYPE POSTGIS

Specify:

CONNECTION "host=yourhostname dbname=yourdatabasename user=yourdbusername password=yourdbpassword port=yourpgport"

CONNECTION parameters can be in any order. Most are optional. dbname is required. host defaults to localhost, port defaults to 5432 - the standard port for PostgreSQL.

Specify:

DATA "geometrycolumn from yourtablename".  

MapServer had a bug related to the keyword from. Specify it in lower case to avoid problems. Geometrycolumn could be the_geom if the shp2pgsql utility is used to load data, or wkb_geometry if ogr2ogr was used.

Complete Mapfile example:

LAYER
  NAME pg_test
  STATUS ON
  TYPE POLYGON
  CONNECTIONTYPE POSTGIS
  CONNECTION "host=mapserver.com dbname=gmap user=julio"
  DATA "wkb_geometry FROM province"
  CLASS
     ...
  END
END

For more info about PostGIS and MapServer see the PostGIS docs: http://postgis.refractions.net/docs/

by Jeff McKenna last modified 2007-10-15 12:30
Contributors: Tyler Mitchell, Jeff McKenna

using PostGIS views with Mapserver

Posted by Bart van den Eijnden at 2005-10-11 05:13
If you want to use PostGIS views with Mapserver make sure you have the following:

1) you need an oid in the view
2) insert a row into the geometry_columns for the view

Example:

create view milieu.vw_bedrijven_publiek as select bedrijven.oid, * from milieu.bedrijven as bedrijven where vertrouwelijk=0;

INSERT INTO geometry_columns VALUES('', 'milieu', 'vw_bedrijven_publiek', 'the_geom', 2, 28992, 'POINT');

Using Table without oid

Posted by Sylvain ¨Perrinel at 2006-10-03 08:39
If your table doesn't have an oid column, You can specify in the data objet like this :
DATA "your_geometric_column from your_table_name using unique your_geometric_column"

Powered by Plone