Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to display a shapefile using OpenLayers and Mapserver. Instead of overlaying it as a png, I want to return a vector, in this case a KML file. My HTML file (located in the same folder as mapserv on my server contains the following html/javascript:

<html>
  <head>
  <title>OpenLayers Example</title>
   <script src="http://openlayers.org/api/OpenLayers.js"></script>
   <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    </head>
    <body>
      <div style="width:100%; height:100%" id="map"></div>
      <script type="text/javascript">

      var map = new OpenLayers.Map('map');

      var googleLayer = new OpenLayers.Layer.Google('Google', {type: google.maps.MapTypeId.SATELLITE});

       // Add WFS data
       var wfsLayer= new OpenLayers.Layer.Vector("WFS", {
           strategies: [new OpenLayers.Strategy.BBOX()],
           protocol: new OpenLayers.Protocol.WFS({
              url: "http://mysite.com/mapserv.cgi/wfs?&map=wfs.map&",
              featureType: "MLSOA",
              featureNS: "http://mysite.com/mapserv.cgi/wfs?&map=wfs.map&",
              srsName: "EPSG:27700",
              version: "1.0.0"  
          })
       });

//add layers
map.addLayers([googleLayer,wfsLayer]);

// Set initial center location
map.setCenter(new OpenLayers.LonLat(-0.13, 51.55).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()),5);
</script>
</body>
</html>

The shapefile, MLSOA, is projected using EPSG:27700. My mapfile, is called wfs.map is as follows:

MAP # start of map file

NAME demo
STATUS ON
SIZE 420 300
EXTENT 82299.5 5002.78 655979.76 657599.55
UNITS METERS
SHAPEPATH "shapefiles"
IMAGECOLOR 255 255 255
  PROJECTION
    "init=epsg:27700"
  END

OUTPUTFORMAT
  NAME "kml"
  DRIVER KML
  MIMETYPE "application/vnd.google-earth.kml.xml"
  IMAGEMODE RGB
  EXTENSION "kml"
END

WEB
#TEMPLATE "template.html"
IMAGEPATH "/home/webapps/htdocs/output/"
IMAGEURL "/output/"
  METADATA
    "wfs_title"          "MLSOA"
    "wfs_version"           "1.0.0"
    "wfs_connectiontimeout" "60"
    "wfs_maxfeatures"       "10"
    "wfs_enable_request"   "*"
  END
END

  LAYER
     NAME "MLSOA"
     TYPE POLYGON
     STATUS DEFAULT
     CONNECTION "http://mysite.com/mapserv.cgi/wfs?&map=wfs.map&"
     CONNECTIONTYPE WFS
     CLASS
       STYLE
        COLOR 255 128 128
          OUTLINECOLOR 96 96 96
        END 
       END
     END
END

To check that this works, when I run:

http://mysite.com/mapserv.cgi/wfs?map=/home/urbmet/webapps/htdocs/wfs.map&SERVICE=WFS&REQUEST=GetCapabilities&VERSION=1.0.0

I get the following output.

<!-- MapServer version 6.0.1 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=KML SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=ICONV SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=THREADS SUPPORTS=GEOS INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE -->

so I assume that it is working ok. However when I open my HTML file, the post query appears to run ok (as far as I understand):

<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<wfs:Query typeName="feature:MLSOA" xmlns:feature="http://mysite.com/mapserv.cgi/wfs?&map=wfs.map&">
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:BBOX>
<ogc:PropertyName>the_geom</ogc:PropertyName>
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
<gml:coordinates decimal="." cs="," ts=" ">-55.50109375,43.134977942511 55.24109375,59.593781185019</gml:coordinates>
</gml:Box>
</ogc:BBOX>
</ogc:Filter>
</wfs:Query>
</wfs:GetFeature>

but the response from the server is as follows:

<?xml version='1.0' encoding="ISO-8859-1" ?>
<ServiceExceptionReport version="1.2.0" xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd">
  <ServiceException code="NoApplicableCode" locator="mapserv">
