Skip to content

Commit

Permalink
Add command-line based tests for ogr2ogr
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitblanc authored and nyalldawson committed Dec 9, 2021
1 parent 83a1553 commit b947365
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 0 deletions.
17 changes: 17 additions & 0 deletions python/plugins/processing/tests/GdalAlgorithmsVectorTest.py
Expand Up @@ -68,6 +68,7 @@ def testOgr2Ogr(self):
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()
source = os.path.join(testDataPath, 'polys.gml')
multi_source = os.path.join(testDataPath, 'multi_layers.gml')
alg = ogr2ogr()
alg.initAlgorithm()

Expand Down Expand Up @@ -100,6 +101,22 @@ def testOgr2Ogr(self):
'-f "GPKG" ' + outdir + '/check.gpkg ' +
source + ' polys2'])

self.assertEqual(
alg.getConsoleCommands({'INPUT': multi_source + '|layername=lines',
'CONVERT_ALL_LAYERS': False,
'OUTPUT': outdir + '/check.gpkg'}, context, feedback),
['ogr2ogr',
'-f "GPKG" ' + outdir + '/check.gpkg ' +
multi_source + ' lines'])

self.assertEqual(
alg.getConsoleCommands({'INPUT': multi_source + '|layername=lines',
'CONVERT_ALL_LAYERS': True,
'OUTPUT': outdir + '/check.gpkg'}, context, feedback),
['ogr2ogr',
'-f "GPKG" ' + outdir + '/check.gpkg ' +
multi_source])

