0

I am currently trying to convert WFS2/GML3.2 data in EPSG:31287 to geojson using openlayers 6.15.1. For geojson I am trying to convert it to EPSG:4326/WGS84 using the following Typescript snippit:

import { WFS } from 'ol/format'
import { GeoJSON } from 'ol/format'
import { register } from 'ol/proj/proj4';
import * as proj4x  from "proj4";
const proj4 = (proj4x as any).default;

// define EPSG:31287
proj4.defs('EPSG:31287', '+proj=lcc +lat_0=47.5 +lon_0=13.3333333333333 +lat_1=49 +lat_2=46 +x_0=400000 +y_0=400000 +ellps=bessel +towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.42319999999019 +units=m +no_defs +type=crs');
register(proj4);

// initialize WFS parser
const parser = new WFS({featureNS: 'http://mapserver.gis.umn.edu/mapserver', version: '2.0.0'

const data = '...some wfs 2.0.0 response containing GML3.2 data...';

// read the features
const wfsFeatures = parser.readFeatures(data);

// and immediatly write it as geojson, transforming it from EPSG:31287->EPSG:4326
const geoJsonString = new GeoJSON().writeFeatures(wfsFeatures, {
    featureProjection: 'EPSG:31287',
    dataProjection: 'EPSG:4326'
  });

However it seems something is going wrong during the re-projection. Not only is the geometry at the wrong location, it also seems rotated/flipped: [1]: https://i.stack.imgur.com/7GV1o.png

Interestingly, no matter which output-transformation I choose (when exporting to GML3.2 instead of GeoJSON, tried 4326 and 3857), the result always looks the same in QGIS. Only when specifying EPSG:31287 everywhere the result is correct (but of course in the wrong projection), most likely because openlayers detects it actually can avoid re-projection between equal projections.

Any idea what is going on here? Some pointers would really help.

user2923748
  • 315
  • 2
  • 9
  • 3
    The EPSG:31287 projection is defined as `Axes: northing, easting` https://epsg.io/31287 Therefore the proj4 definition should include `+axis=neu`. Similar to EPSG:2180 here https://github.com/openlayers/openlayers/issues/11076 – Mike Aug 31 '22 at 13:09
  • Do no include figures from external websites. You should include them directly on the question: we are a reference site (and not a forum), so we expect people will find your question (and so the solution) in few years. We cannot guarantee that with an external link. – Giacomo Catenazzi Aug 31 '22 at 13:27
  • Thanks a lot Mike! Just added +axis=neu and everything worked like charm. I guess I would have never figured that out myself. – user2923748 Aug 31 '22 at 15:05

0 Answers0