diff flys-backend/contrib/shpimporter/utils.py @ 4970:174fbaa3d344 dami

Add handling of River Names and remove target_src parameter This is the first step to make the shpimporter into a more generic geo importer that communicates directly (not only over ogr) with the database. Untested with Oracle
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 13 Feb 2013 12:02:30 +0100
parents c0a58558b817
children a6ee62a070b0
line wrap: on
line diff
--- a/flys-backend/contrib/shpimporter/utils.py	Mon Feb 04 17:54:39 2013 +0100
+++ b/flys-backend/contrib/shpimporter/utils.py	Wed Feb 13 12:02:30 2013 +0100
@@ -1,8 +1,13 @@
 import os
 import sys
 from shpimporter import DEBUG, INFO, ERROR
+try:
+    from osgeo import ogr
+except ImportErrror:
+    import ogr
 
 SHP='.shp'
+SQL_SELECT_ID="SELECT id FROM %s WHERE %s = '%s'"
 
 def findShapefiles(path):
     shapes = []
@@ -20,6 +25,20 @@
 
     return shapes
 
+def getRiverId(dbconn, name):
+    """
+    Returns the id of the river "name"
+    Dbconn must be a python database connection api compliant object
+    """
+    cur = dbconn.cursor()
+    select_stmt = SQL_SELECT_ID % ("rivers", "name", name)
+    cur.execute(select_stmt)
+    row = cur.fetchone()
+    if row:
+        return row[0]
+    else:
+        return 0
+
 def getUTF8(string):
     """
     Tries to convert the string to a UTF-8 encoding by first checking if it

http://dive4elements.wald.intevation.org