-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
Adds supports for "layerid" when present. Drop special handling for "table=" portions found in URI, making the code more generic. Includes testcase. Fixes #15698 - import geodatabase to postgis via processing
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,8 @@ | |
|
||
import psycopg2 | ||
|
||
from osgeo import ogr | ||
|
||
from qgis.PyQt.QtCore import QVariant, QSettings | ||
from qgis.core import (Qgis, QgsFields, QgsField, QgsGeometry, QgsRectangle, QgsWkbTypes, | ||
QgsSpatialIndex, QgsMapLayerRegistry, QgsMapLayer, QgsVectorLayer, | ||
|
@@ -531,20 +533,26 @@ def ogrConnectionString(uri): | |
|
||
|
||
def ogrLayerName(uri): | ||
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]) | ||
fields = uri.split('|') | ||
ogruri = fields[0] | ||
fields = fields[1:] | ||
layerid = 0 | ||
for f in fields: | ||
if f.startswith('layername='): | ||
# Name encoded in uri, nothing more needed | ||
return f.split('=')[1] | ||
if f.startswith('layerid='): | ||
layerid = int(f.split('=')[1]) | ||
# Last layerid= takes precedence, to allow of layername to | ||
# take precedence | ||
ds = ogr.Open(ogruri) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
strk
Author
Contributor
|
||
if not ds: | ||
return "invalid-uri" | ||
ly = ds.GetLayer(layerid) | ||
if not ly: | ||
return "invalid-layerid" | ||
name = ly.GetName() | ||
return name | ||
|
||
|
||
class VectorWriter(object): | ||
|
3 comments
on commit 6c53641
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit breaks all OGR geoprocessing tools. To reproduce:
- open polys.gml from Processing test dataset
- try to execute "Buffer vectors" from GDAL/OGR -> [OGR] Geoprocessing -> Buffer vectors
- algorithm execution will fail with error
Warning 1: layer names ignored in combination with -sql.
ERROR 1: In ExecuteSQL(): sqlite3_prepare(SELECT ST_Buffer(geometry, 1000), * FROM 'polys2'):
no such table: polys2
Also related tests in ToolsTest.py fail if /tmp located on partition different from partition where QGIS sources and build directory located.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And travis cought none of them ? That's scary !
Maybe this is because we have no tests for this algs?
@strk, I think this will not be able to open a URI like
'dbname=\'/tmp/test.sqlite\' table="test" (geometry) sql='
, returning"invalid-uri"
, although"test"
would be expected by anyone callingogrLayerName
.ogrLayerName
gets URIs from QGIS layers. Please fix this so I can send a PR that will hopefully enter into QGIS v2.18.