Transformation from ViennaGIS to WGS84 coordinates

Engineering

Apr 28, 2022

4/28/22

Conversion of ViennaGIS Gauss-Krüger M 34 MGI Austria GK East into Google WGS84 coordinates using the EPSG code 31256.

Conversion of ViennaGIS Gauss-Krüger M 34 MGI Austria GK East into Google WGS84 coordinates using the EPSG code 31256.

Transformation from ViennaGIS to WGS84 coordinates
Transformation from ViennaGIS to WGS84 coordinates
Transformation from ViennaGIS to WGS84 coordinates

In a current project, I had to convert the coordinates from ViennaGIS Gauss-Krüger M 34 MGI Austria GK East to Google WGS84 using the EPSG code 31256. The purpose was to display pins on Google Maps or Leaflet for objects and locations provided by ViennaGIS.

Unfortunately, ViennaGIS uses a Gauss-Krüger M 34 projection, which cannot be used with most Map SDKs. Therefore, I had to convert the coordinates beforehand into Google’s coordinate system. I used the libraries proj4j and proj4js, which are Java and JavaScript ports of the proj library.

The following code snippets show how to transform ViennaGIS GK34 to WGS84 coordinates using Kotlin and JavaScript.

Kotlin

Gk34ToWgs84CoordinatesTransformer.kt

// Kotlin version
// Maven dependency:
//    <dependency>
//      <groupId>org.locationtech.proj4j</groupId>
//      <artifactId>proj4j</artifactId>
//      <version>1.0.0</version>
//    </dependency>
 
package at.agsolutions
 
import at.agsolutions.Gk34Dto
import at.agsolutions.Wgs84Dto
import org.locationtech.proj4j.CRSFactory
import org.locationtech.proj4j.CoordinateTransformFactory
import org.locationtech.proj4j.ProjCoordinate
 
class Gk34ToWgs84CoordinatesTransformer {
 
    private val coordinateTranformFactory = CoordinateTransformFactory()
 
    /**
     * EPSG code 31256 = MGI Austria GK East, Gauss-Krüger M 34 (DKM), Greenwich
     * Cadastral plan in Eastern Austria (Irenental)
     * see https://www.esri-austria.at/service/projektionen-oesterreich/ and https://de.wikipedia.org/wiki/Datum_Austria
     */
    private val transformGk34ToWgs84 = coordinateTranformFactory.createTransform(
        /* GK34 */ CRSFactory().createFromName("epsg:31256"), /* WGS84 */ CRSFactory().createFromName("epsg:4326")
    )
 
