-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OGR provider] Report curve geometry types. Do geometry type conversi…
…ons when needed on feature creation/modification
- Loading branch information
Showing
4 changed files
with
165 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for the OGR/GPKG provider. | ||
.. note:: This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
""" | ||
__author__ = 'Even Rouault' | ||
__date__ = '2016-04-21' | ||
__copyright__ = 'Copyright 2016, Even Rouault' | ||
# This will get replaced with a git SHA1 when you do a git archive | ||
__revision__ = '$Format:%H$' | ||
|
||
import qgis # NOQA | ||
|
||
import os | ||
import tempfile | ||
import shutil | ||
import glob | ||
from osgeo import gdal, ogr | ||
|
||
from qgis.core import QgsVectorLayer, QgsFeature, QgsGeometry | ||
from qgis.testing import start_app, unittest | ||
from utilities import unitTestDataPath | ||
|
||
start_app() | ||
|
||
|
||
def GDAL_COMPUTE_VERSION(maj, min, rev): | ||
return ((maj) * 1000000 + (min) * 10000 + (rev) * 100) | ||
|
||
|
||
class TestPyQgsOGRProviderGpkg(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
"""Run before all tests""" | ||
# Create test layer | ||
cls.basetestpath = tempfile.mkdtemp() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
"""Run after all tests""" | ||
shutil.rmtree(cls.basetestpath, True) | ||
|
||
def testSingleToMultiPolygonPromotion(self): | ||
|
||
version_num = int(gdal.VersionInfo('VERSION_NUM')) | ||
if version_num < GDAL_COMPUTE_VERSION(1, 11, 0): | ||
return | ||
|
||
tmpfile = os.path.join(self.basetestpath, 'testSingleToMultiPolygonPromotion.gpkg') | ||
ds = ogr.GetDriverByName('GPKG').CreateDataSource(tmpfile) | ||
lyr = ds.CreateLayer('test', geom_type=ogr.wkbMultiPolygon) | ||
ds = None | ||
|
||
vl = QgsVectorLayer(u'{}|layerid=0'.format(tmpfile), u'test', u'ogr') | ||
f = QgsFeature() | ||
f.setGeometry(QgsGeometry.fromWkt('POLYGON ((0 0,0 1,1 1,0 0))')) | ||
vl.dataProvider().addFeatures([f]) | ||
got = [f.geometry().exportToWkt(0) for f in vl.getFeatures()][0] | ||
self.assertEqual(got, 'MultiPolygon (((0 0, 0 1, 1 1, 0 0)))') | ||
|
||
def testCurveGeometryType(self): | ||
|
||
version_num = int(gdal.VersionInfo('VERSION_NUM')) | ||
if version_num < GDAL_COMPUTE_VERSION(2, 0, 0): | ||
return | ||
|
||
tmpfile = os.path.join(self.basetestpath, 'testCurveGeometryType.gpkg') | ||
ds = ogr.GetDriverByName('GPKG').CreateDataSource(tmpfile) | ||
lyr = ds.CreateLayer('test', geom_type=ogr.wkbCurvePolygon) | ||
ds = None | ||
|
||
vl = QgsVectorLayer(u'{}'.format(tmpfile), u'test', u'ogr') | ||
self.assertEqual(vl.dataProvider().subLayers(), [u'0:test:0:CurvePolygon']) | ||
f = QgsFeature() | ||
f.setGeometry(QgsGeometry.fromWkt('POLYGON ((0 0,0 1,1 1,0 0))')) | ||
vl.dataProvider().addFeatures([f]) | ||
got = [f.geometry().exportToWkt(0) for f in vl.getFeatures()][0] | ||
self.assertEqual(got, 'CurvePolygon ((0 0, 0 1, 1 1, 0 0))') | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |