I am pulling WFS data into R and using gdalUtils::ogrinfo to look at the available layer names on a WFS server. Using the same url in QGIS, this is very fast and gives complete information. With gdalUtils::ogrinfo, either I get an error, or it is very slow.

This url works fine in QGIS (note: you will have to get your own Key and replace <YourKey> if you want test it)


The following code in R:

keyLINZ <- "<YourKey>"
dsnLINZ <- paste0("https://data.linz.govt.nz/services;key=", keyLINZ,"/wfs?")
ogrinfo(dsnLINZ, ro = TRUE, so = TRUE, verbose = TRUE)

Gives the following error:

 [1] "ERROR 4: Failed to read GeoJSON data"                                                                                                
 [2] "FAILURE:"                                                                                                                            
 [3] "Unable to open datasource `https://data.linz.govt.nz/services;key=<YourKey>/wfs?' with the following drivers."
list of all GDAL drivers
[1] 1
Warning message:
running command '"C:\OSGeo4W64\bin\ogrinfo.exe" -ro  -so  "https://data.linz.govt.nz/services;key=<YourKey>/wfs?" ' had status 1 

It still does not work by adding request=GetCapabilities to the end of the url (like other WFS urls that work).

However, it does work by adding SERVICE=WFS&REQUEST=GetCapabilities to the end of the url. But, it takes a very long time to list the layers. Also, it only lists the layer number and feature type (polygon, point, line). None of the other information that QGIS lists (Title, layer Name, Abstract, coordinate system) are listed, even with the q = TRUE option set.

How can I get the WFS information from the server in R similar to the info in QGIS and at the same speed?


gdalUtils developer here: gdalUtils isn't doing anything except wrapping the GDAL utilities in an R system() call, so the speed of execution is going to be inherent to the gdal executable, nothing specific to the R wrapper.

Your verbose output can help -- you should be able to copy/paste where it says "running command" into your Windows cmd window and try to figure out the error that way -- if it runs in your command window, that does tell me there may be something very weird going on. I suspect you will see the same error in your command window. Try to tweak that to make it work. One possibility is that your string has some odd characters that R doesn't like. Can you try the "manual" way and perhaps send me an offline message (you can get my contact info from the package help) if you want more help troubleshooting it?

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.