[processing][feature] Add tests for gdal:ogrinfo and gdal:ogrinfojson

This commit is contained in:
Andrea Giudiceandrea 2024-07-04 12:08:03 +02:00 committed by Nyall Dawson
parent 3d8a7a7a80
commit 5f85a82caa
5 changed files with 662 additions and 1 deletions

View File

@ -34,7 +34,7 @@ from qgis.testing import (QgisTestCase,
import AlgorithmsTestBase
from processing.algs.gdal.ogr2ogr import ogr2ogr
from processing.algs.gdal.ogrinfo import ogrinfo
from processing.algs.gdal.ogrinfo import ogrinfo, ogrinfojson
from processing.algs.gdal.Buffer import Buffer
from processing.algs.gdal.Dissolve import Dissolve
from processing.algs.gdal.OffsetCurve import OffsetCurve
@ -146,6 +146,27 @@ class TestGdalVectorAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
'-al -so ' +
source + ' polys2'])
source = os.path.join(testDataPath, 'polys.gml')
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'ALL_LAYERS': True,
'SUMMARY_ONLY': True,
'NO_METADATA': False}, context, feedback),
['ogrinfo',
'-al -so ' +
source])
source = os.path.join(testDataPath, 'polys.gml')
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'ALL_LAYERS': True,
'SUMMARY_ONLY': True,
'EXTRA': '-nocount',
'NO_METADATA': False}, context, feedback),
['ogrinfo',
'-al -so -nocount ' +
source])
source = os.path.join(testDataPath, 'filename with spaces.gml')
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
@ -191,6 +212,87 @@ class TestGdalVectorAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest):
'-al -so -nomd "' +
source + '" filename_with_spaces --config X Y --config Z A'])
def testOgrInfoJson(self):
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()
source = os.path.join(testDataPath, 'polys.gml')
alg = ogrinfojson()
alg.initAlgorithm()
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'FEATURES': True,
'NO_METADATA': False}, context, feedback),
['ogrinfo',
'-json -features ' +
source + ' polys2'])
source = os.path.join(testDataPath, 'polys.gml')
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'ALL_LAYERS': True,
'FEATURES': True,
'NO_METADATA': False}, context, feedback),
['ogrinfo',
'-json -features ' +
source])
source = os.path.join(testDataPath, 'polys.gml')
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'ALL_LAYERS': True,
'FEATURES': True,
'EXTRA': '-nocount',
'NO_METADATA': False}, context, feedback),
['ogrinfo',
'-json -features -nocount ' +
source])
source = os.path.join(testDataPath, 'filename with spaces.gml')
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'FEATURES': True,
'NO_METADATA': False}, context, feedback),
['ogrinfo',
'-json -features "' +
source + '" filename_with_spaces'])
source = os.path.join(testDataPath, 'filename with spaces.gml')
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'FEATURES': False,
'NO_METADATA': False}, context, feedback),
['ogrinfo',
'-json "' +
source + '" filename_with_spaces'])
source = os.path.join(testDataPath, 'filename with spaces.gml')
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'FEATURES': True,
'NO_METADATA': True}, context, feedback),
['ogrinfo',
'-json -features -nomd "' +
source + '" filename_with_spaces'])
source = os.path.join(testDataPath, 'filename with spaces.gml')
self.assertEqual(
alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y',
'FEATURES': True,
'NO_METADATA': True}, context, feedback),
['ogrinfo',
'-json -features -nomd "' +
source + '" filename_with_spaces -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y'])
source = os.path.join(testDataPath, 'filename with spaces.gml')
self.assertEqual(
alg.getConsoleCommands({'INPUT': source + '|credential:X=Y|credential:Z=A',
'FEATURES': True,
'NO_METADATA': True}, context, feedback),
['ogrinfo',
'-json -features -nomd "' +
source + '" filename_with_spaces --config X Y --config Z A'])
def testBuffer(self):
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()

View File

