Skip to content

Commit

Permalink
[processing][grass] Fix use of v.external with ogr layers which
Browse files Browse the repository at this point in the history
do not support random read

These layers are not compatible with v.external, so we have to
use v.in.ogr for them

(cherry-picked from aca75cf)
  • Loading branch information
nyalldawson committed Apr 9, 2018
1 parent a675311 commit 1c2103d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
12 changes: 12 additions & 0 deletions python/plugins/processing/algs/grass7/Grass7Algorithm.py
Expand Up @@ -63,6 +63,7 @@
QgsProcessingUtils,
QgsVectorLayer)
from qgis.utils import iface
from osgeo import ogr

from processing.core.ProcessingConfig import ProcessingConfig

Expand Down Expand Up @@ -786,6 +787,17 @@ def loadVectorLayer(self, name, layer, external=False):
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()))
Expand Down
Binary file not shown.
@@ -0,0 +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.
Expand Up @@ -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

0 comments on commit 1c2103d

Please sign in to comment.