Skip to content
Permalink
Browse files

Merge pull request #4782 from nirvn/shapefile_wkbtype

  • Loading branch information
nirvn committed Jul 10, 2017
2 parents 18c3634 + 5b149fb commit 1693873e8aa407b3385fcc42c9597ea2b7bd5c0e
@@ -25,6 +25,7 @@
#include "qgsmessagelog.h"
#include "qgssettings.h"
#include "qgsexception.h"
#include "qgswkbtypes.h"

#include <QTextCodec>
#include <QFile>
@@ -334,7 +335,15 @@ bool QgsOgrFeatureIterator::readFeature( OGRFeatureH fet, QgsFeature &feature )

if ( geom )
{
feature.setGeometry( QgsOgrUtils::ogrGeometryToQgsGeometry( geom ) );
QgsGeometry g = QgsOgrUtils::ogrGeometryToQgsGeometry( geom );

// Insure that multipart datasets return multipart geometry
if ( QgsWkbTypes::isMultiType( mSource->mWkbType ) && !g.isMultipart() )
{
g.convertToMultiType();
}

feature.setGeometry( g );
}
else
feature.clearGeometry();
@@ -390,6 +399,7 @@ QgsOgrFeatureSource::QgsOgrFeatureSource( const QgsOgrProvider *p )
, mOgrGeometryTypeFilter( QgsOgrProvider::ogrWkbSingleFlatten( p->mOgrGeometryTypeFilter ) )
, mDriverName( p->ogrDriverName )
, mCrs( p->crs() )
, mWkbType( p->wkbType() )
{
for ( int i = ( p->mFirstFieldIsFid ) ? 1 : 0; i < mFields.size(); i++ )
mFieldsWithoutFid.append( mFields.at( i ) );
@@ -44,6 +44,7 @@ class QgsOgrFeatureSource : public QgsAbstractFeatureSource
OGRwkbGeometryType mOgrGeometryTypeFilter;
QString mDriverName;
QgsCoordinateReferenceSystem mCrs;
QgsWkbTypes::Type mWkbType = QgsWkbTypes::Unknown;

friend class QgsOgrFeatureIterator;
friend class QgsOgrExpressionCompiler;
@@ -30,6 +30,7 @@ email : sherman at mrcc.com
#include "qgsgeometry.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsvectorlayerexporter.h"
#include "qgswkbtypes.h"
#include "qgis.h"


@@ -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;
}

/**
@@ -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
@@ -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
@@ -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):
@@ -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

0 comments on commit 1693873

Please sign in to comment.
You can’t perform that action at this time.