I am trying to load some WFS data into a leaflet using R. The problem is that there doesn't seem to be a straightforward way to collect it, unlike with WMS, which has the
addWMSTiles() function in the
leaflet package for R.
How can I proceed?
Out of all attempts so far, the one with "greatest" success (no success really, just fetched the XML data) was done using the following code:
library(c(XML,plyr)) fileurl <- "http://ovc.catastro.meh.es/INSPIRE/wfsCP.aspx?service=WFS&request=GetFeature&Typenames=cp.cadastralparcel&SRSname=EPSG::25830&bbox=233673,4015968,233761,4016008&version=2.0.0&" doc <- xmlParse(fileurl,useInternalNodes = TRUE) ### xmlParse()- is to parse the xml content, the parsed content is stored into doc xL <- xmlToList(doc) ###is to convert xml doc into List data <- ldply(xL, data.frame) head(data)
This yields an XML with polygon points in one of the columns, but how can I include this in a Leaflet? It seems too much of a workaround to do this in this way. Does anyone know how to do this in a more straightforward manner?
Link to the inspire XML document on how to request data
UPDATE 1: I have found a way to do this using the
sf R package. With
Unfortunately it was not as straightforward as it seems. I had to install OSGeo4W64 in my machine because the rgdal package was not working properly. I also had to make the evironment variables point toward the OSGeo4W64, and delete the ones that pointed to
sf. I followed this guide.
However I am still wondering how to integrate this in R just as I did with WMS. As you may notice from the url in
st_read, it includes a Bounding Box, which I want leaflet to determine just like it did with WMS (which also required one)