    fun transform(gk34: Gk34Dto): Wgs84Dto {
        val result = ProjCoordinate()
        transformGk34ToWgs84.transform(ProjCoordinate(gk34.x.toDouble(), gk34.y.toDouble()), result)
        return Wgs84Dto(result.y.toBigDecimal(), result.x.toBigDecimal

// Kotlin version
// Maven dependency:
//    <dependency>
//      <groupId>org.locationtech.proj4j</groupId>
//      <artifactId>proj4j</artifactId>
//      <version>1.0.0</version>
//    </dependency>
 
package at.agsolutions
 
import at.agsolutions.Gk34Dto
import at.agsolutions.Wgs84Dto
import org.locationtech.proj4j.CRSFactory
import org.locationtech.proj4j.CoordinateTransformFactory
import org.locationtech.proj4j.ProjCoordinate
 
class Gk34ToWgs84CoordinatesTransformer {
 
    private val coordinateTranformFactory = CoordinateTransformFactory()
 
    /**
     * EPSG code 31256 = MGI Austria GK East, Gauss-Krüger M 34 (DKM), Greenwich
     * Cadastral plan in Eastern Austria (Irenental)
     * see https://www.esri-austria.at/service/projektionen-oesterreich/ and https://de.wikipedia.org/wiki/Datum_Austria
     */
    private val transformGk34ToWgs84 = coordinateTranformFactory.createTransform(
        /* GK34 */ CRSFactory().createFromName("epsg:31256"), /* WGS84 */ CRSFactory().createFromName("epsg:4326")
    )
 
    fun transform(gk34: Gk34Dto): Wgs84Dto {
        val result = ProjCoordinate()
        transformGk34ToWgs84.transform(ProjCoordinate(gk34.x.toDouble(), gk34.y.toDouble()), result)
        return Wgs84Dto(result.y.toBigDecimal(), result.x.toBigDecimal

// Kotlin version
// Maven dependency:
//    <dependency>
//      <groupId>org.locationtech.proj4j</groupId>
//      <artifactId>proj4j</artifactId>
//      <version>1.0.0</version>
//    </dependency>
 
package at.agsolutions
 
import at.agsolutions.Gk34Dto
import at.agsolutions.Wgs84Dto
import org.locationtech.proj4j.CRSFactory
import org.locationtech.proj4j.CoordinateTransformFactory
import org.locationtech.proj4j.ProjCoordinate
 
class Gk34ToWgs84CoordinatesTransformer {
 
    private val coordinateTranformFactory = CoordinateTransformFactory()
 
    /**
     * EPSG code 31256 = MGI Austria GK East, Gauss-Krüger M 34 (DKM), Greenwich
     * Cadastral plan in Eastern Austria (Irenental)
     * see https://www.esri-austria.at/service/projektionen-oesterreich/ and https://de.wikipedia.org/wiki/Datum_Austria
     */
    private val transformGk34ToWgs84 = coordinateTranformFactory.createTransform(
        /* GK34 */ CRSFactory().createFromName("epsg:31256"), /* WGS84 */ CRSFactory().createFromName("epsg:4326")
    )
 
    fun transform(gk34: Gk34Dto): Wgs84Dto {
        val result = ProjCoordinate()
        transformGk34ToWgs84.transform(ProjCoordinate(gk34.x.toDouble(), gk34.y.toDouble()), result)
        return Wgs84Dto(result.y.toBigDecimal(), result.x.toBigDecimal

JavaScript

index.js

// JS version
// package.json contents:
// {
//   "name": "vienna-gis-to-wgs84",
//   "version": "1.0.0",
//   "main": "index.js",
//   "dependencies": {
//     "epsg": "^0.5.0",
//     "proj4": "^2.5.0"
//   }
// }
 
const proj4 = require('proj4');
const epsg = require('epsg');
 
/**
 * EPSG code 31256 = MGI Austria GK East, Gauss-Krüger M 34 (DKM), Greenwich
 * Cadastral plan in Eastern Austria (Irenental)
 * see https://www.esri-austria.at/service/projektionen-oesterreich/ and https://de.wikipedia.org/wiki/Datum_Austria
 */
const gk34ToWgs84 = coordinates => {
  const result = proj4(epsg['EPSG:31256'], 'WGS84', Object.assign({}, coordinates));
  console.log(coordinates.x + ', ' + coordinates.y + ' = ' + result.y + ', ' + result.x);
};
 
gk34ToWgs84({ x: 2950.77, y: 341754.91 });
gk34ToWgs84({ x: 5860.5, y: 342140.71 });
gk34ToWgs84({ x: -9587.52, y: 344411.47 });
// JS version
// package.json contents:
// {
//   "name": "vienna-gis-to-wgs84",
//   "version": "1.0.0",
//   "main": "index.js",
//   "dependencies": {
//     "epsg": "^0.5.0",
//     "proj4": "^2.5.0"
//   }
// }
 
const proj4 = require('proj4');
const epsg = require('epsg');
 
/**
 * EPSG code 31256 = MGI Austria GK East, Gauss-Krüger M 34 (DKM), Greenwich
 * Cadastral plan in Eastern Austria (Irenental)
 * see https://www.esri-austria.at/service/projektionen-oesterreich/ and https://de.wikipedia.org/wiki/Datum_Austria
 */
const gk34ToWgs84 = coordinates => {
  const result = proj4(epsg['EPSG:31256'], 'WGS84', Object.assign({}, coordinates));
  console.log(coordinates.x + ', ' + coordinates.y + ' = ' + result.y + ', ' + result.x);
};
 
gk34ToWgs84({ x: 2950.77, y: 341754.91 });
gk34ToWgs84({ x: 5860.5, y: 342140.71 });
gk34ToWgs84({ x: -9587.52, y: 344411.47 });
// JS version
// package.json contents:
// {
//   "name": "vienna-gis-to-wgs84",
//   "version": "1.0.0",
//   "main": "index.js",
//   "dependencies": {
//     "epsg": "^0.5.0",
//     "proj4": "^2.5.0"
//   }
// }
 
const proj4 = require('proj4');
const epsg = require('epsg');
 
/**
 * EPSG code 31256 = MGI Austria GK East, Gauss-Krüger M 34 (DKM), Greenwich
 * Cadastral plan in Eastern Austria (Irenental)
 * see https://www.esri-austria.at/service/projektionen-oesterreich/ and https://de.wikipedia.org/wiki/Datum_Austria
 */
const gk34ToWgs84 = coordinates => {
  const result = proj4(epsg['EPSG:31256'], 'WGS84', Object.assign({}, coordinates));
  console.log(coordinates.x + ', ' + coordinates.y + ' = ' + result.y + ', ' + result.x);
};
 
gk34ToWgs84({ x: 2950.77, y: 341754.91 });
gk34ToWgs84({ x: 5860.5, y: 342140.71 });
gk34ToWgs84({ x: -9587.52, y: 344411.47 });