msWFSGetFeature(): WFS server error. FLTApplyFilterToLayer() failed
msWFSLayerWhichShapes(): WFS connection error. WFS request produced unexpected output (junk?) for layer MLSOA.
msBuildWFSLayerPostRequest(): WFS connection error. MapServer supports only WFS 1.0.0 or 0.0.14 (please verify the version metadata wfs_version).
msWFSLayerWhichShapes(): WFS connection error. WFS request produced unexpected output (junk?) for layer MLSOA.
msWFSLayerWhichShapes(): WFS connection error. WFS request produced unexpected output (junk?) for layer MLSOA.
msBuildWFSLayerPostRequest(): WFS connection error. MapServer supports only WFS 1.0.0 or 0.0.14 (please verify the version metadata wfs_version).
  </ServiceException>
</ServiceExceptionReport>

I'm not sure what to do to fix this error message. I've checked that Openlayers is sending a query with version: "1.0.0" encoded, but the other errors are not as clear. What can I do to fix this?

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

Your MAP file seems to indicate that your LAYER is coming from another WFS server using CONNECTIONTYPE WFS - are you sure you mean to do this?

If you just want to enable WFS for a layer using data on your server then just define a standard LAYER.

 LAYER
    NAME 'MLSOA'
    TYPE POLYGON
    DATA "C:/path/shapefile.shp"
    CLASS
      STYLE
       COLOR 255 128 128
       OUTLINECOLOR 96 96 96
      END 
    END
END

You'll need to request your WFS using the srsName of the OpenLayers map (EPSG:900913 by default - plus you will have to add this projection definition to your MAP file). Also use version 1.1.0 and add an srsName to your query string. Details and notes (of a not particularly pleasant process!) at:

http://geographika.co.uk/mapserver-openlayers-and-the-wfs-maze

share|improve this answer
    
Hi geographika - thanks for the suggestions. Just so I understand - I should delete the line CONNECTIONTYPE WFS ? I've pasted in my map file into an answer to make sure that I understand what to remove, but I can add it to your answer either. In general, I've found it hard to get a clear example of html/openlayers and a .map file online. I can ensure that all my projections are the same in this case so I hope I do not have to deal with the srsName issue. –  djq Oct 21 '11 at 13:22
    
Yes CONNECTIONTYPE WFS is used when you want to get data from another WFS server –  geographika Oct 21 '11 at 14:19
    
Should I also keep all of the other information, such as the OUTPUTFORMAT and WEB section? I removed everything from the layer file aside from what you suggested, but I get an error <gml:boundedBy> <gml:null>missing</gml:null> </gml:boundedBy> Perhaps that just means that there is an error in my bounding box. –  djq Oct 21 '11 at 14:30
    
Yes keep the rest of the MAP file. It is just your LAYER definition that you need to check. –  geographika Oct 21 '11 at 14:33
add comment

Here is my currently (sort of functioning) mapfile, for future reference using @ geographika's advice:

MAP # start of map file    
NAME demo
STATUS ON
SIZE 420 300
EXTENT 82299.5 5002.78 655979.76 657599.55
UNITS METERS
SHAPEPATH "shapefiles"
IMAGECOLOR 255 255 255
  PROJECTION
    "init=epsg:27700"
  END

OUTPUTFORMAT
  NAME "kml"
  DRIVER KML
  MIMETYPE "application/vnd.google-earth.kml.xml"
  IMAGEMODE RGB
  EXTENSION "kml"
END

WEB
IMAGEPATH "/home/webapps/htdocs/output/"
IMAGEURL "/output/"
  METADATA
    "wfs_title"          "MLSOA"
    "wfs_version"           "1.1.0"
    "wfs_connectiontimeout" "60"
    "wfs_maxfeatures"       "10"
    "wfs_enable_request"   "*"
    "wfs_onlineresource" "http://mysite.com/mapserv.cgi?service=WFS"
  END
LOG 'ERRORLOG.txt'
END

LAYER
  NAME  "MLSOA"
  TYPE POLYGON
  DATA "/home/webapps/htdocs/shapefiles/MLSOA.shp"
  DUMP TRUE
    CLASS
        STYLE   
          COLOR 255 0 0
        END
    END
END # Layer

END # end of mapfile
share|improve this answer
    
Where is the data for your MLSOA layer? Is it in a database or shapefile? –  geographika Oct 21 '11 at 14:14
    
It is in a shapefile, in a directory shapefiles. This directory is in the same place that mapserv is. –  djq Oct 21 '11 at 14:15
    
See my updated answer. LAYER definitions point to the data on your server. MapServer takes care of turning these LAYERS into WMS / WFS services. –  geographika Oct 21 '11 at 14:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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