Simple configuration PostgreSQL/MapServer/Openlayers

Andy Fo ucfsafo at GE.UCL.AC.UK
Sun Mar 11 07:48:31 EDT 2007


Hi,
Is there anybody out there that can help me with this very simple
configuration?
I’m new to WMS and I’m learning about it right now. I’m not completely new
to programming though; I have experience in C, PL/SQL, MapBasic and a bit
of JavaScript and HTML. I’m into GIS and used Oracle Spatial with MapInfo
software at work. I only now started to appreciate open source.

I decided to go onto practice straight away and opted for the following
configuration:

PostgreSQL/PostGIS (this is an excellent db and the documentation is
impressive!)
MapServer for rendering images and
Openlayers as a simple way to interact with the map/information.
Everything installed locally.

All I need is some sort of “Hello World” style example, some sort of
launch pad where I can add or change bit and pieces as I learn. Seeing
something actually working would give me the confidence to going through
all the details.
It should work with this configuration and I would be really grateful if
someone could help me with this.

I have loaded some vector data into Postgres, some polylines (or
linestrings) representing road network. This is referenced to British
National Grid (BNG) srid: 27700. The table has been spatially indexed.

Here’s where I can smell some trouble.
MapServer successfully outputs a png image with the following map file:

MAP
  IMAGETYPE      PNG
  EXTENT         525300 179800 536700 187600
  SIZE           800 600
  SHAPEPATH      "/ms4w/apps/TestMaps/FirstTest"
  IMAGECOLOR     192 192 192
  UNITS          METERS
 LAYER
  CONNECTIONTYPE postgis
  NAME "tlrn_network"
  CONNECTION "user=??? password=??? dbname=mapping host=localhost"
  DATA "wkb_geometry FROM net"
  STATUS ON
  TYPE LINE
  CLASS
   COLOR 0 0 0
  END
  METADATA
   "WMS_SRS"    "EPSG:BNG"
  END
  PROJECTION
   "init=epsg:27700"
  END
 END
END

I tested this firefox and the following URL:

http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/TestMaps/FirstTest/tlrn.map&layer=tlrn_network&mode=map

So far so good, but here’s the trouble:

<html>
<head>
<script src="http://openlayers.org/api/2/OpenLayers.js"></script>
</head>
<body>
  <div style="width:100%; height:100%" id="map"></div>
  <script defer="defer" type="text/javascript">
    var mymap = new OpenLayers.Map('map');
    var mylayer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
        "http://localhost/cgi-bin/mapserv.exe?",{layers:
'tlrn_network',map:'/ms4w/apps/TestMaps/FirstTest/tlrn.map'},{projection:
"EPSG:BNG"});
    mymap.addLayer(mylayer);
    mymap.zoomToMaxExtent();
  </script>
</body>
</html>

It just doesn’t work. Openlayers kind of attempt to display the image, it
shows the correct background color. However, instead of my road network,
it shows the following error message on each tile:

“MsWMSLoadGetMapParams(): WMS server error. Cannot set new SRS on a map
that doesn’t have any projection set. Please make sure your mapfile has a
projection defined at the top level.”

Well, obviously my map file has no defined projection at top level. It is
only defined at the layer’s level (and probably wrongly). Whenever I
attempt to do at the Map top level it seems that things get only worse or
no change at all.
When I get rid of the metadata, for example
#  METADATA
#   "WMS_SRS"    "EPSG:BNG"
#  END
the message changes to:
“msWMSLoadGetMapParams(): WMS server error. Invalid SRS given : SRS must
be valid for all requested layers.

I’m stuck! As I said all I need is something that works and I can use as a
base. I’ll go away and practice with all this without harassing the entire
community (well, for a while at least!).

Many thanks

Andy



More information about the mapserver-users mailing list