rOpenGov / fmi

Finnish Meteorological Institute open data API R client
Other
10 stars 7 forks source link

Package fmi is not up to date? #6

Closed Velimt closed 7 years ago

Velimt commented 8 years ago

I tried to use the fmi package to get FMI weather data following an example given by @jlehtoma. However, the atached script gives an error message which I cannot interpret. However, the commands manage to open th url, and read in XML files in a temp folder, and it is possible to parse the files with the xml package (with hard work though). It would be really nice, if the package would do all that for you, and I hope that somebody could update the fmi package to work fluently.

Veli-Matti Taavitsainen Helsinki Metropolia University of Applied Sciences test.txt (EDIT: code pasted below by @jlehtoma)

library(dplyr)
library(devtools)
library(rwfs)
library(fmi)

stations <- fmi_weather_stations()

kiutakongas.station <- stations[99,]

apiKey <- '' #oma API-avaimeni

fmisid.kiuta <- kiutakongas.station$FMISID

request <- FMIWFSRequest$new(apiKey=apiKey)

request$setParameters(request="getFeature",
                      storedquery_id="fmi::observations::weather::daily::timevaluepair",
                      parameters="rrday,snow,tday,tmin,tmax")

client <- FMIWFSClient$new(request=request)

response <- client$getDailyWeather(startDateTime="2014-01-01T00:00:00Z",
                                   endDateTime="2014-01-01T00:00:00Z",
                                   fmisid=fmisid.kiuta)

request <- FMIWFSRequest$new(apiKey=apiKey)

request$setParameters(request="getFeature",
                      storedquery_id="fmi::observations::weather::daily::timevaluepair",
                      parameters="rrday,snow,tday,tmin,tmax")

client <- FMIWFSClient$new(request=request)

response <- client$getDailyWeather(variables = c("rrday", "snow", "tday", "tmin", "tmax"),
                                   startDateTime="2014-01-01T00:00:00Z",
                                   endDateTime="2014-01-01T00:00:00Z",
                                   fmisid=fmisid.Kaisaniemi)
jlehtoma commented 8 years ago

Thanks for the issue @Velimt , we'll look into this and get back to you.

torsti commented 8 years ago

I think the main advantage of having a package like this would come from not having to necessarily deal with FMI's xml output. Maybe we could build something on top of the xml2 package?!

jlehtoma commented 8 years ago

Agreed, we absolutely do not want to deal with the XML directly. The XML served over from the FMI API is actually Geographic Markup Language (GML). fmi-package uses another R package called rwfs to access the the data which is served over a OGC WFS. rfws uses the R-bindings to GDAL (or OGR more specifically) to read in the data, so there is no need to parse the XML by hand. GDAL's GML driver and the dialect used by FMI were causing some headache at some point, hopefully these have been sorted out by now.

torsti commented 8 years ago

Right. Maybe I should look more closely at the code before I comment too much ;)

torsti commented 8 years ago

Except for the variable fmisid.Kaisaniemi not being defined, I don't get any errors when running the code above.

There seem to be some other issues, like the date only being associated with the first variable, but that seems minor.

jlehtoma commented 8 years ago

The correct value for fmisid.Kaisaniemi is 100971. After putting that in, works fine for me as well. @Velimt : what was the exact error message you got?

Velimt commented 8 years ago

It doesn't work for me.

Here's the error message:

