Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import sys
  2. import os
  3.  
  4.  
  5. import numpy as np
  6. import psycopg2
  7.  
  8. import commands
  9. import subprocess
  10. #from subprocess import call
  11. import popen2
  12.  
  13. #from Tkinter import *
  14. #import tkMessageBox
  15.  
  16. import time
  17. chemin_ogr2ogr = 'C:\OSGeo4W64\bin\'
  18. chemin_saga= 'C:\OSGeo4W64\apps\saga\'
  19.  
  20. c_serveur_postgres_ip = 'xxxxxxx'
  21. c_serveur_postgres_port = 'xxxxx'
  22.  
  23. c_bd_name = 'xxxxxx'
  24. c_log = 'xxxxxx'
  25. c_passw = 'xxxxxx' #
  26.  
  27. c_schema_obs_obs = 'rasters'
  28.  
  29. c_table_entree = 'tr_rge_alti_5m_2016'
  30.  
  31. # d?finition des constantes des noms de champs
  32. c_nom_col_geo = 'rast'
  33.  
  34. print 'connexion ...'
  35.  
  36.  
  37. def connect_db():
  38.  
  39. try:
  40. conn = psycopg2.connect('dbname=' + c_bd_name +' user=' + c_log + ' host=' + c_serveur_postgres_ip + ' password=' + c_passw)
  41. print conn
  42. 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
  43. return conn
  44. except:
  45. print "I am unable to connect to the database"
  46. return None
  47.  
  48. def get_raster(raster_id,conn):
  49.  
  50. query= 'SELECT ST_DumpValues('+c_nom_col_geo+', 1 ) from '+c_schema_obs_obs+ '.'+c_table_entree+ ' where rid={}'.format(raster_id)
  51. conn.cursor().execute(query)
  52. cur = conn.cursor()
  53. res = cur.fetchall()
  54.  
  55. return res[0][0]
  56.  
  57. raster_id=0
  58.  
  59. conn=connect_db()
  60.  
  61. raster=get_raster(raster_id,conn)
  62.  
  63. Traceback (most recent call last):
  64. File "\xxxxxxxprocess_1.py", line 76, in <module>
  65. raster=get_raster(raster_id,conn)
  66. File "\xxxxxxxprocess_1.py", line 68, in get_raster
  67. res = cur.fetchall()
  68. ProgrammingError: no results to fetch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement