Skip to content

Commit

Permalink
[processing] simple test for ogr buffering
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Nov 12, 2016
1 parent 159fda6 commit 5991ecc
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 14 deletions.
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/ogr2ogrbuffer.py
Expand Up @@ -111,7 +111,7 @@ def getConsoleCommands(self):
if field is not None and multi:
arguments.append('-explodecollections')

if len(options) > 0:
if options is not None and len(options) > 0:
arguments.append(options)

commands = []
Expand Down
@@ -0,0 +1,16 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>buffer_lines</Name>
<ElementPath>buffer_lines</ElementPath>
<!--POLYGON-->
<GeometryType>3</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>7</FeatureCount>
<ExtentXMin>-2.00000</ExtentXMin>
<ExtentXMax>12.00000</ExtentXMax>
<ExtentYMin>-4.00000</ExtentYMin>
<ExtentYMax>6.00000</ExtentYMax>
</DatasetSpecificInfo>
</GMLFeatureClass>
</GMLFeatureClassList>

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions python/plugins/processing/tests/testdata/gdal_algorithm_tests.yaml
Expand Up @@ -72,3 +72,17 @@ tests:
- 'Geometry: Line String'
- 'Feature Count: [6|7]' # On some platforms returns 6 instead of 7...

- algorithm: gdalogr:buffervectors
name: OGR buffer lines
params:
DISSOLVEALL: false
DISTANCE: '1'
GEOMETRY: geometry
INPUT_LAYER:
name: lines.gml
type: vector
MULTI: false
results:
OUTPUT_LAYER:
name: expected/gdal/buffer_lines.gml
type: vector
9 changes: 2 additions & 7 deletions python/plugins/processing/tools/dataobjects.py
Expand Up @@ -331,12 +331,7 @@ def exportVectorLayer(layer, supported=None):
del writer
return output
else:
isASCII = True
try:
str(layer.source())
except UnicodeEncodeError:
isASCII = False
if not os.path.splitext(layer.source())[1].lower() in supported or not isASCII:
if not os.path.splitext(layer.source())[1].lower() in supported:
writer = QgsVectorFileWriter(
output, systemEncoding,
layer.fields(), layer.wkbType(),
Expand All @@ -347,7 +342,7 @@ def exportVectorLayer(layer, supported=None):
del writer
return output
else:
return str(layer.source())
return layer.source()


def exportRasterLayer(layer):
Expand Down
7 changes: 1 addition & 6 deletions python/plugins/processing/tools/vector.py
Expand Up @@ -538,7 +538,6 @@ def ogrConnectionString(uri):
return '"' + ogrstr + '"'


#
# The uri parameter is an URI from any QGIS provider,
# so could have different formats.
# Example formats:
Expand Down Expand Up @@ -623,7 +622,7 @@ def __init__(self, destination, encoding, fields, geometryType,

if encoding is None:
settings = QSettings()
encoding = settings.value('/Processing/encoding', 'System', type=str)
encoding = settings.value('/Processing/encoding', 'System', str)

if self.destination.startswith(self.MEMORY_LAYER_PREFIX):
self.isNotFileBased = True
Expand All @@ -650,8 +649,6 @@ def __init__(self, destination, encoding, fields, geometryType,
QgsCredentials.instance().put(connInfo, user, passwd)
else:
raise GeoAlgorithmExecutionException("Couldn't connect to database")
# fix_print_with_import
print(uri.uri())
try:
db = postgis.GeoDB(host=uri.host(), port=int(uri.port()),
dbname=uri.database(), user=user, passwd=passwd)
Expand Down Expand Up @@ -682,8 +679,6 @@ def _runSQL(sql):
elif self.destination.startswith(self.SPATIALITE_LAYER_PREFIX):
self.isNotFileBased = True
uri = QgsDataSourceUri(self.destination[len(self.SPATIALITE_LAYER_PREFIX):])
# fix_print_with_import
print(uri.uri())
try:
db = spatialite.GeoDB(uri=uri)
except spatialite.DbError as e:
Expand Down

0 comments on commit 5991ecc

Please sign in to comment.