[processing] add method in OGR algorithms for getting layer name from source

This commit is contained in:
Alexander Bruy 2014-11-07 16:11:11 +02:00
parent c78a3783a9
commit 2417a82bd7

View File

@ -25,8 +25,8 @@ __copyright__ = '(C) 2012, Victor Olaya'
__revision__ = '$Format:%H$'
import string
import re
import os
try:
from osgeo import ogr
@ -36,6 +36,7 @@ except:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
@ -66,3 +67,21 @@ class OgrAlgorithm(GdalAlgorithm):
else:
ogrstr = unicode(layer.source())
return ogrstr
def ogrLayerName(self, uri):
layerName = None
if 'host' in uri:
regex = re.compile('(table=")(.+?)(\.")(.+?)"')
r = regex.search(uri)
return r.groups()[1] + '.' + r.groups()[3]
elif 'dbname' in uri:
regex = re.compile('(table=")(.+?)"')
r = regex.search(uri)
return r.groups()[1]
elif 'layername' in uri:
regex = re.compile('(layername=)(.*)')
r = regex.search(uri)
return r.groups()[1]
else:
return os.path.basename(os.path.splitext(uri)[0])