@ -0,0 +1,143 @@
{
"description":"C:/OSGeo4W/apps/qgis-dev/python/plugins/processing/tests/testdata/lines.gml",
"driverShortName":"GML",
"driverLongName":"Geography Markup Language (GML)",
"layers":[
{
"name":"lines",
"metadata":{
},
"geometryFields":[
{
"name":"",
"type":"LineString",
"nullable":true,
"extent":[
-1.0,
-3.0,
11.0,
5.0
],
"coordinateSystem":{
"wkt":"GEOGCRS[\"WGS 84\",\n ENSEMBLE[\"World Geodetic System 1984 ensemble\",\n MEMBER[\"World Geodetic System 1984 (Transit)\"],\n MEMBER[\"World Geodetic System 1984 (G730)\"],\n MEMBER[\"World Geodetic System 1984 (G873)\"],\n MEMBER[\"World Geodetic System 1984 (G1150)\"],\n MEMBER[\"World Geodetic System 1984 (G1674)\"],\n MEMBER[\"World Geodetic System 1984 (G1762)\"],\n MEMBER[\"World Geodetic System 1984 (G2139)\"],\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]],\n ENSEMBLEACCURACY[2.0]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n CS[ellipsoidal,2],\n AXIS[\"geodetic latitude (Lat)\",north,\n ORDER[1],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n AXIS[\"geodetic longitude (Lon)\",east,\n ORDER[2],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n USAGE[\n SCOPE[\"Horizontal component of 3D system.\"],\n AREA[\"World.\"],\n BBOX[-90,-180,90,180]],\n ID[\"EPSG\",4326]]",
"projjson":{
"$schema":"https://proj.org/schemas/v0.7/projjson.schema.json",
"type":"GeographicCRS",
"name":"WGS 84",
"datum_ensemble":{
"name":"World Geodetic System 1984 ensemble",
"members":[
{
"name":"World Geodetic System 1984 (Transit)",
"id":{
"authority":"EPSG",
"code":1166
}
},
{
"name":"World Geodetic System 1984 (G730)",
"id":{
"authority":"EPSG",
"code":1152
}
},
{
"name":"World Geodetic System 1984 (G873)",
"id":{
"authority":"EPSG",
"code":1153
}
},
{
"name":"World Geodetic System 1984 (G1150)",
"id":{
"authority":"EPSG",
"code":1154
}
},
{
"name":"World Geodetic System 1984 (G1674)",
"id":{
"authority":"EPSG",
"code":1155
}
},
{
"name":"World Geodetic System 1984 (G1762)",
"id":{
"authority":"EPSG",
"code":1156
}
},
{
"name":"World Geodetic System 1984 (G2139)",
"id":{
"authority":"EPSG",
"code":1309
}
}
],
"ellipsoid":{
"name":"WGS 84",
"semi_major_axis":6378137,
"inverse_flattening":298.257223563
},
"accuracy":"2.0",
"id":{
"authority":"EPSG",
"code":6326
}
},
"coordinate_system":{
"subtype":"ellipsoidal",
"axis":[
{
"name":"Geodetic latitude",
"abbreviation":"Lat",
"direction":"north",
"unit":"degree"
},
{
"name":"Geodetic longitude",
"abbreviation":"Lon",
"direction":"east",
"unit":"degree"
}
]
},
"scope":"Horizontal component of 3D system.",
"area":"World.",
"bbox":{
"south_latitude":-90,
"west_longitude":-180,
"north_latitude":90,
"east_longitude":180
},
"id":{
"authority":"EPSG",
"code":4326
}
},
"dataAxisToSRSAxisMapping":[
2,
1
]
}
}
],
"featureCount":6,
"fields":[
{
"name":"fid",
"type":"String",
"nullable":false,
"uniqueConstraint":false
}
]
}
],
"metadata":{
},
"domains":{
}
}

View File

