0

Following the documentation found here, I've been trying to create an OpenLayers map view using a custom projection, EPSG:4674 to be more specific. My current code looks like this:

import proj4 from 'proj4';
import {register} from 'ol/proj/proj4';
import {get as getProjection} from 'ol/proj';

proj4.defs('EPSG:4674','GEOGCS["SIRGAS 2000",DATUM["Sistema_de_Referencia_Geocentrico_para_las_AmericaS_2000",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6674"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4674"]]');
register(proj4);
const SIRGAS2000 = getProjection('EPSG:4674');

const map = new Map({
  view: new View({
    projection: SIRGAS2000
...

and those are my layers, in my GeoServer instance: GeoServer layers

The problem happens whenever I try to load any WMS source using the following code:

import { Tile as TileLayer } from "ol/layer";
import { XYZ as XYZSource, TileWMS as TileWMSSource } from "ol/source";

const estadoLayer = new TileLayer({
  title: "Estado",
  source: new TileWMSSource({
    url: GEOSERVER_WMS_URL,
    params: { LAYERS: "postgis:estado", TILED: true },
    projection: SIRGAS2000,
  }),
});

OpenLayers sends reversed BBOX coordinates to my GeoServer, as you can see here: Reversed coordinates

The funny thing is: If I remove the projection attribute from TileWMS constructor and set View's projection to "EPSG:4326", everything works fine:

Normal coordinates

What could be causing this issue? Considering that EPSG:4674 should, in theory, be compatible with EPSG:4326.

3
  • 1
    The official registry epsg.org defines the axis order as Lat Lon epsg.org/crs/wkt/id/4674 OpenLayers is aware that WMS 1.3.0 uses Lat Lon for EPSG:4326 but for custom projection you need to specify the axis order in the proj4 definition. Alternatively you could use WMS 1.1.0 which like epsg.io always assumes Lon Lat order.
    – Mike
    Commented Dec 14, 2020 at 13:24
  • Oh, I didn't know that! Thanks for pointing it out! I've definetely overlooked it! So... about proj4 axis order, how could I change that? I Googled it for a while but couldn't find any answers.
    – salgado
    Commented Dec 14, 2020 at 13:31
  • If you use the proj4js definition format simply add +axis=neu to the definition. I'm not familiar with proj4 use of WKT format but you could try AXIS('Geodetic latitude', NORTH),AXIS('Geodetic longitude', EAST)
    – Mike
    Commented Dec 14, 2020 at 13:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.