diff --git a/python/plugins/processing/algs/gdal/OgrAlgorithm.py b/python/plugins/processing/algs/gdal/OgrAlgorithm.py index 9263bafe223..c6ccfe1175b 100644 --- a/python/plugins/processing/algs/gdal/OgrAlgorithm.py +++ b/python/plugins/processing/algs/gdal/OgrAlgorithm.py @@ -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])