Skip to content

Commit 2417a82

Browse files
committedNov 7, 2014
[processing] add method in OGR algorithms for getting layer name from source
1 parent c78a378 commit 2417a82

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed
 

‎python/plugins/processing/algs/gdal/OgrAlgorithm.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
import string
2928
import re
29+
import os
3030

3131
try:
3232
from osgeo import ogr
@@ -36,6 +36,7 @@
3636

3737
from PyQt4.QtCore import *
3838
from PyQt4.QtGui import *
39+
3940
from qgis.core import *
4041

4142
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
@@ -66,3 +67,21 @@ def ogrConnectionString(self, uri):
6667
else:
6768
ogrstr = unicode(layer.source())
6869
return ogrstr
70+
71+
def ogrLayerName(self, uri):
72+
layerName = None
73+
74+
if 'host' in uri:
75+
regex = re.compile('(table=")(.+?)(\.")(.+?)"')
76+
r = regex.search(uri)
77+
return r.groups()[1] + '.' + r.groups()[3]
78+
elif 'dbname' in uri:
79+
regex = re.compile('(table=")(.+?)"')
80+
r = regex.search(uri)
81+
return r.groups()[1]
82+
elif 'layername' in uri:
83+
regex = re.compile('(layername=)(.*)')
84+
r = regex.search(uri)
85+
return r.groups()[1]
86+
else:
87+
return os.path.basename(os.path.splitext(uri)[0])

0 commit comments

Comments
 (0)