Skip to content

Commit

Permalink
[processing] add method in OGR algorithms for getting layer name from…
Browse files Browse the repository at this point in the history
… source
  • Loading branch information
alexbruy committed Nov 7, 2014
1 parent c78a378 commit 2417a82
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion python/plugins/processing/algs/gdal/OgrAlgorithm.py
Expand Up @@ -25,8 +25,8 @@

__revision__ = '$Format:%H$'

import string
import re
import os

try:
from osgeo import ogr
Expand All @@ -36,6 +36,7 @@

from PyQt4.QtCore import *
from PyQt4.QtGui import *

from qgis.core import *

from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
Expand Down Expand Up @@ -66,3 +67,21 @@ def ogrConnectionString(self, uri):
else:
ogrstr = unicode(layer.source())
return ogrstr

def ogrLayerName(self, uri):
layerName = None

if 'host' in uri:
regex = re.compile('(table=")(.+?)(\.")(.+?)"')

This comment has been minimized.

Copy link
@gioman

gioman Nov 8, 2014

Contributor

Seems to me there is an extra '"'

should be

regex = re.compile('(table=")(.+?)(.)(.+?)"')

at least in the context of creating ogr2ogr based tools with the -sql switch.

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])

0 comments on commit 2417a82

Please sign in to comment.