#!/usr/bin/python # -*- coding: utf-8 import sys, os, math, numpy, argparse import psycopg2 as ppg import grass.script as g from rpy2 import robjects as ro from rpy2.robjects.packages import importr as rin from progressbar import * r_base = rin('base') class pgwrapper: def __init__(self,dbname, srid, host='localhost',user='',passwd=''): self.dbname = dbname # Database name which connect to. self.srid = str(srid) # Identifier of spatial reference system. self.host = host # Host name (default is "localhost") self.user = user # User name for login to the database. self.password = passwd # Password for login to the database. self.connection = self.setConnect() # Set a onnection to the database self.cursor = self.setCursor() # Generate cursor. def setConnect(self): conn = ppg.connect( "dbname='" + self.dbname + "' user='******' host='" + self.host + "' password='******'") return conn def tableExists(self, table): sql_exists = "SELECT EXISTS(SELECT * FROM information_schema.tables WHERE table_name='" + table + "')"