Skip to content

Commit

Permalink
[processing][feature] Add tests for gdal:ogrinfo and gdal:ogrinfojson
Browse files Browse the repository at this point in the history
  • Loading branch information
agiudiceandrea authored and nyalldawson committed Jul 10, 2024
1 parent 3d8a7a7 commit 5f85a82
Show file tree
Hide file tree
Showing 5 changed files with 662 additions and 1 deletion.
104 changes: 103 additions & 1 deletion python/plugins/processing/tests/GdalAlgorithmsVectorTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

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
Expand Down Expand Up @@ -146,6 +146,27 @@ def testOgrInfo(self):
'-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,
Expand Down Expand Up @@ -191,6 +212,87 @@ def testOgrInfo(self):
'-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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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":{
}
}
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
Loading

0 comments on commit 5f85a82

Please sign in to comment.