comparison 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
comparison
equal deleted inserted replaced
4963:1469066cc7d9 4970:174fbaa3d344
1 import os 1 import os
2 import sys 2 import sys
3 from shpimporter import DEBUG, INFO, ERROR 3 from shpimporter import DEBUG, INFO, ERROR
4 try:
5 from osgeo import ogr
6 except ImportErrror:
7 import ogr
4 8
5 SHP='.shp' 9 SHP='.shp'
10 SQL_SELECT_ID="SELECT id FROM %s WHERE %s = '%s'"
6 11
7 def findShapefiles(path): 12 def findShapefiles(path):
8 shapes = [] 13 shapes = []
9 14
10 for root, dirs, files in os.walk(path): 15 for root, dirs, files in os.walk(path):
17 idx = f.find(SHP) 22 idx = f.find(SHP)
18 if (idx+len(SHP)) == len(f): 23 if (idx+len(SHP)) == len(f):
19 shapes.append((f.replace(SHP, ''), root + "/" + f)) 24 shapes.append((f.replace(SHP, ''), root + "/" + f))
20 25
21 return shapes 26 return shapes
27
28 def getRiverId(dbconn, name):
29 """
30 Returns the id of the river "name"
31 Dbconn must be a python database connection api compliant object
32 """
33 cur = dbconn.cursor()
34 select_stmt = SQL_SELECT_ID % ("rivers", "name", name)
35 cur.execute(select_stmt)
36 row = cur.fetchone()
37 if row:
38 return row[0]
39 else:
40 return 0
22 41
23 def getUTF8(string): 42 def getUTF8(string):
24 """ 43 """
25 Tries to convert the string to a UTF-8 encoding by first checking if it 44 Tries to convert the string to a UTF-8 encoding by first checking if it
26 is UTF-8 and then trying cp1252 45 is UTF-8 and then trying cp1252

http://dive4elements.wald.intevation.org