0

When requesting featureInfo from MapServer using getGetFeatureInfoUrl() of OL3 lib

var req_url = the_layer.getSource().getGetFeatureInfoUrl(
  evt.coordinate,
  map.getView().getResolution(),
  map.getView().getProjection(), //4326
  {
     'INFO_FORMAT': 'application/vnd.ogc.gml',
  }
);

it returns response in which the coordinates X and Y are in coorect order but after parsing the response theu are flipped:

$.ajax(req_url, {
            async: false
          })
          .done(function(resp){
            //console.log(resp);
            WMSfeatures = parser.readFeatures(resp);
            console.log(WMSfeatures);
           });

Coordinates in response from mapserver:

[[223.745,250.638],[232.028,255.22],[229.376,264.126]] (in EPSG:4326)

Parsed response:

[[250.638,223.745],[255.22,232.028],[264.126,229.376]] (in EPSG:4326)

What is wrong here?

1

If you ever need to flip coordinates.. one way is to send it to postgis, that have a function for it:

//prepare GeoJson parser
var parser_GJ = new ol.format.GeoJSON();
//prepare GeoJson String
var GJ_geom_str = parser_GJ.writeGeometry(WMSfeatures[0].getGeometry()); 
//Send to PHP function using AJAX (returns GeoJSON String)
var GJ_geom = Utils.flipCoordinates(GJ_geom_str);
//Set geometry for the feature
WMSfeatures[0].setGeometry(parser_GJ.readGeometry(GJ_geom));

The PHP snippet is following:

function flip_coordinates($GJ_geom){
  $sql = "SELECT ST_AsGeoJSON(ST_FlipCoordinates(ST_Force_2D(ST_GeomFromGeoJSON('$GJ_geom')))) as flipped";
  return dibi::fetchSingle($sql);
}

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.