[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
This commit is contained in:
Nyall Dawson 2018-04-08 09:58:06 +10:00
parent 8ba762a630
commit aca75cfa6e
6 changed files with 42 additions and 14 deletions

View File

@ -63,6 +63,7 @@ from qgis.core import (Qgis,
QgsProcessingUtils,
QgsVectorLayer)
from qgis.utils import iface
from osgeo import ogr
from processing.core.ProcessingConfig import ProcessingConfig
@ -786,6 +787,17 @@ class Grass7Algorithm(QgsProcessingAlgorithm):
if external is None:
external = ProcessingConfig.getSetting(
Grass7Utils.GRASS_USE_VEXTERNAL)
# safety check: we can only use external for ogr layers which support random read
if external:
ds = ogr.Open(layer.source())
if ds is not None:
ogr_layer = ds.GetLayer()
if ogr_layer is None or not ogr_layer.TestCapability(ogr.OLCRandomRead):
external = False
else:
external = False
self.inputLayers.append(layer)
self.setSessionProjectionFromLayer(layer)
destFilename = 'vector_{}'.format(os.path.basename(getTempFilename()))

View File

@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]

View File

@ -3,18 +3,33 @@
tests:
# v.* modules
# - algorithm: grass7:r.plane
# name: GRASS7 r.plane
# params:
# GRASS_REGION_PARAMETER: 344500.0,358400.0,6682800.0,6693700.0
# azimuth: 125
# dip: 45
# easting: 351610
# elevation: 50
# northing: 6688312
# type: 1
# results:
# output:
# hash: a9326678c39b6f925e7f22f6e79a48217100071cc8af85d675f28462
# type: rasterhash
- algorithm: grass7:v.buffer
name: Buffer vectors
params:
-c: false
-s: false
-t: false
GRASS_MIN_AREA_PARAMETER: 0.0001
GRASS_OUTPUT_TYPE_PARAMETER: 0
GRASS_SNAP_TOLERANCE_PARAMETER: -1.0
angle: 0.0
cats: ''
distance: 0.1
input:
name: lines.gml
type: vector
scale: 1.0
tolerance: 0.01
type:
- 0
- 1
- 4
where: ''
results:
output:
name: expected/grass7/buffer_lines.shp
type: vector
compare:
geometry:
precision: 7