ogr2ogr -f GML -splitlistfields C:\Users\velimt\AppData\Local\Temp\RtmpQH9eAd\file127c7a232d0f C:\Users\velimt\AppData\Local\Temp\RtmpQH9eAd\file127c3130576c PointTimeSeriesObservation Error in convertOGR(sourceFile = private$cachedResponseFile, layer = layer, : Conversion failed. In addition: Warning message: running command 'ogr2ogr -f GML -splitlistfields C:\Users\velimt\AppData\Local\Temp\RtmpQH9eAd\file127c7a232d0f C:\Users\velimt\AppData\Local\Temp\RtmpQH9eAd\file127c3130576c PointTimeSeriesObservation' had status 127

and here's the code:

library(dplyr) library(devtools) library(rwfs) library(fmi)

a <- fmi_weather_stations()

Kaisaniemi <- a[24,]

apiKey <- '0253711c-056f-439b-af9d-a5a3a2920faf'

fmisid.Kaisaniemi <- Kaisaniemi$FMISID

startDateTime <- "2015-01-01" endDateTime <- "2015-12-31"

request <- FMIWFSRequest$new(apiKey=apiKey)

request$setParameters(request="getFeature", storedquery_id="fmi::observations::weather::daily::timevaluepair", parameters="rrday,snow,tday,tmin,tmax")

client <- FMIWFSClient$new(request=request)

response <- client$getDailyWeather(startDateTime=startDateTime, endDateTime=endDateTime, fmisid=fmisid.Kaisaniemi)


From: Joona Lehtomäki [notifications@github.com] Sent: Sunday, June 05, 2016 9:16 PM To: rOpenGov/fmi Cc: Veli-Matti Taavitsainen; Mention Subject: Re: [rOpenGov/fmi] Package fmi is not up to date? (#6)

The correct value for fmisid.Kaisaniemi is 100971. After putting that in, works fine for me as well. @Velimt<redir.aspx?REF=W3eXD912URTyIHWrZZD63CdShmcZMKOL1IgYSuiCUWe4-ZKec4_TCAFodHRwczovL2dpdGh1Yi5jb20vVmVsaW10> : what was the exact error message you got?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<redir.aspx?REF=9Bs1Y938ozfvp0ltgMGpIWI0OBdKN3wtjUvTle4lQTe4-ZKec4_TCAFodHRwczovL2dpdGh1Yi5jb20vck9wZW5Hb3YvZm1pL2lzc3Vlcy82I2lzc3VlY29tbWVudC0yMjM4MjgyMzc.>, or mute the thread<redir.aspx?REF=W69Kc4cjhQ_WoBSgG23RhyvGD4-vkADcQzTgJIEuKfe4-ZKec4_TCAFodHRwczovL2dpdGh1Yi5jb20vbm90aWZpY2F0aW9ucy91bnN1YnNjcmliZS9BUzBBTFpMdDZXMkRYWjNlQ2FJRWt0R2F4S01ZU05HLWtzNXFJeEpyZ2FKcFpNNEl1RnVm>.

jlehtoma commented 8 years ago

Still works for me. I suspect this is an issue with with ogr2ogr (GDAL) rather than fmi. The warning message

running command 'ogr2ogr -f GML [...] had status 127`

hints that ogr2ogr command is not found in your system. I suggest you look at the fmi tutorial's installation section for Windows and see if ogr2ogr can be found with the required options (-splitlistfields and -explodecollections).

ouzor commented 8 years ago

@Velimt: Are you perhaps running RStudio? I recall vaguely having a similar problem with RStudio and fmi package. I had to open RStudio with some specific command from terminal, otherwise fmi package didn't work. Can you try R without RStudio and see if the same problem occurs?

On Wed, Jun 8, 2016 at 11:08 AM, Velimt notifications@github.com wrote:

It doesn't work for me.

Here's the error message:

ogr2ogr -f GML -splitlistfields C:\Users\velimt\AppData\Local\Temp\RtmpQH9eAd\file127c7a232d0f C:\Users\velimt\AppData\Local\Temp\RtmpQH9eAd\file127c3130576c PointTimeSeriesObservation Error in convertOGR(sourceFile = private$cachedResponseFile, layer = layer, : Conversion failed. In addition: Warning message: running command 'ogr2ogr -f GML -splitlistfields C:\Users\velimt\AppData\Local\Temp\RtmpQH9eAd\file127c7a232d0f C:\Users\velimt\AppData\Local\Temp\RtmpQH9eAd\file127c3130576c PointTimeSeriesObservation' had status 127

and here's the code:

library(dplyr) library(devtools) library(rwfs) library(fmi)

a <- fmi_weather_stations()

Kaisaniemi <- a[24,]

apiKey <- '0253711c-056f-439b-af9d-a5a3a2920faf'

fmisid.Kaisaniemi <- Kaisaniemi$FMISID

startDateTime <- "2015-01-01" endDateTime <- "2015-12-31"

request <- FMIWFSRequest$new(apiKey=apiKey)

request$setParameters(request="getFeature", storedquery_id="fmi::observations::weather::daily::timevaluepair", parameters="rrday,snow,tday,tmin,tmax")

client <- FMIWFSClient$new(request=request)

response <- client$getDailyWeather(startDateTime=startDateTime, endDateTime=endDateTime, fmisid=fmisid.Kaisaniemi)


From: Joona Lehtomäki [notifications@github.com] Sent: Sunday, June 05, 2016 9:16 PM To: rOpenGov/fmi Cc: Veli-Matti Taavitsainen; Mention Subject: Re: [rOpenGov/fmi] Package fmi is not up to date? (#6)

The correct value for fmisid.Kaisaniemi is 100971. After putting that in, works fine for me as well. @Velimt<redir.aspx?REF=W3eXD912URTyIHWrZZD63CdShmcZMKOL1IgYSuiCUWe4-ZKec4_TCAFodHRwczovL2dpdGh1Yi5jb20vVmVsaW10> : what was the exact error message you got?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<redir.aspx?REF=9Bs1Y938ozfvp0ltgMGpIWI0OBdKN3wtjUvTle4lQTe4-ZKec4_TCAFodHRwczovL2dpdGh1Yi5jb20vck9wZW5Hb3YvZm1pL2lzc3Vlcy82I2lzc3VlY29tbWVudC0yMjM4MjgyMzc.>, or mute the thread<redir.aspx?REF=W69Kc4cjhQ_WoBSgG23RhyvGD4-vkADcQzTgJIEuKfe4-ZKec4_TCAFodHRwczovL2dpdGh1Yi5jb20vbm90aWZpY2F0aW9ucy91bnN1YnNjcmliZS9BUzBBTFpMdDZXMkRYWjNlQ2FJRWt0R2F4S01ZU05HLWtzNXFJeEpyZ2FKcFpNNEl1RnVm>.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rOpenGov/fmi/issues/6#issuecomment-224518614, or mute the thread https://github.com/notifications/unsubscribe/ABK-iusa1rObxS4DBmugbrGjYcARxoaEks5qJnh0gaJpZM4IuFuf .

Velimt commented 8 years ago

I normally use RStudio for convenience, but I already tried with R (3.02) and got the same error message. I have also installed rgdal, and all other packages mentioned.

Next I'll check ogr2ogr followinf Joonas suggestion.


From: Juuso Parkkinen [notifications@github.com] Sent: Wednesday, June 08, 2016 11:33 AM To: rOpenGov/fmi Cc: Veli-Matti Taavitsainen; Mention Subject: Re: [rOpenGov/fmi] Package fmi is not up to date? (#6)

@Velimt: Are you perhaps running RStudio? I recall vaguely having a similar problem with RStudio and fmi package. I had to open RStudio with some specific command from terminal, otherwise fmi package didn't work. Can you try R without RStudio and see if the same problem occurs?

On Wed, Jun 8, 2016 at 11:08 AM, Velimt notifications@github.com wrote:

It doesn't work for me.

Here's the error message:

ogr2ogr -f GML -splitlistfields C:\Users\velimt\AppData\Local\Temp\RtmpQH9eAd\file127c7a232d0f C:\Users\velimt\AppData\Local\Temp\RtmpQH9eAd\file127c3130576c PointTimeSeriesObservation Error in convertOGR(sourceFile = private$cachedResponseFile, layer = layer, : Conversion failed. In addition: Warning message: running command 'ogr2ogr -f GML -splitlistfields C:\Users\velimt\AppData\Local\Temp\RtmpQH9eAd\file127c7a232d0f C:\Users\velimt\AppData\Local\Temp\RtmpQH9eAd\file127c3130576c PointTimeSeriesObservation' had status 127

and here's the code:

library(dplyr) library(devtools) library(rwfs) library(fmi)

a <- fmi_weather_stations()

Kaisaniemi <- a[24,]

apiKey <- '0253711c-056f-439b-af9d-a5a3a2920faf'

fmisid.Kaisaniemi <- Kaisaniemi$FMISID

startDateTime <- "2015-01-01" endDateTime <- "2015-12-31"

request <- FMIWFSRequest$new(apiKey=apiKey)

request$setParameters(request="getFeature", storedquery_id="fmi::observations::weather::daily::timevaluepair", parameters="rrday,snow,tday,tmin,tmax")

client <- FMIWFSClient$new(request=request)

response <- client$getDailyWeather(startDateTime=startDateTime, endDateTime=endDateTime, fmisid=fmisid.Kaisaniemi)


From: Joona Lehtomäki [notifications@github.com] Sent: Sunday, June 05, 2016 9:16 PM To: rOpenGov/fmi Cc: Veli-Matti Taavitsainen; Mention Subject: Re: [rOpenGov/fmi] Package fmi is not up to date? (#6)

The correct value for fmisid.Kaisaniemi is 100971. After putting that in, works fine for me as well. @Velimt<redir.aspx?REF=W3eXD912URTyIHWrZZD63CdShmcZMKOL1IgYSuiCUWe4-ZKec4_TCAFodHRwczovL2dpdGh1Yi5jb20vVmVsaW10> : what was the exact error message you got?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<redir.aspx?REF=9Bs1Y938ozfvp0ltgMGpIWI0OBdKN3wtjUvTle4lQTe4-ZKec4_TCAFodHRwczovL2dpdGh1Yi5jb20vck9wZW5Hb3YvZm1pL2lzc3Vlcy82I2lzc3VlY29tbWVudC0yMjM4MjgyMzc.>, or mute the thread<redir.aspx?REF=W69Kc4cjhQ_WoBSgG23RhyvGD4-vkADcQzTgJIEuKfe4-ZKec4_TCAFodHRwczovL2dpdGh1Yi5jb20vbm90aWZpY2F0aW9ucy91bnN1YnNjcmliZS9BUzBBTFpMdDZXMkRYWjNlQ2FJRWt0R2F4S01ZU05HLWtzNXFJeEpyZ2FKcFpNNEl1RnVm>.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rOpenGov/fmi/issues/6#issuecomment-224518614, or mute the thread https://github.com/notifications/unsubscribe/ABK-iusa1rObxS4DBmugbrGjYcARxoaEks5qJnh0gaJpZM4IuFuf .

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<redir.aspx?REF=8L1JBdZpsTAM0HuP089egLIywS4hl6Z3-S1oQhAJCES3hpnKd4_TCAFodHRwczovL2dpdGh1Yi5jb20vck9wZW5Hb3YvZm1pL2lzc3Vlcy82I2lzc3VlY29tbWVudC0yMjQ1MjQyMTU.>, or mute the thread<redir.aspx?REF=fAJzWIrbL9Dj8XWPdte8V6_PGqccjgD8vMtoZaMV_ta3hpnKd4_TCAFodHRwczovL2dpdGh1Yi5jb20vbm90aWZpY2F0aW9ucy91bnN1YnNjcmliZS9BUzBBTGF4N1ZlZVktUWhpdlBxTHhTYVVwRlhPQmJObGtzNXFKbjVnZ2FKcFpNNEl1RnVm>.

Velimt commented 8 years ago

The problem is in ogr2ogr. Unfortunately I encountered some problems in the installation following the instructions in the link given. In addition, to me the installation and usage of the package seems unnecessarily complicated and user unfriendly. The good think is that in spite of the error the commands save the needed xml file in a temp folder, and I had no problems in retrieving the data using the xml package. So for the time being I'll work in this way.

The commands reading in the xml file for rain and temperature:

getTime <- function(x) {x[[1]][[1]]} getVal <- function(x) {x[[1]][[2]]}

KN15 <- xmlParse('file1b3c8a419e') KN15list <- xmlToList(KN15) # first level is the series RainList <- KN15list[[1]][[1]][['result']][[1]] Rain <- as.numeric(sapply(RainList[1:355],getVal)) i <- which(Rain==-1) Rain[i] <- 0 TempList <- KN15list[[3]][[1]][['result']][[1]] Temp <- as.numeric(sapply(TempList[1:355],getVal)) TimeList <- KN15list[[3]][[1]][['result']][[1]] Time <- strptime(substr(sapply(RainList[1:355],getTime),1,10), '%Y-%m-%d') time <- as.numeric(Time)/3600/24 time <- time-time[1]+1 plot(Time,Temp,type='l') grid()

plot(Time,Rain,type='l') grid()


From: Joona Lehtomäki [notifications@github.com] Sent: Wednesday, June 08, 2016 11:18 AM To: rOpenGov/fmi Cc: Veli-Matti Taavitsainen; Mention Subject: Re: [rOpenGov/fmi] Package fmi is not up to date? (#6)

Still works for me. I suspect this is an issue with with ogr2ogr (GDAL) rather than fmi. The warning message

running command 'ogr2ogr -f GML [...] had status 127`

suggests that ogr2ogr command is not found in your system. I suggest you look at the fmi tutorial's installation section for Windows<redir.aspx?REF=C_zpMcPhsUx8Sr9dXdr5HjMenR6NKI1cKqDZkb6OzzG2tYy2eY_TCAFodHRwczovL2dpdGh1Yi5jb20vck9wZW5Hb3YvZm1pL2Jsb2IvbWFzdGVyL3ZpZ25ldHRlcy9mbWlfdHV0b3JpYWwubWQjd2luZG93cw..> and see if ogr2ogr can be found with the required options (-splitlistfields and -explodecollections).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<redir.aspx?REF=h8NK3penGvbWg6BhLarXwprKo-6_xyvtxoGL_VOuALG2tYy2eY_TCAFodHRwczovL2dpdGh1Yi5jb20vck9wZW5Hb3YvZm1pL2lzc3Vlcy82I2lzc3VlY29tbWVudC0yMjQ1MjA3NDg.>, or mute the thread<redir.aspx?REF=O_BtIAnxdZy05PXhIhQdzwBCCyiOwPjRvoPmJrIrxia2tYy2eY_TCAFodHRwczovL2dpdGh1Yi5jb20vbm90aWZpY2F0aW9ucy91bnN1YnNjcmliZS9BUzBBTGI4TmtsX05KQnM0ajh6Y1NkV1FjUnRWNk1MRmtzNXFKbnJZZ2FKcFpNNEl1RnVm>.

jlehtoma commented 8 years ago

The problem is in ogr2ogr. Unfortunately I encountered some problems in the installation following the instructions in the link given.

Can you specify what these problems are? This could be useful for anyone struggling withe the same problem.

In addition, to me the installation and usage of the package seems unnecessarily complicated and user unfriendly.

Thanks for the feedback, but unfortunately there really seems to be no way around it. Technically, GDAL (OGR) is the only way we are aware of reading in GML, which is in itself rather convoluted format. Having the FMI serving data e.g. in geoJSON would make things a lot easier, but this is really a decision out of our hands. In case you think e.g. the fmi installation instructions could be improved, we're more than happy to hear any suggestions.

Further, Windows is somewhat notorious for getting certain tools (including GDAL) to work and none of us work primarily on Windows. That's why any feedback regarding especially Windows is valuable.

The good think is that in spite of the error the commands save the needed xml file in a temp folder, and I had no problems in retrieving the data using the xml package. So for the time being I'll work in this way.

Great that you can get forward with working with XML. For fmi, one the key features is to be able to get spatial data directly for which GDAL is great (if it works).

torsti commented 8 years ago

Is there any way of working with the GDAL/OGR API at in R, for example with rgdal's readOGR, without having to use ogr2ogr or other tools? I guess this interaction takes place in rwfs and not fmi or is readOGR already built on top of ogr2ogr?

jlehtoma commented 8 years ago

Currently rwfs indeed downloads the XML (GML) file locally and then uses ogr2ogr to work on it. GDAL/OGR does have a WFS-driver, which in theory could be used to read GML directly. This would get rid of the need to use ogr2ogr. As so long as readOGR() supports the necessary options now passed on to ogr2ogr, this could be an option. @statguy any comments?

@torsti in case you want to give a stab, could you open an issue with rwfs?

torsti commented 8 years ago

@jlehtoma I'm a bit overloaded until midsummer, so I'll open the issue once (if) I actually have time to look into rwfs properly.

jlehtoma commented 8 years ago

Great, @torsti . I'm closing this issue since it's related to GDAL/OGR installation rather than fmi. @Velimt feel free to add information on your problems though.

jlehtoma commented 7 years ago

Coming back to this, rwfs README does state the following:

Due to limited support for WFS 2.x in the rgdal package, which the rwfs package depends on, data in WFS 2.x is accessible only via downloading the data first and thus no streaming can be used (at least in some services).

Should check what are the current capabilities of streaming data directly from FMI.

jlehtoma commented 7 years ago

I'm reopening this as I just got an email reporting the same issue with Mac. Apparently GDAL (i.e. ogr2ogr) is found on command-line, but not when called from R (prompt or RStudio).

@ouzor : can you remember what it took to get things working on Mac?

ouzor commented 7 years ago

Try this for opening RStudio from command line on OSX: 'open -a rstudio'

On Mon, Sep 5, 2016 at 3:55 PM, Joona Lehtomäki notifications@github.com wrote:

Reopened #6 https://github.com/rOpenGov/fmi/issues/6.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rOpenGov/fmi/issues/6#event-778314659, or mute the thread https://github.com/notifications/unsubscribe-auth/ABK-itBe8R33W1Ms_c0m3xQuxF_nnMHUks5qnBFNgaJpZM4IuFuf .

torsti commented 7 years ago

Is this definitely just OS X specific? There could be some temporary workaround for setting the path. Otherwise we probably need to figure issue #9 out first. In case dropping the ogr2ogr dependency is possible, we might then just want to find the time to rework the package and not fix this?!

jlehtoma commented 7 years ago

Thanks @ouzor , open -a did the trick. Apparently the GDAL installation path on Mac is not standard (i.e. can vary) so it needs to be set correctly. Will have to update the installation instructions.

@torsti : Resolving #9 would be great as it would do away with the configuration of local ogr2ogr. I suggest making this a priority for now.

jlehtoma commented 7 years ago

Note that there has been some progress in removing the ogr2ogr steps from rwfs, see https://github.com/rOpenGov/rwfs/issues/5

EemeIi commented 7 years ago

I am facing the same problem with ogr2ogr on Windows 10, tried both with RStudio and with plain R. Any hints on how to get things working? The tutorial didn't seem to include any Windows-specific installation section any more.

jlehtoma commented 7 years ago

@EemeIi : try installing rwfs (fmi dependency) from develop branch:

devtools::install_github("ropengov/rwfs", ref="develop")

This will do away with ogr2ogr problems on Windows. Currently this approach is a bit inconvenient, but this will be fixed soon.

EemeIi commented 7 years ago

That seems to fix it, thanks @jlehtoma

jlehtoma commented 7 years ago

@EemeIi , since you are on Windows 10, could you also post here the output of the following command:

library(rgdal)

Also, which version of R are you using? I'm trying to figure out this issue with rwfs, you can also comment directly on that issue.

EemeIi commented 7 years ago

@jlehtoma: Loading required package: sp rgdal: version: 1.2-5, (SVN revision 648) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 2.0.1, released 2015/09/15 Path to GDAL shared files: C:/Users/Leppis/Documents/R/win-library/3.2/rgdal/gdal GDAL does not use iconv for recoding strings. Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491] Path to PROJ.4 shared files: C:/Users/Leppis/Documents/R/win-library/3.2/rgdal/proj Linking to sp version: 1.2-4 Warning messages: 1: package ‘rgdal’ was built under R version 3.2.5 2: package ‘sp’ was built under R version 3.2.5

with R 3.2.4 Revised "Very Secure Dishes".

jlehtoma commented 7 years ago

Thanks @EemeIi ! Weird, that seems to be the same version of rgdal I've been testing with on Windows. If you don't mind, could you still post the output of the following commands?

library(rgdal)
ogrDrivers()$name

and

sessionInfo()
EemeIi commented 7 years ago

@jlehtoma here you go:

library(rgdal) Loading required package: sp rgdal: version: 1.2-5, (SVN revision 648) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 2.0.1, released 2015/09/15 Path to GDAL shared files: C:/Users/Leppis/Documents/R/win-library/3.2/rgdal/gdal GDAL does not use iconv for recoding strings. Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491] Path to PROJ.4 shared files: C:/Users/Leppis/Documents/R/win-library/3.2/rgdal/proj Linking to sp version: 1.2-4 Warning messages: 1: package ‘rgdal’ was built under R version 3.2.5 2: package ‘sp’ was built under R version 3.2.5 ogrDrivers()$name [1] "AeronavFAA" "ARCGEN" "AVCBin" "AVCE00" "BNA" "CSV"
[7] "DGN" "DXF" "EDIGEO" "ESRI Shapefile" "Geoconcept" "GeoJSON"
[13] "Geomedia" "GeoRSS" "GML" "GPKG" "GPSBabel" "GPSTrackMaker" [19] "GPX" "HTF" "Idrisi" "JML" "KML" "MapInfo File"
[25] "Memory" "MSSQLSpatial" "ODBC" "ODS" "OGR_GMT" "OGR_PDS"
[31] "OGR_SDTS" "OGR_VRT" "OpenAir" "OpenFileGDB" "OSM" "PCIDSK"
[37] "PDF" "PGDUMP" "PGeo" "REC" "S57" "SEGUKOOA"
[43] "SEGY" "Selafin" "SQLite" "SUA" "SVG" "SXF"
[49] "TIGER" "UK .NTF" "Walk" "WAsP" "VFK" "XLSX"
[55] "XPlane"
sessionInfo() R version 3.2.4 Revised (2016-03-16 r70336) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)

locale: [1] LC_COLLATE=Finnish_Finland.1252 LC_CTYPE=Finnish_Finland.1252 LC_MONETARY=Finnish_Finland.1252 [4] LC_NUMERIC=C LC_TIME=Finnish_Finland.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] rgdal_1.2-5 sp_1.2-4

loaded via a namespace (and not attached): [1] tools_3.2.4 grid_3.2.4 lattice_0.20-33

jlehtoma commented 7 years ago

Thanks again @EemeIi . As expected, your rgdal installation does not have the WFS driver enabled either. I'm not sure how the new version of rwfs fixed your issue, but could test the following code and report whether you run into any errors. It tries to read a feature over WFS from the URL below (this is the query response) directly using rgdal:

library(rwfs)

base_url <- "http://demo.mapserver.org/cgi-bin/wfs?"

TestWFSStreamingRequest <-  R6::R6Class(
  "TestWFSStreamingRequest",
  inherit = WFSStreamingRequest,
  private = list(
    getURL = function() {
      # Use a public WFS (1.0.0/1.1.0) server to query world cities
      url <- paste0(base_url, private$getParametersString())
      return(url)
    }
  ),
  public = list(
    getDataSource = function() {
      return(private$getURL())
    }
  )
)

streaming_request <- TestWFSStreamingRequest$new()
streaming_request$getFeature(version = "1.1.0",
                             typeNames = "cities",
                             maxFeatures = 10)
# Create the client instance
streaming_client <- WFSStreamingClient$new(request = streaming_request)
streaming_layers <- streaming_client$listLayers()
EemeIi commented 7 years ago

@jlehtoma: Direct copy paste gave me:

`Streaming layers directly from the data source http://demo.mapserver.org/cgi-bin/wfs?service=WFS&version=1.1.0&request=GetFeature&typeName=cities&maxFeatures=10

Error in rgdal::ogrListLayers(dsn = dataSource) : Cannot open data source

Warning message:

In private$.listLayers(dataSource = private$request$getDataSource()) : Unable to connect to the data source or error in query result.`

jlehtoma commented 7 years ago

Thanks for the additional help. As suspected, the WFS driver is not enabled.