@ -0,0 +1,74 @@
<pre>INFO: Open of `C:/OSGeo4W/apps/qgis-dev/python/plugins/processing/tests/testdata/points_lines.gpkg'
using driver `GPKG' successful.
Layer name: points
Geometry: Point
Feature Count: 9
Extent: (0.000000, -5.000000) - (8.000000, 3.000000)
Layer SRS WKT:
GEOGCRS["WGS 84",
ENSEMBLE["World Geodetic System 1984 ensemble",
MEMBER["World Geodetic System 1984 (Transit)"],
MEMBER["World Geodetic System 1984 (G730)"],
MEMBER["World Geodetic System 1984 (G873)"],
MEMBER["World Geodetic System 1984 (G1150)"],
MEMBER["World Geodetic System 1984 (G1674)"],
MEMBER["World Geodetic System 1984 (G1762)"],
MEMBER["World Geodetic System 1984 (G2139)"],
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]],
ENSEMBLEACCURACY[2.0]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["geodetic latitude (Lat)",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["geodetic longitude (Lon)",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
USAGE[
SCOPE["Horizontal component of 3D system."],
AREA["World."],
BBOX[-90,-180,90,180]],
ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
FID Column = fid
Geometry Column = geom
id: Integer (0.0)
id2: Integer (0.0)
Layer name: lines
Geometry: Line String
Feature Count: 7
Extent: (-1.000000, -3.000000) - (11.000000, 5.000000)
Layer SRS WKT:
GEOGCRS["WGS 84",
ENSEMBLE["World Geodetic System 1984 ensemble",
MEMBER["World Geodetic System 1984 (Transit)"],
MEMBER["World Geodetic System 1984 (G730)"],
MEMBER["World Geodetic System 1984 (G873)"],
MEMBER["World Geodetic System 1984 (G1150)"],
MEMBER["World Geodetic System 1984 (G1674)"],
MEMBER["World Geodetic System 1984 (G1762)"],
MEMBER["World Geodetic System 1984 (G2139)"],
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]],
ENSEMBLEACCURACY[2.0]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["geodetic latitude (Lat)",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["geodetic longitude (Lon)",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
USAGE[
SCOPE["Horizontal component of 3D system."],
AREA["World."],
BBOX[-90,-180,90,180]],
ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
FID Column = fid
Geometry Column = geom</pre>

View File

@ -0,0 +1,279 @@
{
"description":"C:/OSGeo4W/apps/qgis-dev/python/plugins/processing/tests/testdata/points_lines.gpkg",
"driverShortName":"GPKG",
"driverLongName":"GeoPackage",
"layers":[
{
"name":"points",
"metadata":{
},
"geometryFields":[
{
"name":"geom",
"type":"Point",
"nullable":true,
"extent":[
0.0,
-5.0,
8.0,
3.0
],
"coordinateSystem":{
"wkt":"GEOGCRS[\"WGS 84\",\n ENSEMBLE[\"World Geodetic System 1984 ensemble\",\n MEMBER[\"World Geodetic System 1984 (Transit)\"],\n MEMBER[\"World Geodetic System 1984 (G730)\"],\n MEMBER[\"World Geodetic System 1984 (G873)\"],\n MEMBER[\"World Geodetic System 1984 (G1150)\"],\n MEMBER[\"World Geodetic System 1984 (G1674)\"],\n MEMBER[\"World Geodetic System 1984 (G1762)\"],\n MEMBER[\"World Geodetic System 1984 (G2139)\"],\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]],\n ENSEMBLEACCURACY[2.0]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n CS[ellipsoidal,2],\n AXIS[\"geodetic latitude (Lat)\",north,\n ORDER[1],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n AXIS[\"geodetic longitude (Lon)\",east,\n ORDER[2],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n USAGE[\n SCOPE[\"Horizontal component of 3D system.\"],\n AREA[\"World.\"],\n BBOX[-90,-180,90,180]],\n ID[\"EPSG\",4326]]",
"projjson":{
"$schema":"https://proj.org/schemas/v0.7/projjson.schema.json",
"type":"GeographicCRS",
"name":"WGS 84",
"datum_ensemble":{
"name":"World Geodetic System 1984 ensemble",
"members":[
{
"name":"World Geodetic System 1984 (Transit)",
"id":{
"authority":"EPSG",
"code":1166
}
},
{
"name":"World Geodetic System 1984 (G730)",
"id":{
"authority":"EPSG",
"code":1152
}
},
{
"name":"World Geodetic System 1984 (G873)",
"id":{
"authority":"EPSG",
"code":1153
}
},
{
"name":"World Geodetic System 1984 (G1150)",
"id":{
"authority":"EPSG",
"code":1154
}
},
{
"name":"World Geodetic System 1984 (G1674)",
"id":{
"authority":"EPSG",
"code":1155
}
},
{
"name":"World Geodetic System 1984 (G1762)",
"id":{
"authority":"EPSG",
"code":1156
}
},
{
"name":"World Geodetic System 1984 (G2139)",
"id":{
"authority":"EPSG",
"code":1309
}
}
],
"ellipsoid":{
"name":"WGS 84",
"semi_major_axis":6378137,
"inverse_flattening":298.257223563
},
"accuracy":"2.0",
"id":{
"authority":"EPSG",
"code":6326
}
},
"coordinate_system":{
"subtype":"ellipsoidal",
"axis":[
{
"name":"Geodetic latitude",
"abbreviation":"Lat",
"direction":"north",
"unit":"degree"
},
{
"name":"Geodetic longitude",
"abbreviation":"Lon",
"direction":"east",
"unit":"degree"
}
]
},
"scope":"Horizontal component of 3D system.",
"area":"World.",
"bbox":{
"south_latitude":-90,
"west_longitude":-180,
"north_latitude":90,
"east_longitude":180
},
"id":{
"authority":"EPSG",
"code":4326
}
},
"dataAxisToSRSAxisMapping":[
2,
1
]
}
}
],
"featureCount":9,
"fidColumnName":"fid",
"fields":[
{
"name":"id",
"type":"Integer",
"nullable":true,
"uniqueConstraint":false
},
{
"name":"id2",
"type":"Integer",
"nullable":true,
"uniqueConstraint":false
}
]
},
{
"name":"lines",
"metadata":{
},
"geometryFields":[
{
"name":"geom",
"type":"LineString",
"nullable":true,
"extent":[
-1.0,
-3.0,
11.0,
5.0
],
"coordinateSystem":{
"wkt":"GEOGCRS[\"WGS 84\",\n ENSEMBLE[\"World Geodetic System 1984 ensemble\",\n MEMBER[\"World Geodetic System 1984 (Transit)\"],\n MEMBER[\"World Geodetic System 1984 (G730)\"],\n MEMBER[\"World Geodetic System 1984 (G873)\"],\n MEMBER[\"World Geodetic System 1984 (G1150)\"],\n MEMBER[\"World Geodetic System 1984 (G1674)\"],\n MEMBER[\"World Geodetic System 1984 (G1762)\"],\n MEMBER[\"World Geodetic System 1984 (G2139)\"],\n ELLIPSOID[\"WGS 84\",6378137,298.257223563,\n LENGTHUNIT[\"metre\",1]],\n ENSEMBLEACCURACY[2.0]],\n PRIMEM[\"Greenwich\",0,\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n CS[ellipsoidal,2],\n AXIS[\"geodetic latitude (Lat)\",north,\n ORDER[1],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n AXIS[\"geodetic longitude (Lon)\",east,\n ORDER[2],\n ANGLEUNIT[\"degree\",0.0174532925199433]],\n USAGE[\n SCOPE[\"Horizontal component of 3D system.\"],\n AREA[\"World.\"],\n BBOX[-90,-180,90,180]],\n ID[\"EPSG\",4326]]",
"projjson":{
"$schema":"https://proj.org/schemas/v0.7/projjson.schema.json",
"type":"GeographicCRS",
"name":"WGS 84",
"datum_ensemble":{
"name":"World Geodetic System 1984 ensemble",
"members":[
{
"name":"World Geodetic System 1984 (Transit)",
"id":{
"authority":"EPSG",
"code":1166
}
},
{
"name":"World Geodetic System 1984 (G730)",
"id":{
"authority":"EPSG",
"code":1152
}
},
{
"name":"World Geodetic System 1984 (G873)",
"id":{
"authority":"EPSG",
"code":1153
}
},
{
"name":"World Geodetic System 1984 (G1150)",
"id":{
"authority":"EPSG",
"code":1154
}
},
{
"name":"World Geodetic System 1984 (G1674)",
"id":{
"authority":"EPSG",
"code":1155
}
},
{
"name":"World Geodetic System 1984 (G1762)",
"id":{
"authority":"EPSG",
"code":1156
}
},
{
"name":"World Geodetic System 1984 (G2139)",
"id":{
"authority":"EPSG",
"code":1309
}
}
],
"ellipsoid":{
"name":"WGS 84",
"semi_major_axis":6378137,
"inverse_flattening":298.257223563
},
"accuracy":"2.0",
"id":{
"authority":"EPSG",
"code":6326
}
},
"coordinate_system":{
"subtype":"ellipsoidal",
"axis":[
{
"name":"Geodetic latitude",
"abbreviation":"Lat",
"direction":"north",
"unit":"degree"
},
{
"name":"Geodetic longitude",
"abbreviation":"Lon",
"direction":"east",
"unit":"degree"
}
]
},
"scope":"Horizontal component of 3D system.",
"area":"World.",
"bbox":{
"south_latitude":-90,
"west_longitude":-180,
"north_latitude":90,
"east_longitude":180
},
"id":{
"authority":"EPSG",
"code":4326
}
},
"dataAxisToSRSAxisMapping":[
2,
1
]
}
}
],
"featureCount":7,
"fidColumnName":"fid",
"fields":[
]
}
],
"metadata":{
},
"domains":{
},
"relationships":{
}
}

View File

@ -242,6 +242,69 @@ tests:
- 'Geometry: Line String'
- 'Feature Count: [6|7]' # On some platforms returns 6 instead of 7...
- algorithm: gdal:ogrinfo
name: ogrinfo all layers
params:
INPUT:
name: points_lines.gpkg
type: vector
SUMMARY_ONLY: 'True'
ALL_LAYERS: 'True'
results:
OUTPUT:
name: expected/gdal/vector_info_2.html
type: regex
rules:
- 'Layer name: points'
- 'Geometry: Point'
- 'Feature Count: 9'
- 'Extent: \(0.000000, -5.000000\) - \(8.000000, 3.000000\)'
- 'Layer name: lines'
- 'Geometry: Line String'
- 'Feature Count: 7'
- 'Extent: \(-1.000000, -3.000000\) - \(11.000000, 5.000000\)'
- algorithm: gdal:ogrinfojson
name: ogrinfo (json)
condition:
gdal:
at_least: 3070000
params:
INPUT:
name: lines.gml
type: vector
results:
OUTPUT:
name: expected/gdal/vector_info.json
type: regex
rules:
- '"extent":\[\n\s*-1.0,\s*-3.0,\n\s*11.0,\n\s*5.0\n\s*\],'
- '"type":"LineString",'
- '"featureCount":[6|7],' # On some platforms returns 6 instead of 7...
- algorithm: gdal:ogrinfojson
name: ogrinfo (json) all layers
condition:
gdal:
at_least: 3070000
params:
INPUT:
name: points_lines.gpkg
type: vector
results:
OUTPUT:
name: expected/gdal/vector_info_2.json
type: regex
rules:
- '"name":"points",'
- '"type":"Point",'
- '"extent":\[\n\s*0.0,\s*-5.0,\n\s*8.0,\n\s*3.0\n\s*\],'
- '"featureCount":9,'
- '"name":"lines",'
- '"type":"LineString",'
- '"extent":\[\n\s*-1.0,\s*-3.0,\n\s*11.0,\n\s*5.0\n\s*\],'
- '"featureCount":7,'
- algorithm: gdal:onesidebuffer
name: One-sided buffer (left-handed)
params: