Database Reference
In-Depth Information
require(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
conn <- dbConnect(drv, user="postgres",
dbname="pgissc")
sql.str <- "select id, st_x(location) as x,
st_y(location) as y, location from stands;"
waypts <- dbGetQuery(conn, sql.str)
dist.matrix <- rdist.earth(waypts[,2:3],
R=3949.0)
rtsp <- TSP(dist.matrix)
soln <- solve_TSP(rtsp)
dbDisconnect(conn)
dbUnloadDriver(drv)
return(attributes(soln)$tour_length)
$$
LANGUAGE plr STRICT;
SELECT tsp_tour_length();
tsp_tour_length
------------------
2804.58129355858
(1 row)
We can optionally auto load R functions in Postgres. There are special modules
plr_modules that contain the R functions.
Search WWH ::




Custom Search