Skip to content
Permalink
Browse files

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

… source
  • Loading branch information
alexbruy committed Nov 7, 2014
1 parent c78a378 commit 2417a82bd7ab559f2a067d46c14cbfcdbc849c49
Showing with 20 additions and 1 deletion.
  1. +20 −1 python/plugins/processing/algs/gdal/OgrAlgorithm.py
@@ -25,8 +25,8 @@

__revision__ = '$Format:%H$'

import string
import re
import os

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

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

from qgis.core import *

from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
@@ -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.
You can’t perform that action at this time.