Skip to content
Permalink
Browse files

[processing][gdal] Fix ogrinfo algorithm fails when path name has spaces

Fixes #19655

(cherry-picked from d0a705f)
  • Loading branch information
nyalldawson committed Aug 21, 2018
1 parent 9c3f053 commit 821aad4315b347f3a346610b9722867af9efd3c9
@@ -74,7 +74,7 @@ def commandName(self):
return 'ogrinfo'

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = [self.commandName(), '-al']
arguments = ['-al']

if self.parameterAsBool(parameters, self.SUMMARY_ONLY, context):
arguments.append('-so')
@@ -87,7 +87,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

connectionString = GdalUtils.ogrConnectionString(inLayer.source(), context)
arguments.append(connectionString)
return arguments
return [self.commandName(), GdalUtils.escapeAndJoin(arguments)]

def processAlgorithm(self, parameters, context, feedback):
GdalUtils.runGdal(self.getConsoleCommands(parameters, context, feedback), feedback)
@@ -44,6 +44,7 @@
from processing.algs.gdal.buildvrt import buildvrt
from processing.algs.gdal.hillshade import hillshade
from processing.algs.gdal.ogr2ogr import ogr2ogr
from processing.algs.gdal.ogrinfo import ogrinfo
from processing.algs.gdal.proximity import proximity
from processing.algs.gdal.rasterize import rasterize
from processing.algs.gdal.retile import retile
@@ -1092,6 +1093,48 @@ def testOgr2Ogr(self):
'-f "LIBKML" "d:/temp/my out/check.kml" ' +
source + ' polys2'])

def testOgrInfo(self):
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()
source = os.path.join(testDataPath, 'polys.gml')
alg = ogrinfo()
alg.initAlgorithm()

self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'SUMMARY_ONLY': True,
'NO_METADATA': False}, context, feedback),
['ogrinfo',
'-al -so ' +
source])

source = os.path.join(testDataPath, 'filename with spaces.gml')
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'SUMMARY_ONLY': True,
'NO_METADATA': False}, context, feedback),
['ogrinfo',
'-al -so "' +
source + '"'])

source = os.path.join(testDataPath, 'filename with spaces.gml')
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'SUMMARY_ONLY': False,
'NO_METADATA': False}, context, feedback),
['ogrinfo',
'-al "' +
source + '"'])

source = os.path.join(testDataPath, 'filename with spaces.gml')
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'SUMMARY_ONLY': True,
'NO_METADATA': True}, context, feedback),
['ogrinfo',
'-al -so -nomd "' +
source + '"'])

def testHillshade(self):
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ filename with spaces.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>0</gml:X><gml:Y>-5</gml:Y></gml:coord>
<gml:coord><gml:X>8</gml:X><gml:Y>3</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:filename_with_spaces fid="points.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>1,1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>1</ogr:id>
<ogr:id2>2</ogr:id2>
</ogr:filename_with_spaces>
</gml:featureMember>
<gml:featureMember>
<ogr:filename_with_spaces fid="points.1">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,3</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>2</ogr:id>
<ogr:id2>1</ogr:id2>
</ogr:filename_with_spaces>
</gml:featureMember>
<gml:featureMember>
<ogr:filename_with_spaces fid="points.2">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,2</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>3</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:filename_with_spaces>
</gml:featureMember>
<gml:featureMember>
<ogr:filename_with_spaces fid="points.3">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5,2</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>4</ogr:id>
<ogr:id2>2</ogr:id2>
</ogr:filename_with_spaces>
</gml:featureMember>
<gml:featureMember>
<ogr:filename_with_spaces fid="points.4">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4,1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>5</ogr:id>
<ogr:id2>1</ogr:id2>
</ogr:filename_with_spaces>
</gml:featureMember>
<gml:featureMember>
<ogr:filename_with_spaces fid="points.5">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-5</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>6</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:filename_with_spaces>
</gml:featureMember>
<gml:featureMember>
<ogr:filename_with_spaces fid="points.6">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>7</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:filename_with_spaces>
</gml:featureMember>
<gml:featureMember>
<ogr:filename_with_spaces fid="points.7">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>8</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:filename_with_spaces>
</gml:featureMember>
<gml:featureMember>
<ogr:filename_with_spaces fid="points.8">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:id>9</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:filename_with_spaces>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="filename_with_spaces" type="ogr:filename_with_spaces_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="filename_with_spaces_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:PointPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="id" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="id2" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="10"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>

0 comments on commit 821aad4

Please sign in to comment.
You can’t perform that action at this time.