Skip to content

Commit aca75cf

Browse files
committedApr 9, 2018
[processing][grass] Fix use of v.external with ogr layers which
do not support random read These layers are not compatible with v.external, so we have to use v.in.ogr for them
1 parent 8ba762a commit aca75cf

File tree

6 files changed

+42
-14
lines changed

6 files changed

+42
-14
lines changed
 

‎python/plugins/processing/algs/grass7/Grass7Algorithm.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
QgsProcessingUtils,
6464
QgsVectorLayer)
6565
from qgis.utils import iface
66+
from osgeo import ogr
6667

6768
from processing.core.ProcessingConfig import ProcessingConfig
6869

@@ -786,6 +787,17 @@ def loadVectorLayer(self, name, layer, external=False):
786787
if external is None:
787788
external = ProcessingConfig.getSetting(
788789
Grass7Utils.GRASS_USE_VEXTERNAL)
790+
791+
# safety check: we can only use external for ogr layers which support random read
792+
if external:
793+
ds = ogr.Open(layer.source())
794+
if ds is not None:
795+
ogr_layer = ds.GetLayer()
796+
if ogr_layer is None or not ogr_layer.TestCapability(ogr.OLCRandomRead):
797+
external = False
798+
else:
799+
external = False
800+
789801
self.inputLayers.append(layer)
790802
self.setSessionProjectionFromLayer(layer)
791803
destFilename = 'vector_{}'.format(os.path.basename(getTempFilename()))
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Binary file not shown.
Binary file not shown.

‎python/plugins/processing/tests/testdata/grass7_algorithms_vector_tests.yaml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,33 @@
33
tests:
44

55
# v.* modules
6-
# - algorithm: grass7:r.plane
7-
# name: GRASS7 r.plane
8-
# params:
9-
# GRASS_REGION_PARAMETER: 344500.0,358400.0,6682800.0,6693700.0
10-
# azimuth: 125
11-
# dip: 45
12-
# easting: 351610
13-
# elevation: 50
14-
# northing: 6688312
15-
# type: 1
16-
# results:
17-
# output:
18-
# hash: a9326678c39b6f925e7f22f6e79a48217100071cc8af85d675f28462
19-
# type: rasterhash
6+
- algorithm: grass7:v.buffer
7+
name: Buffer vectors
8+
params:
9+
-c: false
10+
-s: false
11+
-t: false
12+
GRASS_MIN_AREA_PARAMETER: 0.0001
13+
GRASS_OUTPUT_TYPE_PARAMETER: 0
14+
GRASS_SNAP_TOLERANCE_PARAMETER: -1.0
15+
angle: 0.0
16+
cats: ''
17+
distance: 0.1
18+
input:
19+
name: lines.gml
20+
type: vector
21+
scale: 1.0
22+
tolerance: 0.01
23+
type:
24+
- 0
25+
- 1
26+
- 4
27+
where: ''
28+
results:
29+
output:
30+
name: expected/grass7/buffer_lines.shp
31+
type: vector
32+
compare:
33+
geometry:
34+
precision: 7
2035

0 commit comments

Comments
 (0)
Please sign in to comment.