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.