rOpenGov / fmi

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

Error in CPL_read_ogr() #28

Closed ilarischeinin closed 6 years ago

ilarischeinin commented 6 years ago

I'm not sure if this is really about fmi (or rather rwfs), but I get the following error when I try to run the code from the tutorial:

library(fmi)
apiKey <- "" # with a valid key
request <- FMIWFSRequest$new(apiKey = apiKey)
request$setParameters(request = "getFeature",
                      storedquery_id = "fmi::observations::weather::daily::timevaluepair",
                      starttime = "2014-01-01T00:00:00Z",
                      endtime = "2014-01-01T00:00:00Z",
                      bbox = "19.09,59.3,31.59,70.13",
                      parameters = "rrday,snow,tday,tmin,tmax")
client <- FMIWFSClient$new(request=request)
layers <- client$listLayers()
response <- client$getLayer(layer=layers[1], parameters=list(splitListFields=TRUE))
Error in CPL_read_ogr(dsn, layer, as.character(options), quiet, type,  : 
  Not compatible with STRSXP: [type=list].
Error in private$.getLayer(dataSource = sourceFile, layer = layer, ...) : 
  Fatal error.

The two files from the temp directory are attached (I added a ".txt" suffix so that GitHub would accept them).

Below is my sessionInfo(). Both fmi and rwfs are the current GitHub versions (SHAs aa9ec3b1 and 6c341a0a).

R version 3.4.3 (2017-11-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.2

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] fmi_0.2.1 R6_2.2.2 

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.14     bindr_0.1        raster_2.6-7     magrittr_1.5    
 [5] units_0.4-6      lattice_0.20-35  rlang_0.1.6      udunits2_0.13   
 [9] dplyr_0.7.4      tools_3.4.3      rgdal_1.2-16     grid_3.4.3      
[13] e1071_1.6-8      DBI_0.7          class_7.3-14     assertthat_0.2.0
[17] digest_0.6.13    tibble_1.4.1     sf_0.5-5         bindrcpp_0.2    
[21] glue_1.2.0       sp_1.2-5         compiler_3.4.3   pillar_1.0.1    
[25] rwfs_0.2.0       classInt_0.1-24  pkgconfig_2.0.1 

This is with gdal 1.11.5_3 and geos 3.6.2 installed via Homebrew and rgdal and rgeos compiled from source. At first I had the same error message with binary versions installed from CRAN (without the Homebrew packages). But since with that setup the output from library(rgdal) included GDAL binary built with GEOS: FALSE and I wasn't sure if that was required, I installed the Homebrew versions and complied the R packages from source, so that it's now TRUE:

Loading required package: sp
rgdal: version: 1.2-16, (SVN revision 701)
 Geospatial Data Abstraction Library extensions to R successfully loaded
 Loaded GDAL runtime: GDAL 1.11.5, released 2016/07/01
 Path to GDAL shared files: /usr/local/Cellar/gdal/1.11.5_3/share/gdal
 GDAL binary built with GEOS: TRUE 
 Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
 Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/sf/proj
 Linking to sp version: 1.2-5 

And finally, here's ogrDrivers()$name:

 [1] "AeronavFAA"     "ARCGEN"         "AVCBin"         "AVCE00"        
 [5] "BNA"            "CartoDB"        "CouchDB"        "CSV"           
 [9] "DGN"            "DXF"            "EDIGEO"         "ElasticSearch" 
[13] "ESRI Shapefile" "Geoconcept"     "GeoJSON"        "GeoRSS"        
[17] "GFT"            "GML"            "GMT"            "GPKG"          
[21] "GPSBabel"       "GPSTrackMaker"  "GPX"            "HTF"           
[25] "Idrisi"         "KML"            "MapInfo File"   "Memory"        
[29] "ODS"            "OpenAir"        "OpenFileGDB"    "OSM"           
[33] "PCIDSK"         "PDF"            "PDS"            "PGDump"        
[37] "REC"            "S57"            "SDTS"           "SEGUKOOA"      
[41] "SEGY"           "SQLite"         "SUA"            "SVG"           
[45] "SXF"            "TIGER"          "UK .NTF"        "VFK"           
[49] "VRT"            "WAsP"           "WFS"            "XLS"           
[53] "XLSX"           "XPlane"        

file59b658cff123 file59b658cff123.gfs

jlehtoma commented 6 years ago

Thanks for the report @ilarischeinin ! The error you encountered is due to the recent switch from rgdal to sf. There's a lot to be fixed in the tutorial and I was just working my way through it over the weekend. Unfortunately getting rasters over the API proved to more tricky than I thought. Furthermore, much of the background explanation in the tutorial has become obsolete since dropping GDAL CLI tools (i.e. ogr2ogr) so I need to check all the text as well. In any case, the fixed tutorial is not in master yet.

For now you should be able to run the piece of code above (but not the whole tutorial) by doing the following:

library(fmi)
apiKey <- "" # with a valid key
request <- FMIWFSRequest$new(apiKey = apiKey)
request$setParameters(request = "getFeature",
                      storedquery_id = "fmi::observations::weather::daily::timevaluepair",
                      starttime = "2014-01-01T00:00:00Z",
                      endtime = "2014-01-01T00:00:00Z",
                      bbox = "19.09,59.3,31.59,70.13",
                      parameters = "rrday,snow,tday,tmin,tmax")
client <- FMIWFSClient$new(request = request)
layers <- client$listLayers()
response <- client$getLayer(layer = layers$name)
# or alternatively:
# response <- client$getLayer(layer = layers[[1]])

Apologies for the extra hassle you had to go through in tracing the error, I should've communicated the situation better.

jlehtoma commented 6 years ago

Then there's also this #30 , feel free to chime in.

ilarischeinin commented 6 years ago

Ah, great, thank you!

Actually, I wasn't really going through the tutorial, but simply noticed that some of my own old code didn't work anymore. I used the example from the tutorial just to get a reprex that's as familiar as possible. I had recently updated the OS and all, so I thought the problem was at my end. I did check the NEWS.md though, to see if it mentioned any breaking changes. Perhaps it would be worth it to mention something there, as there might be others besides me who suddenly find their code not working anymore.

jlehtoma commented 6 years ago

Very good point. The thing is, that the breaking change is at rwfs's end. Also I'm pretty sure that this wasn't a breaking change initially as the switch is already more than a year old and at the time the old call signature did work. It could be that changes sf caused the issue more recently.

In any case, all this explaining makes a little difference from user's point of view. I'll add a note in rwfs and link it back here. Yet another reason not to have the separation between the two packages...