0

Just set up my MapServer on Ubuntu - all good. Downloaded this tutorial and it works fine: http://download.osgeo.org/mapserver/docs/mapserver-tutorial.zip

I've tried adding a PostGIS layer to the map, without success - can anyone help me. Here is the map file:

MAP
  IMAGETYPE      PNG
  CONFIG "MS_ERRORFILE" "/tmp/ms_error.txt"
  DEBUG 5
  EXTENT         11.8496964862307 55.5990839999999 13.02463 57.8704279999999
  SIZE           400 300
  SHAPEPATH      "../data"
  IMAGECOLOR     255 255 255

  # Layer objects are defined beneath the map object.  You need at least one
  # layer defined in your map file before you can display a map...  You can
  # define as many layers as you'd like although a limit is typically hard-coded
  # in map.h in the MapServer source.  The default limit is set at 100.  You'd
  # have to have a very specialized application to need more than 100 layers in
  # your application.

  # Start of LAYER DEFINITIONS ---------------------------------------------
  LAYER # States polygon layer begins here
    NAME         states
    DATA         states_ugl
    STATUS       OFF
    TYPE         POLYGON

    # The class object is defined within the layer object.  You can define as
    # many classes as you need (well, there are limits as with layers, but it's
    # senseless to define more than ten on a "normal" layer.  There are
    # situations, however, where you might have to do it.)
    CLASS
      NAME       "The Upper Great Lakes States"

      # There are styles in a class, just like there are classes in a layer,
      # just like there are layers in a map.  You can define multiple styles in
      # a class just as you can define multiple classes in a layer and multiple
      # layers in a map.
      STYLE
        COLOR        232 232 232
        OUTLINECOLOR 32 32 32
      END
    END
  END # States polygon layer ends here   
  LAYER 
    CONNECTIONTYPE postgis 
    NAME "plats" 
    DEBUG 5
    # Connect to a spatial database
    CONNECTION "user=postgres dbname=test host=localhost password=xxxxx"
    #PROCESSING "CLOSE_CONNECTION=DEFER"
    # Get the lines from the 'geom' column of the 'plats' table 
    DATA "geom from plats" 
    STATUS OFF
    TYPE POLYGON 
    CLASS
      NAME       "Plats"

      # There are styles in a class, just like there are classes in a layer,
      # just like there are layers in a map.  You can define multiple styles in
      # a class just as you can define multiple classes in a layer and multiple
      # layers in a map.
      STYLE
        COLOR        232 232 232
        OUTLINECOLOR 32 32 32
      END
    END
  END
  # End of LAYER DEFINITIONS -------------------------------

END # All map files must come to an end just as all other things must come to...

the debug output wasn't much help ...

[Fri Mar 14 19:28:07 2014].610665 CGI Request 1 on process 8022
[Fri Mar 14 19:28:07 2014].611179 msDrawMap(): rendering using outputformat named png (AGG/PNG).
[Fri Mar 14 19:28:07 2014].611200 msDrawMap(): WMS/WFS set-up and query, 0.000s
[Fri Mar 14 19:28:07 2014].611318 msDrawMap(): Layer 0 (states), 0.000s
[Fri Mar 14 19:28:07 2014].611336 msDrawMap(): Drawing Label Cache, 0.000s
[Fri Mar 14 19:28:07 2014].611343 msDrawMap() total time: 0.001s
[Fri Mar 14 19:28:07 2014].616884 msSaveImage(stdout) total time: 0.006s
[Fri Mar 14 19:28:07 2014].616976 mapserv request processing time (msLoadMap not incl.): 0.006s
[Fri Mar 14 19:28:07 2014].616989 msFreeMap(): freeing map at 0x8211eb8.
[Fri Mar 14 19:28:07 2014].617015 freeLayer(): freeing layer at 0x821a130.
[Fri Mar 14 19:28:07 2014].617025 msPostGISLayerIsOpen called.

Can anyone help?

  • What exactly was your output? Did mapserver render an empty layer, or did you have errors? Could you also provide the WMS url that you used, the layer status in your mapfile is OFF, you need to request the layer explicitly if the layer is set to off I think. – yellowcap Mar 25 '14 at 13:38
1

I'd change your map file in these ways:

  1. You don't have a WEB ... END section in your map file? Check documentation to see if you need it (I always include one).
  2. Your LAYER section should have a projection defined.
  3. Your DATA defn should be in the form of a SQL SELECT statement.
  4. Not sure you really want STATUS OFF?

Like this:

LAYER
    NAME "plats"
    TYPE POLYGON
    PROJECTION
        "init=epsg:4326"
    END
    CONNECTIONTYPE POSTGIS
    CONNECTION "user=postgres dbname=test host=localhost password=xxxxx"
    DATA "geom FROM (SELECT gid, geom FROM plats) as foo using unique gid using SRID=4326"
    CLASS
      NAME  "Plats"
      STYLE
        COLOR        232 232 232
        OUTLINECOLOR 32 32 32
      END #end style
    END #end class
END #end layer
1

By looking at the debug output you have never requested your new layer "plats" but only the "states" layer. It looks like your mapfile is from this very very old Mapserver tutorial http://download.osgeo.org/mapserver/docs/mapserver-tutorial.zip

With which method did you try to get this new map rendered? With some url given from the browser or what? The pgtutorial map in the same zip is better to use as a template but honestly I would recommend not to follow that tutorial. It is worth reading through but it is so old that the mapfiles in it do not work at all with recent Mapserver versions if you want to use WMS/WFS/WCS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.