I am brand new to R (long-time user of Knime!) and I have recently picked up a new role where I can combine the two. I have managed to get Knime to find RServe and I found a thread here detailing what I want to do - convert UK Easting/Northing to Long/Lat. I am using the R Snippet node to run the following:
utmcoor<-SpatialPoints(cbind(knime.in$“Easting”,knime.in$“Northing”), proj4string=CRS(“+proj=utm +zone=30”))
#utmdata$X and utmdata$Y are corresponding to UTM Easting and Northing, respectively.
#zone= UTM zone
However, I keep getting the error Execute failed: R evaluation failed.: “class(knime.out)”…and I don’t really know what that means! Is there something else I need to do? I was just expecting some numbers out.
If it helps, I have a very simple test table of “Easting” and “Northing” (both integers) which I am feeding into the R Snippet.
Hi @JWebb
Both in R and Py Snippet, it’s mandatory to send a data frame object to the output port.
Said so, ‘utmcoor’ and ‘longlatcoor’ (returned from ‘spatial points’ [sp] and ‘rgdal’ libraries) are list objects. Then you will need to subset a data frame from this ‘longlatcoor’ list and send it to the output port.
I need to do some R training because I haven’t got a clue what that means I was just copying the example, to be honest! Thanks; I’ll try and figure something out. At least it’s not a setting issue.
goes a long way. You will have to deal with the structure of the data (often strings) later but it will work. If you just want to store something from within R and use it later again in R you could also save something as .rdata:
Perfect! That worked well. A simple solution which works for me for the time being. Once I get my head round R a bit more, I’m sure things will become clearer, but I am happy that works for now Thank you!
It’s not giving the correct answer, but at least I am getting something out!
Well done @JWebb ! The first step is to understand the few KNIME-R connection rules. Combine KNIME and R (Py) becomes a perfect tool for non native programmers as myself.
If you want us to review the workflow, or code, or test the input data, don’t hesitate to share.
I think it’s a good start that I have made the connection and managed to get it to so something in my first week using it!
I am trying to convert UK Easting/Northing coordinates to lat/long. I have taken 537869, 178976 (somewhere in Greenwich) as an example, but the lat/long converted point appears to be in the Atlantic Ocean somewhere off the coast off the Ivory Coast! I appreciate, however, this is not an R forum, so I can try and raise the question elsewhere. I also appreciate, however, that you may be intrigued, so this is what I am using:
utmcoor<-SpatialPoints(cbind(knime.in$“Easting”,knime.in$“Northing”), proj4string=CRS(“+proj=utm +zone=30”))
#utmdata$X and utmdata$Y are corresponding to UTM Easting and Northing, respectively.
#zone= UTM zone
I don’t think UTM is the correct system. I just need to find someone who has managed it for BNG and steal their code Which is harder to find than it sounds!
That one has not worked, I’m afraid. I have plotted both “Greenwich” points x/y and y/x just to make sure I wasn’t getting them the wrong way round. One was in the sea off the Seychelles and one was in the sea off the coast of Northern Ireland! The result it gave me was -5.430676428765502 for x and 54.68721915653498 for y. I’m sure it’s just a case of figuring out which conversion scheme to use, so thank you for your input and I shall have to investigate the correct numbers.
Update:
I completely overlooked something! I can specify the coordinate system I am using in the program, so I do not actually need to convert it. however, I didn’t realise I was able to do that until reading your feedback to my last post, so you did solve my problem in a roundabout way! Thank you for the input.
@JWebb glad you found it. Maybe you can provide your solution with the example and a description what you did in a short workflow. That might help others in the future
It was not in Knime, I’m afraid. No lick with getting that R Snippet to convert the coordinates effectively, I’m afraid.
The ultimate goal was to feed into Tableau to aid some work I am doing and Tableau allows you to specify the coordinate system you are using with its MAKEPOINT function. I didn’t realise that was such a thing until I saw @gonhaddock use the number codes from epsg.io
At least this gives me a workaround until I can get better with R and maybe have a reasonable idea of what is going on!
This currently fixes it, and works in RStudio, returning the mentioned result:
but returning an error in KNIME (RStudio oversees it):
"To mute warnings of possible GDAL/OSR exportToProj4() degradation, use options(“rgdal_show_exportToProj4_warnings”=“none”) before loading sp or rgdal. Error: subscript out of bounds …"
There are some literature about this Error related to Windows, but I don’t have time now for debugging.
@JWebb
Your coding resulted to be more optimal than the testing mine. Usually I need a workaround to fully understand ‘R to facts’ conceptual relation.
This is the code working within KNIME as stated in your posted link :