TransWikia.com

OpenLayers flip coordinate order for BBOX WMS request

Geographic Information Systems Asked by Eetmyhouse on August 6, 2021

I have a WMS layer which have a different axis-orientation to the one that OpenLayers sends out in the BBOX-request.

Openlayers uses the BBOX (minx,miny,maxx,maxy): BBOX=1438239.124213878%2C7895639.273745567%2C1448023.0638343806%2C7905423.213366069

But to get my map-tiles I have to swap the axis-order to this (miny,minx,maxy,maxy):

BBOX=7895639.273745567%2C1438239.124213878%2C7905423.213366069%2C1448023.0638343806

The x and y should change order in the request. Is there any simple solution to this?

I´ve tried to read other questions, but most requests is to change the coordinate system, which I´m not interested in.

Also, the same question I have is posted here: How change axis/coordinates/xy order for a particular layer in a Map?

But that is referring to OpenLayers 2.

2 Answers

If you don't have access to the server to fix the non-standard WMS you can use a custom tile url function to swap the bbox coordinates. This should work for a standard tile grid with square tiles and centered at [0,0].

var defaultUrlFunction = source.getTileUrlFunction().bind(source);
source.setTileUrlFunction( function(tileCoord, pixelRatio, projection) {
    var coord = ol.extent.getCenter(this.getTileGrid().getTileCoordExtent(tileCoord)).reverse();
    var newTileCoord = this.getTileGrid().getTileCoordForCoordAndZ(coord, tileCoord[0]);
    return defaultUrlFunction(newTileCoord, pixelRatio, projection);
});

Answered by Mike on August 6, 2021

Openlayers uses the BBOX (minx,miny,maxx,maxy)

So does WMS version 1.3.0:

7.2.4.6.8 BoundingBox

WMS service metadata shall declare one or more bounding boxes (as defined in 6.7.4) for each Layer. A Bounding Box metadata element may either be stated explicitly or may be inherited from a parent Layer. In XML, the metadata element includes the following attributes:

⎯ CRS indicates the Layer CRS that applies to this bounding box.

⎯ minx, miny, maxx, maxy indicate the limits of the bounding box using the axis units and order of the specified CRS.

⎯ resx and resy (optional) indicate the spatial resolution of the data comprising the layer in those same units.

And indeed WMS 1.1.1:

7.2.3.6 BBOX

The required BBOX parameter allows a Client to request a particular Bounding Box. Bounding Boxes are defined in the Basic Service Elements section. The value of the BBOX parameter in a GetMap request is a list of comma-separated numbers of the form "minx,miny,maxx,maxy".

The difference between the two standards is not the order of the x,y in the request, it's the potential difference between the definition of which axis (Easting/Northing, Latitude/Longitude, ...) constitutes x or y.

In WMS 1.1.1 the axis order is set as X=longitude (easting) and Y=latitude (northing), even if the actual axis order specified in the coordinate reference system is the other way around... In WMS 1.3.0 the axis order is specified according to the coordinate reference system definition.

So...

urn:ogc:def:crs:EPSG::3857 defines its axes as first axis "easting (X)" and second axis "northing (Y)"

Assuming you are using EPSG::3857, there should be no difference to your application if you use a WMS 1.1.1 or WMS 1.3.0.

Assuming OpenLayers is expecting x=Longitude/Easting, and you are using EPSG::3857, then if your data is displaying in the wrong location, the issue is with the WMS.

Answered by nmtoken on August 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP