Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to add one of the included datasets with GeoServer to an OpenLayers map. I've followed the OpenGeo tutorials, seen similar thread on here, but I can't seem to crack it. Can somebody take a glance at my code and GeoServer setup and tell me where I'm going wrong?

Here's my code:

//WMS map
world = new OpenLayers.Layer.WMS("Global Imagery", "", {
    layers : "openstreetmap",
    format : "image/png"

parks = new OpenLayers.Layer.Vector("WFS", {
    strategies : [new OpenLayers.Strategy.BBOX()],
    protocol : new OpenLayers.Protocol.WFS({
        url : "http://localhost:8081/geoserver/wfs",
        featureType : "medford:parks",
        featureNS : ""



GeoServer details: workspace name = medford, Namespace URI = For the feature type I have tried "parks" and "medford:parks"

The layer is enabled, advertised and has a 30 feature return limit.

I'm struggling to put a simple map together.

Updated Solution. Working Now.

wfs = new OpenLayers.Layer.Vector("Fields_WFS", {
        strategies : [new OpenLayers.Strategy.Fixed()],
        protocol : new OpenLayers.Protocol.WFS({
        version : "1.1.0",
        url : GEOSERVER_HOST + ":" + GEOSERVER_PORT + "/geoserver/wfs", 
        featurePrefix : "rpid",
        featureType : "FIELDS_SUBSET_BNG_OSGB36_1",
        featureNS : "<namespace>", 
        //geometryName : "GEOM", type "Geometry"
        srsName : "EPSG:27700"
    renderers : renderer

Does not need to specify the geometry Name in Layer definition. Since Native SRS was null in our dataset, if we keep geometryName than it takes default, but without it, it uses map projection(27700- in our case).

share|improve this question
up vote 18 down vote accepted

Take a look at my answer on this post.

  1. Make sure your featureNS value is in the "Edit Workspace Page under Namespace URI" in your GEOSERVER. Do not use something as generic as "". Use something like "http://yourdomain/application/catalogLayer" or something unique like that. You can make this URI up, just make it unique.
  2. You have new BBOX() as a strategy but what do that box have as dimensions? I would change it to [new OpenLayers.Strategy.Fixed()] for testing.
  3. featureType is not actually the type of geometry, it's your "Layer Name" in GEOSERVER (i know, misleading).
  4. geometryName is the name of the field in your postgis database that has the Geometry data type. In GEOSERVER, Under "Edit Layer" you can see at the bottom "Feature Type details". There you will see a field with type "Geometry". Use the value under the property column

I would specify featurePrefix and version. Try something like this:

var wfs = new OpenLayers.Layer.Vector(
            "Stavros Features",
                strategies: [new OpenLayers.Strategy.Fixed()]
                , projection: new OpenLayers.Projection("EPSG:4326")
                , protocol: new OpenLayers.Protocol.WFS({
                    version: "1.1.0",
                    url: "http://localhost:8081/geoserver/wfs",
                    featurePrefix: 'myWorkspace', //geoserver worspace name
                    featureType: "medford:parks", //geoserver Layer Name
                    featureNS: "", // Edit Workspace Namespace URI
                    geometryName: "bounds" // field in Feature Type details with type "Geometry"
share|improve this answer
Thanks capdragon. I've taken all the steps but still no workspace is now called rpid and i've added a featurePrefix. I've tried featureType with and without appending the workspace. I've tried various namespaces including: "";, "localhost:8081/rpid";. I'm still confused about this property. I've inserted the projection and geometry name (GEOM). My map.html page lives here: file:///C:/Aptana/Workspace/GIS/map.html. Will this catch me out with the Same Origin Policy below? My Net tabe in Firebug shows a 'OPTIONS wfs' with no response – geo_james Jan 30 '12 at 14:33
The namespace of featureNS can be whatever you like so both of those will work. The important thing is that you have it exactly the same on your geoserver. Or else things don't get serialized and you get no response from the web service. So go into geoserver, click on your workspace (this will take you to the page Edit Workspace. the Name is what put as featurePrefix. And the Namespace URI is what you put as featureNS. Also, not sure if the file:///c: location will require you to use a proxy. But i would make the file live at http://localhost to test and make sure. – CaptDragon Jan 30 '12 at 14:43
OK I've now moved my code to localhost:8081/apps/index.html and changed my featureNS. I can now see 30 features coming back on the response...<rpid:OBJECTID>25</rpid:OBJECTID><rpid:FIELD_ID>NS/86427/74196</rpid:‌​‌​FIELD_ID><rpid:GROSS_AREA>2.307</rpid:GROSS_AREA>. Progress! However I'm not seeing any of the features on my map. When added as WMS I can see them fine. The only other layer is a base WMS. My console is also riddled with errors such as: OpenLayers.Marker is undefined and Ext.preg is not a function. I'm importing all my libraries locally... – geo_james Jan 30 '12 at 18:48
When you say there are 30 features in the response. They are in xml format wrapped within a parent <wfs:FeatureCollection numberOfFeatures="30"... element right? – CaptDragon Jan 30 '12 at 18:59
I would say create a new very simple test page and add that WFS layer. It seems to me that those errors are comming from other parts of your code since OpenLayers.Marker is not involved with WFS. Maybe i'm wrong, but creating a simple test page always help determine if it's working or not. That's what i do anyway. – CaptDragon Jan 30 '12 at 19:04

just correct your featuretype from "medford:parks" to "parks"

var wfs = new OpenLayers.Layer.Vector(
            "Stavros Features",
                strategies: [new OpenLayers.Strategy.Fixed()]
                , projection: new OpenLayers.Projection("EPSG:4326")
                , protocol: new OpenLayers.Protocol.WFS({
                    version: "1.0.0",
                    url: "http://localhost:8081/geoserver/wfs",
                    featureType: "parks", //geoserver Layer Name without workspace prefix
                    featureNS: ""


See jsfiddle as example:

share|improve this answer

Your code is ok. You just need to change the browser address of your page. Point your browser page through "localhost:8080/geoserver/www/your_file_name.html" instead of "file:\c......"

Then the vector layer will render perfectly.

share|improve this answer

Your problem is that you have the prefix on the feature name and a namespace this is confusing GeoServer (and/or OpenLayers).


 featureType : "parks",

I have some WFS examples at with commented source code that you can study.

share|improve this answer
Thanks iant. I've now tried without the prefix and I think there is a wider issue – geo_james Jan 30 '12 at 14:34
link is not working iant – Sam007 May 14 '12 at 19:06

First thing to check: is your server / test webpage on ''? If it isn't, you won't be able to access WFS because of the Same Origin Policy. You can technically use a proxy to fix this. (though in my opinion this is just a case of WFS being a poorly designed protocol)

share|improve this answer
Same Origin is a browser problem, WFS works exactly as designed. – iant Jan 20 '12 at 8:32
Yes and no: WFS is XML, so it necessitates an XML parser on every platform but Firefox (and 'the desktop'), and it also doesn't mix well with the only way we have to do cross-domain communication: JSONP. GeoJSON, on the other hand, is natively parsed in nearly every browser and is easily and commonly wrapped to be cross-domain compatible. Obviously not apples-to-oranges, and that's not the extent of my WFS critique (bloated, poorly extended, etc). – tmcw Jan 20 '12 at 23:16
You are assuming that browsers make good WFS clients. You hardly ever want to pull large amounts of geographic data into a web browser as vectors. – iant Jan 30 '12 at 14:37
Hi tmcw. No my test page is just a local file on my C drive. What should I set my Namespace URI to if i want to work with a local GeoServer on port 8081? – geo_james Jan 30 '12 at 14:40

Your Answer


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.