Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import os
- import numpy as np
- import psycopg2
- import commands
- import subprocess
- #from subprocess import call
- import popen2
- #from Tkinter import *
- #import tkMessageBox
- import time
- chemin_ogr2ogr = 'C:\OSGeo4W64\bin\'
- chemin_saga= 'C:\OSGeo4W64\apps\saga\'
- c_serveur_postgres_ip = 'xxxxxxx'
- c_serveur_postgres_port = 'xxxxx'
- c_bd_name = 'xxxxxx'
- c_log = 'xxxxxx'
- c_passw = 'xxxxxx' #
- c_schema_obs_obs = 'rasters'
- c_table_entree = 'tr_rge_alti_5m_2016'
- # d?finition des constantes des noms de champs
- c_nom_col_geo = 'rast'
- print 'connexion ...'
- def connect_db():
- try:
- conn = psycopg2.connect('dbname=' + c_bd_name +' user=' + c_log + ' host=' + c_serveur_postgres_ip + ' password=' + c_passw)
- print conn
- conn.set_session(autocommit=True) #if you want your updates to take effect without being in a transaction and requiring a commit, for a beginner, I would set this to True
- return conn
- except:
- print "I am unable to connect to the database"
- return None
- def get_raster(raster_id,conn):
- query= 'SELECT ST_DumpValues('+c_nom_col_geo+', 1 ) from '+c_schema_obs_obs+ '.'+c_table_entree+ ' where rid={}'.format(raster_id)
- conn.cursor().execute(query)
- cur = conn.cursor()
- res = cur.fetchall()
- return res[0][0]
- raster_id=0
- conn=connect_db()
- raster=get_raster(raster_id,conn)
- Traceback (most recent call last):
- File "\xxxxxxxprocess_1.py", line 76, in <module>
- raster=get_raster(raster_id,conn)
- File "\xxxxxxxprocess_1.py", line 68, in get_raster
- res = cur.fetchall()
- ProgrammingError: no results to fetch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement