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.

This question is an exact duplicate of:

I am trying to add a vector layer with a WFS protocol.

var wfs = new OpenLayers.Layer.Vector("WFS", {
                strategies: [new OpenLayers.Strategy.BBOX({resFactor: 1})],
                projection: new OpenLayers.Projection("ESPG:900913"),
                protocol: new OpenLayers.Protocol.WFS({
                    url: geoserverURL,
                    srsName: "EPSG:28992",                    
                    maxFeatures: 20,
                    featureType: "FEATURE",
                    geometryName: "the_geom",   
                    featureNS: "http://tempuri.org/"                   
                })              
            });
            map.addLayer(wfs);

In my database (postgis) the coordinates are stored as EPSG:28992. My baselayer is OSM so that should be ESPG:900913. But the features are not projected on the correct spot.

I tried other projections but the features are not projected correctly that way either.

What am I doing wrong here?

Edit:

I tried changing

projection: new OpenLayers.Projection("ESPG:900913")

to

projection: new OpenLayers.Projection("EPSG:4326")

or

projection: new OpenLayers.Projection("EPSG:28992")

But the features are still nowhere near where they are supposed to be.

share|improve this question

marked as duplicate by Devdatta Tengshe, Fezter, whuber Apr 26 '13 at 13:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Are there any errors in Firebug? Is the wfs coming from a different domain? Have you used a proper url? –  Devdatta Tengshe Apr 26 '13 at 10:48
    
I can see the features but they are just showing up at the wrong spot on the OSM baselayer. I looked at your answer from that other question. My WFS vector layer projection should be EPSG:28992 right? Because that's the projection of my data? –  Edward van Raak Apr 26 '13 at 11:47

1 Answer 1

up vote 2 down vote accepted

You should use the following code:

var wfs = new OpenLayers.Layer.Vector("WFS", {
            strategies: [new OpenLayers.Strategy.BBOX({resFactor: 1})],
            projection: new OpenLayers.Projection("ESPG:28992"),
            protocol: new OpenLayers.Protocol.WFS({
                url: geoserverURL,
                srsName: "EPSG:28992",                    
                maxFeatures: 20,
                featureType: "FEATURE",
                geometryName: "the_geom",   
                featureNS: "http://tempuri.org/"                   
            })              
        });
        map.addLayer(wfs);

Another thing you need is the Proj4j JavaScript file. This is needed to convert the coordinates for the point from EPSG:28992 to EPSG:3857. (OpenLayers can do it on its own for EPSG:4326 to EPSG:3857, and requires this libary for transformation between other projection.)

You should read this User Guide. You can download the library from here: Downloads. You will also need the file for your projection in Proj4 format. You can download that from here: Spatial reference.org

Once you set up your application to use the proj4js library, it should work.

share|improve this answer
    
I changed my code to the above and I already had Proj4 included in my project. I did discover something weird though. GeoServer throws a runtime exception when I use "projection: new OpenLayers.Projection("ESPG:28992")". When I use projection: new OpenLayers.Projection("EPSG:4326") the exception doesn't occur. –  Edward van Raak Apr 26 '13 at 13:03
    
I reprojected my data through GeoServer (native to declared) to EPSG:4326 and it's working fine now. This is a bit stupid because it's converting twice now... I have no idea why it's throwing that exception, must be a bug. –  Edward van Raak Apr 26 '13 at 13:29

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