[Raster-commits] r412 - in pkg: . rasterdb rasterdb/R rasterdb/inst rasterdb/inst/db rasterdb/man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Apr 18 05:22:58 CEST 2009


Author: rhijmans
Date: 2009-04-18 05:22:58 +0200 (Sat, 18 Apr 2009)
New Revision: 412

Added:
   pkg/rasterdb/
   pkg/rasterdb/DESCRIPTION
   pkg/rasterdb/NAMESPACE
   pkg/rasterdb/R/
   pkg/rasterdb/R/rasterToAccess.R
   pkg/rasterdb/inst/
   pkg/rasterdb/inst/db/
   pkg/rasterdb/inst/db/template
   pkg/rasterdb/man/
   pkg/rasterdb/man/rasterToAccess.Rd
Log:



Property changes on: pkg/rasterdb
___________________________________________________________________
Name: svn:ignore
   + chm


Added: pkg/rasterdb/DESCRIPTION
===================================================================
--- pkg/rasterdb/DESCRIPTION	                        (rev 0)
+++ pkg/rasterdb/DESCRIPTION	2009-04-18 03:22:58 UTC (rev 412)
@@ -0,0 +1,12 @@
+Package: rasterDB
+Type: Package
+Title: raster database functions
+Version: 0.0
+Date: 2009-4-17
+Depends: RODBC, RSQLite, raster
+Author: Robert J. Hijmans
+Maintainer: Robert J. Hijmans <r.hijmans at gmail.com>
+Description: database functions for the raster package
+License: GPL3
+LazyLoad: yes
+URL: http://raster.r-forge.r-project.org/
\ No newline at end of file

Added: pkg/rasterdb/NAMESPACE
===================================================================
--- pkg/rasterdb/NAMESPACE	                        (rev 0)
+++ pkg/rasterdb/NAMESPACE	2009-04-18 03:22:58 UTC (rev 412)
@@ -0,0 +1 @@
+exportPattern("^[^\\.]")
\ No newline at end of file

Added: pkg/rasterdb/R/rasterToAccess.R
===================================================================
--- pkg/rasterdb/R/rasterToAccess.R	                        (rev 0)
+++ pkg/rasterdb/R/rasterToAccess.R	2009-04-18 03:22:58 UTC (rev 412)
@@ -0,0 +1,37 @@
+
+
+rasterToAccess <- function(raster, filename) {
+	ext(filename) <- '.mdb'
+	if (!file.exists(filename)) {
+		empty <- system.file("db/template", package="raster")
+		file.copy(empty, filename)
+	}
+	accdb <- odbcConnectAccess(filename)
+	ind <- sqlQuery(accdb, "SELECT * FROM [index]")
+	ln1 <- layerNames(raster)
+	ln1 <- substr(ln1, 1, 60)
+	if (ln1 == "") {
+		ln1 <- deparse(substitute(raster))
+	}
+	ln <- ln1
+	cnt <- 2
+	while (ln %in% ind$tablename) {
+		ln <- paste(ln1, "_", cnt, sep="")
+		cnt <- cnt + 1
+	}
+
+	df <- data.frame(t(c(ln, 1, nrow(raster), ncol(raster), xmin(raster), xmax(raster), ymin(raster), ymax(raster))))
+	colnames(df) <- c('tablename', 'nlayers', 'nrow', 'ncol', 'xmin', 'xmax', 'ymin', 'ymax')
+	sqlSave(accdb, df, tablename = 'index', append=TRUE, fast=FALSE, rownames=FALSE, safer=FALSE)
+	
+	filename(raster) <- paste(filename, '#', ln, sep="")
+	
+	if (dataContent(raster) == 'all') {
+		df <- as.data.frame(values(raster))
+		colnames(df) <- 'values'
+		sqlSave(accdb, df, tablename = ln, append=FALSE, fast = FALSE, rownames=FALSE, safer=FALSE) 
+	}
+	
+	odbcClose(accdb)
+	return(raster)
+}

Added: pkg/rasterdb/inst/db/template
===================================================================
(Binary files differ)


Property changes on: pkg/rasterdb/inst/db/template
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: pkg/rasterdb/man/rasterToAccess.Rd
===================================================================
--- pkg/rasterdb/man/rasterToAccess.Rd	                        (rev 0)
+++ pkg/rasterdb/man/rasterToAccess.Rd	2009-04-18 03:22:58 UTC (rev 412)
@@ -0,0 +1,33 @@
+\name{rasterToAccess}
+\alias{rasterToAccess}
+
+\title{ raster to Mdb }
+\description{
+  copy a RasterLayer to an Access database
+}
+\usage{
+rasterToAccess(raster, filename)
+}
+
+\arguments{
+  \item{raster}{ RasterLayer object}
+  \item{filename}{ filename of Access database }
+}
+\details{
+  If the Access database does not exist, it will be created. 
+}
+\value{
+ a RasterLayer object
+}
+
+
+\author{Robert J. Hijmans}
+
+\examples{
+r <- raster(ncol=10, nrow=10)
+r[] <- runif(100)
+r2 <- rasterToAccess(r, 'AccessTest.mdb')
+}
+
+\keyword{ spatial }
+



More information about the Raster-commits mailing list