I am trying to export GeoJSON for a list of feature objects using OpenLayers 2. The features are in EPSG:3857 projection and I would like to convert all geometries to EPSG:4326. I am perfectly capable of doing this by looping through the features like so:

var construccionFeatures = layerCONSTRUCCION.features;
  for (var i = 0; i < construccionFeatures.length; i++) {
    construccionFeatures[i].geometry = construccionFeatures[i].geometry.transform('EPSG:3857', 'EPSG:4326');
var json = new OpenLayers.Format.GeoJSON().write(construccionFeatures);

I just would like to know whether there is a quicker solution. Is it possible to directly transform all geometries in the list in one go? Speed is key here since I run this process after a WFS layer loadend event in order to feed the GeoJSON to the OSMBuildings library.


This issue has resolved itself. I switched to OpenLayers 3 since asking. Data and feature projection can now be passed as options to the read and write function of the GeoJSON format class.

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.