def testOgrInfo(self):
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()
Expand Down
41 changes: 41 additions & 0 deletions python/plugins/processing/tests/testdata/multi_layers.gfs
@@ -0,0 +1,41 @@
<GMLFeatureClassList>
<SequentialLayers>true</SequentialLayers>
<GMLFeatureClass>
<Name>points</Name>
<ElementPath>points</ElementPath>
<!--POINT-->
<GeometryType>1</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>9</FeatureCount>
<ExtentXMin>0.00000</ExtentXMin>
<ExtentXMax>8.00000</ExtentXMax>
<ExtentYMin>-5.00000</ExtentYMin>
<ExtentYMax>3.00000</ExtentYMax>
</DatasetSpecificInfo>
<PropertyDefn>
<Name>id</Name>
<ElementPath>id</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>id2</Name>
<ElementPath>id2</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
</GMLFeatureClass>
<GMLFeatureClass>
<Name>lines</Name>
<ElementPath>lines</ElementPath>
<!--LINESTRING-->
<GeometryType>2</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>7</FeatureCount>
<ExtentXMin>-1.00000</ExtentXMin>
<ExtentXMax>11.00000</ExtentXMax>
<ExtentYMin>-3.00000</ExtentYMin>
<ExtentYMax>5.00000</ExtentYMax>
</DatasetSpecificInfo>
</GMLFeatureClass>
</GMLFeatureClassList>
111 changes: 111 additions & 0 deletions python/plugins/processing/tests/testdata/multi_layers.gml
@@ -0,0 +1,111 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ results_convert_all_layers_points_lines.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>-1</gml:X><gml:Y>-5</gml:Y></gml:coord>
<gml:coord><gml:X>11</gml:X><gml:Y>5</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:points fid="points.0">
<ogr:geom><gml:Point srsName="EPSG:4326"><gml:coordinates>1,1</gml:coordinates></gml:Point></ogr:geom>
<ogr:id>1</ogr:id>
<ogr:id2>2</ogr:id2>
</ogr:points>
</gml:featureMember>
<gml:featureMember>
<ogr:points fid="points.1">
<ogr:geom><gml:Point srsName="EPSG:4326"><gml:coordinates>3,3</gml:coordinates></gml:Point></ogr:geom>
<ogr:id>2</ogr:id>
<ogr:id2>1</ogr:id2>
</ogr:points>
</gml:featureMember>
<gml:featureMember>
<ogr:points fid="points.2">
<ogr:geom><gml:Point srsName="EPSG:4326"><gml:coordinates>2,2</gml:coordinates></gml:Point></ogr:geom>
<ogr:id>3</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:points>
</gml:featureMember>
<gml:featureMember>
<ogr:points fid="points.3">
<ogr:geom><gml:Point srsName="EPSG:4326"><gml:coordinates>5,2</gml:coordinates></gml:Point></ogr:geom>
<ogr:id>4</ogr:id>
<ogr:id2>2</ogr:id2>
</ogr:points>
</gml:featureMember>
<gml:featureMember>
<ogr:points fid="points.4">
<ogr:geom><gml:Point srsName="EPSG:4326"><gml:coordinates>4,1</gml:coordinates></gml:Point></ogr:geom>
<ogr:id>5</ogr:id>
<ogr:id2>1</ogr:id2>
</ogr:points>
</gml:featureMember>
<gml:featureMember>
<ogr:points fid="points.5">
<ogr:geom><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-5</gml:coordinates></gml:Point></ogr:geom>
<ogr:id>6</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:points>
</gml:featureMember>
<gml:featureMember>
<ogr:points fid="points.6">
<ogr:geom><gml:Point srsName="EPSG:4326"><gml:coordinates>8,-1</gml:coordinates></gml:Point></ogr:geom>
<ogr:id>7</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:points>
</gml:featureMember>
<gml:featureMember>
<ogr:points fid="points.7">
<ogr:geom><gml:Point srsName="EPSG:4326"><gml:coordinates>7,-1</gml:coordinates></gml:Point></ogr:geom>
<ogr:id>8</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:points>
</gml:featureMember>
<gml:featureMember>
<ogr:points fid="points.8">
<ogr:geom><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-1</gml:coordinates></gml:Point></ogr:geom>
<ogr:id>9</ogr:id>
<ogr:id2>0</ogr:id2>
</ogr:points>
</gml:featureMember>
<gml:featureMember>
<ogr:lines fid="lines.0">
<ogr:geom><gml:LineString srsName="EPSG:4326"><gml:coordinates>6,2 9,2 9,3 11,5</gml:coordinates></gml:LineString></ogr:geom>
</ogr:lines>
</gml:featureMember>
<gml:featureMember>
<ogr:lines fid="lines.1">
<ogr:geom><gml:LineString srsName="EPSG:4326"><gml:coordinates>-1,-1 1,-1</gml:coordinates></gml:LineString></ogr:geom>
</ogr:lines>
</gml:featureMember>
<gml:featureMember>
<ogr:lines fid="lines.2">
<ogr:geom><gml:LineString srsName="EPSG:4326"><gml:coordinates>2,0 2,2 3,2 3,3</gml:coordinates></gml:LineString></ogr:geom>
</ogr:lines>
</gml:featureMember>
<gml:featureMember>
<ogr:lines fid="lines.3">
<ogr:geom><gml:LineString srsName="EPSG:4326"><gml:coordinates>3,1 5,1</gml:coordinates></gml:LineString></ogr:geom>
</ogr:lines>
</gml:featureMember>
<gml:featureMember>
<ogr:lines fid="lines.4">
<ogr:geom><gml:LineString srsName="EPSG:4326"><gml:coordinates>7,-3 10,-3</gml:coordinates></gml:LineString></ogr:geom>
</ogr:lines>
</gml:featureMember>
<gml:featureMember>
<ogr:lines fid="lines.5">
<ogr:geom><gml:LineString srsName="EPSG:4326"><gml:coordinates>6,-3 10,1</gml:coordinates></gml:LineString></ogr:geom>
</ogr:lines>
</gml:featureMember>
<gml:featureMember>
<ogr:lines fid="lines.6">
</ogr:lines>
</gml:featureMember>
</ogr:FeatureCollection>

0 comments on commit b947365

Please sign in to comment.