I want to get the native SRS/EPSG-Code of a layer deployed in GeoServer. Maybe similar to this solution: https://stackoverflow.com/questions/32766126/get-the-epsg-code-from-openlayers-3-layer but with Openlayers 2 or the RESTful API of GeoServer.

Is there a way to achieve this? GeoServer itself displays those native EPSG codes when you look at your layers on the right hand side.

So somehow this must be possible but I just can't find the answer.

  • Have you looked in the capabilities response? – Ian Turton Dec 4 '18 at 13:03
  • 1
    WMS does not define any supported SRS to be native SRS but you could check WFS or WCS capabilities if they are available from the service. – user30184 Dec 4 '18 at 13:24
  • Well it seems like the WMS is indeed giving the native EPSG in the capabilities. See my proposed answer on this question – Leo.1906 Dec 5 '18 at 7:39

Ok I have found a solution that works for me. I hope that this is something that works in every environment but for now I have not tested it somewhere else than on my own GeoServer.

This is the js code:

function getEPSG(bboxObject) {
    var bboxObject = JSON.stringify(bboxObject);
    bboxObject = bboxObject.split('"');

    for (var i = 0; i < bboxObject.length; i++) {
        if (bboxObject[i].includes("EPSG")) {
            return bboxObject[i];

    console.log("function getEPSG encountered an error!");
    return "EPSG:4326";

What you have to do prior to this function is to make a GetCapabilities request on your WMS server and find the layer you want to work with. Then extract the bbox object and pass it on to this function. The bbox object contains the boundingbox in the native SRS and also states the EPSG-Code of it.

But be sure to use the version=1.1.0 when making the GetCapabilities request if you want to work on with that bounding box provided. It seems that version=1.3.0 switches the coordinates of the box so that this can't be used at all.

| improve this answer | |
  • 1
    GetCapabilities will have an entry for each supported EPSG for each layer. Your code will find a supported EPSG, but there may be more than one and there's nothing to indicate which one is the native SRS. – Mike Dec 6 '18 at 0:21
  • That's not true. I dont grab the list of supported EPSG (which is nearly everything). Look at the response of such an request. And than look at the boundingbox object (bbox). The bbox is computed when you import the layer into GeoServer from the native EPSG of the data. And this EPSG Code is also stated in the response. – Leo.1906 Dec 6 '18 at 8:51
  • 1
    It must be server dependent. I'm using fetch(url + '&request=GetCapabilities').then(function(response) { return response.text(); }).then(function(text) { console.log(JSON.stringify(new ol.format.WMSCapabilities().read(text).Capability.Layer.BoundingBox)); }); and getting an array containing multiple EPSG codes and extents. – Mike Dec 6 '18 at 16:49
  • 1
    Same result using the OpenLayers 2 parser except the sort order was different console.log(JSON.stringify(new OpenLayers.Format.WMSCapabilities().read(text).capability.layers[0].bbox)); Note that to get SRS/CRS from WMS 1.3.0 you may need to specify new OpenLayers.Format.WMSCapabilities({version: '1.3.0'}) – Mike Dec 6 '18 at 17:43
  • Please look here what I mean. If you make the request and than loop to the specific layer you are working with, this is the response and that is where you get the EPSG from: i.stack.imgur.com/zmf5X.png – Leo.1906 Dec 10 '18 at 11:58

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.