I am reading the Proj4js User Guide but cannot quite grasp it. I import the library

<script src="lib/proj4js-combined.js"></script>


function init() {

    (...) // reading from GML string - one polygon in EPSG:3031
    var features = format.read(strGML);

    Proj4js.defs['EPSG:3031'] = '+proj=stere +lat_0=-90 +lat_ts=-71 +lon_0=0 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs';

    var source = new OpenLayers.Projection('EPSG:3031');
    var wgs84 = new OpenLayers.Projection('WGS84');

    OpenLayers.Projection.transform(features[0], source, wgs84);

    (...) // show polygon on map


Well, this doesn't work. Reading of GML string works fine as the polygon shows correctly on map if the coordinates are in WGS84 (and without the transformation, of course). But when I put in the string with other coordinates and try to transform it doesn't work. Is it possible to transform a polygon at once or do I have to do it point-by-point (and how would I do it)? Thanks

EDIT: My GML string loks like this:

<gml:featureMember xmlns:gml="http://www.opengis.net/gml xsi:schemaLocation="http://www.opengis.net/gml http://schemas.opengis.net/gml/3.1.1/profiles/gmlsfProfile/1.0.0/gmlsf.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <feature:feature xmlns:feature="http://example.com/feature">
                                 <gml:posList>591674.39 5022898.05 545682.5 4722908.1 571701.44 5322909.29 651691.25 5022904.6 591674.39 5022898.05

Should I, instead of

OpenLayers.Projection.transform(features[0], source, wgs84); 


OpenLayers.Projection.transform(features[0].geometry, source, wgs84);

or even something else?

3 Answers 3


Since you want to transform the coordinates of the feature, you need to apply the transformation to the feature geometry.

//like this:
features[0].geometry.transform(source, wgs84);

//instead of:
//OpenLayers.Projection.transform(features[0].geometry, source, wgs84);

Try this change in your code:

var source = new OpenLayers.Projection('EPSG:3031');
var wgs84 = new OpenLayers.Projection('EPSG:4326');

This must works.

  • Still nothing, can you look if I am transforming it correctly considering the GML structure? Commented May 26, 2014 at 22:24

I believe the second option is correct.

OpenLayers.Projection.transform(features[0].geometry, source, wgs84);
  • Are you able expand upon your Answer just a little? Normally, "about a paragraph is considered" the minimum here. Its current state was flagged up as being "low-quality because of its length and content".
    – PolyGeo
    Commented May 27, 2014 at 2:10
  • There is still no polygon showing. If I put the wgs84 coordinates and leave IN the transformation code, the polygon shows correctly which means the coordinates are not getting transformed at all (in both cases). Why? Commented May 27, 2014 at 19:01

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.