Wednesday, November 10, 2010

R Environment and PostgreSQL

Be The First To Comment
# Install PostgreSQL 8.4 - 32 bit and install pgJDBC Driver, OLEDB Driver from Stack Builder..........
# Install R 2.11.1 -32 bit
# Open R interface..

library(rJava)
library(DBI)
library(RJDBC)
library(RpgSQL)

.jinit(classpath=NULL,parameters=getOption("-Xmx4000m"),silent=FALSE,force.init=TRUE)
con <- dbConnect(pgSQL(), user = "username", password = "password", dbname = "db_name",host="hostname")
result<-dbGetQuery(con, 'select blah1, blah2 from "tbl_blh"')

str(result)

result

Cheers !!!

Automatically Generate KML Files from CSV file

Be The First To Comment
# Import System Modules

import sys, string, os, csv

# Enter the input and output file names here

inputFileName="PROJECT.csv"
outputFileName="PROJ.kml"

inFile=open(inputFileName)
outFile=open(outputFileName,'a')

# Enter the total number of records here
numobs = 12

header =""+"\n"+\
""+"\n"+\
""+"\n"+\
"Spatial Distribution of Students "+"\n"

# Read in the stand attributes file one line at a time

outFile.write(str(header))

for obs in range(numobs):
readline=inFile.readline()

# Select the variables
currow=readline.split(",")
student=currow[0]
year=currow[1]
rslat=currow[2]
rslong=currow[3]
advisor=currow[4]
studyarea=currow[5]

outFile.write(""+"\n"+\
""+student+""+"\n"+\
""+"Location: "+studyarea +","+"Thesis Year: "+year+","+"Thesis Advisor: "+advisor +""+"\n"+\
""+"\n"+\
""+rslong+","+rslat+"13"+""+"\n"+\
"
"+"\n"+\
"
"+"\n")
#print studentInfo
#outFile.write(str(studentInfo))

footer="
"+"\n"+\
"
"

outFile.write(str(footer))

inFile.close()
outFile.close()
 

© 2011 GIS and Remote Sensing Tools, Tips and more .. ToS | Privacy Policy | Sitemap

About Me