Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
    
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. –  kpurdon Apr 28 '13 at 0:33

3 Answers 3

up vote 0 down vote accepted

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

share|improve this answer
    
Thank you. Got it working now. I'll update my question with the actual solution later today. –  kpurdon May 1 '13 at 16:33

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!

share|improve this answer
    
I get the same un-transformed results using this method. –  kpurdon Apr 28 '13 at 0:49

@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...

share|improve this answer
    
How can I write the transformed feature to a new feature so I can access the vertices and bounds in the transformed projection? –  kpurdon Apr 26 '13 at 20:23
    
Also, the alert you gave still printed the un-transformed coordinates. –  kpurdon Apr 26 '13 at 20:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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