1

When I do this in JavaScript, using OpenLayers 3, it works:

    ol.proj.transform([153.47, -28.11], 'EPSG:4326', 'EPSG:3857');

I realize that this is because OpenLayers already knows both projections and is able to transform between them.

I want to be able to project from 'EPSG:28356' (GDA94 zone 56) to 'EPSG:3857'. So, I've installed and imported proj4js, got the appropriate string from http://spatialreference.org/ref/epsg/gda94-mga-zone-56/proj4js/ and it gives me:

"+proj=utm +zone=56 +south +ellps=GRS80 +towgs84=200,0,0,0,0,0,0 +units=m +no_defs"

So, in my code:

    proj4.defs("EPSG:28356", "+proj=utm +zone=56 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");

    let projection = new ol.proj.Projection({
      code: this.props.item.data.code,
      units: this.props.item.data.units,
      extent: this.props.item.data.extent
    });

    ol.proj.addProjection(projection);

    let c1 = [543100.508297332, 6880073.9025688];
    let c2 = ol.proj.transform(c1, 'EPSG:28356', 'EPSG:3857');

But this doesn't work. It didn't surprise me to get the exact same coordinates (somewhat rounded) back in c2, since the string states '+towgs84=0,0,0,0,0,0,0'.

I can also get the correct result from https://epsg.io/transform#s_srs=28356&t_srs=3857&x=543100.5082973&y=6880073.9025688 which would be [17080772.24, -3274771.77].

Does spatialreference.org give me the wrong proj4 string for this projection and if so, where to get a correct one? Or am I making some other mistake in trying to get this projection to work?

2
  • I just noticed myself that QGIS shows the same string in its Layer Spatial Reference System attribute for the location if I load it in there and it is able to render everything in the correct location, so apparently that's not the problem, or at least not the whole problem.
    – Grismar
    Commented Nov 10, 2017 at 4:38
  • Maybe related: gis.stackexchange.com/questions/120021/… . I'm not sure if you added the projection correctly.
    – AndreJ
    Commented Nov 10, 2017 at 8:34

1 Answer 1

1

I put together a quick JSFiddle to have a look at this.

The string you're using for Proj4 seems to work fine in my example, so I don't believe that is the problem.

I could reproduce your issue (ol.proj.transform returns same coord) by commenting out the proj4.defs(... line. Without knowing what's in the this.props.item.data object it's a little hard to confirm, but at a guess I'd say the projection you're adding to openlayers is overriding the proj4 based projection. Furthermore, I don't believe you need the openlayers definition as it should use the definition you've given to proj4.

tl;dr, the following should work.

proj4.defs("EPSG:28356", "+proj=utm +zone=56 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
let c1 = [543100.508297332, 6880073.9025688];
let c2 = ol.proj.transform(c1, 'EPSG:28356', 'EPSG:3857');

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.