Skip to content

Reproject PostGIS Layer

Jeff McKenna edited this page Jul 18, 2019 · 17 revisions

Important Notes

Follow the "Important Notes" section on the PROJECTION page in the MapServer docs: https://mapserver.org/mapfile/projection.html

Connect through ogrinfo (to see extent values, projection, etc.)

Get list of layers

ogrinfo -ro PG:"host=127.0.0.1 user=postgres password=postgres port=5432 dbname=gmap"

returns:

  INFO: Open of `PG:host=127.0.0.1 user=postgres password=postgres port=5432 dbname=gmap'
        using driver `PostgreSQL' successful.
  1: province (Multi Polygon)
  2: popplace (Point)

Get summary of 'province' layer

ogrinfo -ro PG:"host=127.0.0.1 user=postgres password=postgres port=5432 dbname=gmap" province -summary

returns:

INFO: Open of `PG:host=127.0.0.1 user=postgres password=postgres port=5432 dbname=gmap'
      using driver `PostgreSQL' successful.

Layer name: province
Geometry: Multi Polygon
Feature Count: 1068
Extent: (-2340603.750000, -719746.062500) - (3009430.500000, 3836605.250000)
Layer SRS WKT:
PROJCS["NAD83 / Canada Atlas Lambert",
    GEOGCS["NAD83",
        DATUM["North_American_Datum_1983",
            SPHEROID["GRS 1980",6378137,298.257222101,
                AUTHORITY["EPSG","7019"]],
            TOWGS84[0,0,0,0,0,0,0],
            AUTHORITY["EPSG","6269"]],
        PRIMEM["Greenwich",0,
            AUTHORITY["EPSG","8901"]],
        UNIT["degree",0.0174532925199433,
            AUTHORITY["EPSG","9122"]],
        AUTHORITY["EPSG","4269"]],
    PROJECTION["Lambert_Conformal_Conic_2SP"],
    PARAMETER["standard_parallel_1",49],
    PARAMETER["standard_parallel_2",77],
    PARAMETER["latitude_of_origin",49],
    PARAMETER["central_meridian",-95],
    PARAMETER["false_easting",0],
    PARAMETER["false_northing",0],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AXIS["Easting",EAST],
    AXIS["Northing",NORTH],
    AUTHORITY["EPSG","3978"]]
FID Column = gid
Geometry Column = geom
area: Real (0.0)
perimeter: Real (0.0)
province_: Real (0.0)
province_i: Real (0.0)
status: String (30.0)
name: String (30.0)
name_e: String (30.0)
name_f: String (30.0)
reg_code: Integer (0.0)
poly_featu: Integer (0.0)
island: String (30.0)
island_e: String (30.0)
island_f: String (30.0)

Describe table through psql

psql -U postgres -p 5432 gmap
gmap=# \d province

returns:

                                         Table "public.province"
   Column   |            Type             | Collation | Nullable |                Default           
------------+-----------------------------+-----------+----------+---------------------------------------
 gid        | integer                     |           | not null | nextval('province_gid_seq'::regclass)
 area       | double precision            |           |          |
 perimeter  | double precision            |           |          |
 province_  | double precision            |           |          |
 province_i | double precision            |           |          |
 status     | character varying(30)       |           |          |
 name       | character varying(30)       |           |          |
 name_e     | character varying(30)       |           |          |
 name_f     | character varying(30)       |           |          |
 reg_code   | integer                     |           |          |
 poly_featu | integer                     |           |          |
 island     | character varying(30)       |           |          |
 island_e   | character varying(30)       |           |          |
 island_f   | character varying(30)       |           |          |
 geom       | geometry(MultiPolygon,3978) |           |          |
Indexes:
    "province_pkey" PRIMARY KEY, btree (gid)
    "province_geom_idx" gist (geom)

Working Mapfile Example Reprojecting PG Layer from 3978 to 4326

MAP
  NAME "postgis"
  STATUS ON
  SIZE 400 300
  SYMBOLSET "../etc/symbols.txt"
  ## latlong output extents
  EXTENT -180 -90 180 90
  UNITS DD
  SHAPEPATH "../data"
  IMAGECOLOR 255 255 255
  FONTSET "../etc/fonts.txt"

  # output projection
  PROJECTION
    "init=epsg:4326"
  END


  #
  # Start of layer definitions
  #


  LAYER
    NAME provinces
    METADATA
      "wms_title" "Land"
      "wms_extent" "-2340603.750000 -719746.062500 3009430.500000 3836605.250000"
    END
    TYPE POLYGON
    STATUS ON
    CONNECTIONTYPE postgis
    CONNECTION "host=127.0.0.1 user=postgres password=postgres port=5432 dbname=gmap"
    DATA "geom FROM province USING unique gid using srid=3978"
    # input projection / source projection of the data
    PROJECTION
      "init=epsg:3978"
    END
    CLASS
      NAME "Land"
      STYLE
        COLOR 240 240 240
        OUTLINECOLOR 199 199 199
      END
    END
    PROCESSING "CLOSE_CONNECTION=DEFER"
    TEMPLATE "ttt"
  END # layer



END # Map File

Clone this wiki locally