1

I have a OpenLayers vector with a single feature [0]. It's coordinates are in the map projection (EPSG:3413) and I want them in WGS84 (EPSG:4326) decimal degrees. I have the following code which executes with no errors.

    // Transform the polygon to WGS84 (EPSG:4326)
        polybound.features[0].geometry.transform(new OpenLayers.Projection("EPSG:3413"),new OpenLayers.Projection("EPSG:4326"));

        // Get the extent/vertices of the polygon drawn
        var polyBounds = polybound.features[0].geometry.getVertices(); alert(polyBounds);
        var polyExt = polybound.features[0].geometry.getBounds(); alert(polyExt);

However both the alerts show the untransformed coordinates.

Eg:

alert(polyBounds);

POINT(-2486558.28125 -1947299.71875),POINT(-4121511.40625 -1737690.34375),POINT(-3555566.09375 -2722854.40625)

alert(polyExt);

-4121511.40625,-2722854.40625,-2486558.28125,-1737690.34375

How do I get the vector feature coordinates to transform correctly?

  • Are you using the Proj4js library? Have you referred to the proper projection in Proj4 format? – Devdatta Tengshe Apr 27 '13 at 16:30
  • @Davdatta Tengshe I'm not using the Proj4js library, rather whatever is build into OpenLayers. The (new OpenLayers.Projection("EPSG:3413")) works because thats what my map frame is in. – Kyle Purdon Apr 28 '13 at 0:33
1

Please refer to the OpenLayer Docs for OpenLayers.Projection. The docs state the following:

By default, OpenLayers ships with the ability to transform coordinates between geographic (EPSG:4326) and web or spherical mercator (EPSG:900913 et al.) coordinate reference systems....

Additional transforms may be added by using the proj4js library. If the proj4js library is included, the transform method will work between any two coordinate reference systems with proj4js definitions.

So you need to refer to the Proj4JS library and have your projection file for EPSG:3413.

You should read this User Guide. You can download the library from here: Downloads. You will also need the file for your projection in Proj4 format. You can download that from here: Spatial reference.org

  • Thank you. Got it working now. I'll update my question with the actual solution later today. – Kyle Purdon May 1 '13 at 16:33
0

@kpurdon, there is no problem with your code but you have to know that transforming is not overwriting to existed feature. so try the following code:

alert(polybound.features[0].geometry.transform(new OpenLayers.Projection("EPSG:3413"),new OpenLayers.Projection("EPSG:4326")));

i hope it helps you...

  • How can I write the transformed feature to a new feature so I can access the vertices and bounds in the transformed projection? – Kyle Purdon Apr 26 '13 at 20:23
  • Also, the alert you gave still printed the un-transformed coordinates. – Kyle Purdon Apr 26 '13 at 20:25
0

Try this as same was my case:

var geographic = new OpenLayers.Projection("EPSG:4326");
var mercator = new OpenLayers.Projection("EPSG:3413");

var polygon= polybound.feature.geometry;
    //alert(polygon);
    var bounds=polygon.getBounds();
    var poly = polygon.transform(
            mercator,geographic 
        );
alert(poly);

Hope will works!

  • I get the same un-transformed results using this method. – Kyle Purdon Apr 28 '13 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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