WFS - cannot add layer (JSON error)


I’ve been trying to add some WFS’s in MapWindow - but I’m getting the same problem in each one, a JSON error and the layer is not shown.

For instance, the following:

            OgrDatasource ds = new OgrDatasource();
            string url = @",332709,461502,347119,EPSG:27700&srsName=EPSG:27700&outputFormat=GeoJSON";

            if (ds.Open(url))
               var numLayers = ds.LayerCount;
               if (numLayers > 0)
                   Console.WriteLine(ds.GetLayerName(0)); // This give correct response
                    var lyr = ds.GetLayer(0, false);
                    var lyrHandle = axMap1.AddLayer(lyr, true);

The above fails to add anything and after the “Open” call, although it returns, “True”, the dataset has a gdal error message of “JSON parsing error: unexpected character (at offset 0)”. I always get this same error even if I use a different wfs from a different provider. The stated driver name of the datasource comes through as “GeoJSONSeq”.

In the example above, I’ve added “GeoJSON” as the outputFormat, but I get the same error whatever I put as the outputFormat (or leave it out of the call).

How can I get the layer to be added?


Rob H

Hello @robhoney

I tried running the code you submitted, but I get the following error:

GDAL FAILURE: SSL certificate problem: self signed certificate in certificate chain

Is there more to this app that I am missing? (I realize that this may be something that is not accessible to me).


Hi @jerryfaust ,

I originally got that error too (I forgot). I had to add system environment variable “GDAL_HTTP_UNSAFESSL” with value = “YES”. This is actually another issue for me so I’d appreciate advice on how to get it to work without having to do this. I’m not sure if this is something to do with the version of GDAL MapWindow is using. I’ve read something about curl too - is this possible?

The data is open data so should work for you. You can either set the system environment variable as above, or you can access via “http” rather than “https”.

Long term I don’t think it will be supported (http), so I’m also keen to solve the certificate chain problem.


Rob H

Hello Rob.

Running your code above, but using http rather than https, and removing the GeoJSON reference (&outputFormat=GeoJSON), I am able to load the map, as shown:

and the only GDAL message I got was being unable to open the mw_styles table, which it says doesn’t exist.

Using the GeoJSON reference, GetLayerName returns “file”, and inspecting the lyr variable, it says that it is using the GeoJSON driver. It looks like I get a small speck in the middle of the map that I cannot zoom in to, but I do not get a JSON parsing error.

Excluding the GeoJSON reference, GetLayerName returns “Flood_Map_for_Planning_Rivers_and_Sea_Flood_Zone_2”, and the lyr variable tells me that it is using the GML driver.

The only map setting that I made prior to your code was to set the TileProvider = ProviderNone.

I don’t know what this all means for your experience. Could there be other settings or conditions in your environment that are affecting the load?



I noticed that the coordinates looked wrong (too close to [0, 0]), and noticed that the URL is specifying EPGS of 27700. So as a test, I added the following code prior to loading the layer:

GeoProjection gp = new GeoProjection();
axMap1.GeoProjection = gp;

and then I get the following position. Hopefully that’s correct.