Skip to content

Commit

Permalink
[ogr] return multi{linestring,polygon} type for shapefile driver
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jul 10, 2017
1 parent 18c3634 commit 1aa0091
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ email : sherman at mrcc.com
#include "qgsgeometry.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsvectorlayerexporter.h"
#include "qgswkbtypes.h"
#include "qgis.h"


Expand Down Expand Up @@ -1175,7 +1176,12 @@ size_t QgsOgrProvider::layerCount() const
*/
QgsWkbTypes::Type QgsOgrProvider::wkbType() const
{
return static_cast<QgsWkbTypes::Type>( mOGRGeomType );
QgsWkbTypes::Type wkb = static_cast<QgsWkbTypes::Type>( mOGRGeomType );
if ( ogrDriverName == QLatin1String( "ESRI Shapefile" ) && ( wkb == QgsWkbTypes::LineString || wkb == QgsWkbTypes::Polygon ) )
{
wkb = QgsWkbTypes::multiType( wkb );
}
return wkb;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/src/python/test_provider_virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_Query(self):
# the same, without specifying the geometry column name
l2 = QgsVectorLayer("?layer_ref=%s&query=%s&uid=OBJECTID" % (l1.id(), query), "vtab", "virtual", False)
self.assertEqual(l2.isValid(), True)
self.assertEqual(l2.dataProvider().wkbType(), 3)
self.assertEqual(l2.dataProvider().wkbType(), 6)
ref_sum2 = sum(f.attributes()[0] for f in l2.getFeatures())
ref_sum3 = sum(f.id() for f in l2.getFeatures())
# check we have the same rows
Expand All @@ -204,7 +204,7 @@ def test_Query(self):
# with two geometry columns, but no geometry column specified (will take the first)
l2 = QgsVectorLayer("?layer_ref=%s&query=%s&uid=OBJECTID" % (l1.id(), query), "vtab", "virtual", False)
self.assertEqual(l2.isValid(), True)
self.assertEqual(l2.dataProvider().wkbType(), 3)
self.assertEqual(l2.dataProvider().wkbType(), 6)
ref_sum2 = sum(f.attributes()[0] for f in l2.getFeatures())
ref_sum3 = sum(f.id() for f in l2.getFeatures())
# check we have the same rows
Expand Down Expand Up @@ -343,7 +343,7 @@ def test_reopen(self):

l2 = QgsVectorLayer(tmp, "tt", "virtual", False)
self.assertEqual(l2.isValid(), True)
self.assertEqual(l2.dataProvider().wkbType(), 3)
self.assertEqual(l2.dataProvider().wkbType(), 6)
self.assertEqual(l2.dataProvider().featureCount(), 4)

def test_reopen2(self):
Expand Down Expand Up @@ -448,7 +448,7 @@ def test_sql2(self):
l4 = QgsVectorLayer("?query=%s&uid=ObjectId" % query, "tt", "virtual")
self.assertEqual(l4.isValid(), True)

self.assertEqual(l4.dataProvider().wkbType(), 3)
self.assertEqual(l4.dataProvider().wkbType(), 6)
self.assertEqual(l4.dataProvider().crs().postgisSrid(), 4326)

n = 0
Expand Down

0 comments on commit 1aa0091

Please sign in to comment.