Run R script from Python -


i want run r-script python script. r-script required projection of lat lon coordinates in different coordinate system. have considered 2 options this. in first option parse lat , lon coordinates r-script shown below. r-script returns x , y python script, can't figure out how this.

project<-function(lat,lon){  library(sp) library(rgdal)  xy <- cbind(x = lon, y = lat) s <- spatialpoints(xy) proj4string(s) <- crs("+proj=longlat +ellps=wgs84 +datum=wgs84 +no_defs") snew <- sptransform(s, crs("+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs")) x <- coordinates(snew)[1] y <- coordinates(snew)[2]  return(x,y) } 

for second option i've considered using r-script @ bottom lat , lon in it. try run python subprocess.popen('rscript project.r', shell=true).wait() not seem work. not write xy.txt file. if run cmd line, however, r-script job. can me out 1 of these 2 options?

library(sp) library(rgdal)  lat <- 52.29999924 lon <- 4.76999998  xy <- cbind(x = lon, y = lat) s <- spatialpoints(xy) proj4string(s) <- crs("+proj=longlat +ellps=wgs84 +datum=wgs84 +no_defs") snew <- sptransform(s, crs("+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs")) x <- coordinates(snew)[1] y <- coordinates(snew)[2]  cat(x, file="xy.txt",sep="") cat(y,file="xy.txt",append=true) 

for first solution -- r output coordinates console (using print or cat or whatever in r), capture in python (see here: running shell command python , capturing output)

that give string teh lat/lon coords in it, have parse them out using appropraite python functions.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -