Skip to content

Commit abe9fd0

Browse files
committedMay 29, 2015
Move more wkb type code to QgsWKBTypes. Fix possibility to load curved geometries into QGIS
1 parent dd53fda commit abe9fd0

File tree

6 files changed

+23
-59
lines changed

6 files changed

+23
-59
lines changed
 

‎src/core/geometry/qgscompoundcurvev2.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,16 @@ void QgsCompoundCurveV2::drawAsPolygon( QPainter& p ) const
470470
bool QgsCompoundCurveV2::insertVertex( const QgsVertexId& position, const QgsPointV2& vertex )
471471
{
472472
QList< QPair<int, QgsVertexId> > curveIds = curveVertexId( position );
473-
QList< QPair<int, QgsVertexId> >::const_iterator idIt = curveIds.constBegin();
474-
for ( ; idIt != curveIds.constEnd(); ++idIt )
473+
if ( curveIds.size() < 1 )
475474
{
476-
//return after first result
477-
return mCurves[idIt->first]->insertVertex( idIt->second, vertex );
475+
return false;
478476
}
479-
return false;
477+
int curveId = curveIds.at( 0 ).first;
478+
if ( curveId >= mCurves.size() )
479+
{
480+
return false;
481+
}
482+
return mCurves[curveId]->insertVertex( curveIds.at( 0 ).second, vertex );
480483
}
481484

482485
bool QgsCompoundCurveV2::moveVertex( const QgsVertexId& position, const QgsPointV2& newPos )

‎src/core/qgsdatasourceuri.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -139,35 +139,7 @@ QgsDataSourceURI::QgsDataSourceURI( QString uri )
139139
}
140140
else if ( pname == "type" )
141141
{
142-
QString geomTypeUpper = pval.toUpper();
143-
if ( geomTypeUpper == "POINT" )
144-
{
145-
mWkbType = QGis::WKBPoint;
146-
}
147-
else if ( geomTypeUpper == "LINESTRING" || geomTypeUpper == "LINE" )
148-
{
149-
mWkbType = QGis::WKBLineString;
150-
}
151-
else if ( geomTypeUpper == "POLYGON" )
152-
{
153-
mWkbType = QGis::WKBPolygon;
154-
}
155-
else if ( geomTypeUpper == "MULTIPOINT" )
156-
{
157-
mWkbType = QGis::WKBMultiPoint;
158-
}
159-
else if ( geomTypeUpper == "MULTILINESTRING" )
160-
{
161-
mWkbType = QGis::WKBMultiLineString;
162-
}
163-
else if ( geomTypeUpper == "MULTIPOLYGON" )
164-
{
165-
mWkbType = QGis::WKBMultiPolygon;
166-
}
167-
else
168-
{
169-
mWkbType = QGis::WKBUnknown;
170-
}
142+
mWkbType = ( QGis::WkbType )QgsWKBTypes::parseType( pval );
171143
}
172144
else if ( pname == "selectatid" )
173145
{

‎src/providers/postgres/qgspostgresconn.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,38 +1474,26 @@ QString QgsPostgresConn::postgisWkbTypeName( QGis::WkbType wkbType )
14741474
return geometryType;
14751475
}
14761476

1477-
QString QgsPostgresConn::postgisTypeFilter( QString geomCol, QGis::WkbType geomType, bool castToGeometry )
1477+
QString QgsPostgresConn::postgisTypeFilter( QString geomCol, QgsWKBTypes::Type wkbType, bool castToGeometry )
14781478
{
14791479
geomCol = quotedIdentifier( geomCol );
14801480
if ( castToGeometry )
14811481
geomCol += "::geometry";
14821482

1483+
QgsWKBTypes::GeometryType geomType = QgsWKBTypes::geometryType( wkbType );
14831484
switch ( geomType )
14841485
{
1485-
case QGis::WKBPoint:
1486-
case QGis::WKBPoint25D:
1487-
case QGis::WKBMultiPoint:
1488-
case QGis::WKBMultiPoint25D:
1489-
return QString( "upper(geometrytype(%1)) IN ('POINT','MULTIPOINT','POINTM','MULTIPOINTM')" ).arg( geomCol );
1490-
case QGis::WKBLineString:
1491-
case QGis::WKBLineString25D:
1492-
case QGis::WKBMultiLineString:
1493-
case QGis::WKBMultiLineString25D:
1494-
return QString( "upper(geometrytype(%1)) IN ('LINESTRING','MULTILINESTRING','LINESTRINGM','MULTILINESTRINGM')" ).arg( geomCol );
1495-
case QGis::WKBPolygon:
1496-
case QGis::WKBPolygon25D:
1497-
case QGis::WKBMultiPolygon:
1498-
case QGis::WKBMultiPolygon25D:
1499-
return QString( "upper(geometrytype(%1)) IN ('POLYGON','MULTIPOLYGON','POLYGONM','MULTIPOLYGONM','POLYHEDRALSURFACE','TIN')" ).arg( geomCol );
1500-
case QGis::WKBNoGeometry:
1486+
case QgsWKBTypes::PointGeometry:
1487+
return QString( "upper(geometrytype(%1)) IN ('POINT','POINTZ','POINTM','POINTZM','MULTIPOINT','MULTIPOINTZ','MULTIPOINTM','MULTIPOINTZM')" ).arg( geomCol );
1488+
case QgsWKBTypes::LineGeometry:
1489+
return QString( "upper(geometrytype(%1)) IN ('LINESTRING','LINESTRINGZ','LINESTRINGM','LINESTRINGZM','CIRCULARSTRING','CIRCULARSTRINGZ','CIRCULARSTRINGM','CIRCULARSTRINGZM','COMPOUNDCURVE','COMPOUNDCURVEZ','COMPOUNDCURVEM','COMPOUNDCURVEZM','MULTILINESTRING','MULTILINESTRINGZ','MULTILINESTRINGM','MULTILINESTRINGZM','MULTICURVE','MULTICURVEZ','MULTICURVEM','MULTICURVEZM')" ).arg( geomCol );
1490+
case QgsWKBTypes::PolygonGeometry:
1491+
return QString( "upper(geometrytype(%1)) IN ('POLYGON','POLYGONZ','POLYGONM','POLYGONZM','CURVEPOLYGON','CURVEPOLYGONZ','CURVEPOLYGONM','CURVEPOLYGONZM','MULTIPOLYGON','MULTIPOLYGONZ','MULTIPOLYGONM','MULTIPOLYGONZM','MULTIPOLYGONM','MULTISURFACE','MULTISURFACEZ','MULTISURFACEM','MULTISURFACEZM','POLYHEDRALSURFACE','TIN')" ).arg( geomCol );
1492+
case QgsWKBTypes::NullGeometry:
15011493
return QString( "geometrytype(%1) IS NULL" ).arg( geomCol );
1502-
case QGis::WKBUnknown:
1503-
Q_ASSERT( !"unknown geometry unexpected" );
1494+
default: //unknown geometry
15041495
return QString::null;
15051496
}
1506-
1507-
Q_ASSERT( !"unexpected geomType" );
1508-
return QString::null;
15091497
}
15101498

15111499
int QgsPostgresConn::postgisWkbTypeDim( QGis::WkbType wkbType )

‎src/providers/postgres/qgspostgresconn.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "qgis.h"
2828
#include "qgsdatasourceuri.h"
29+
#include "qgswkbtypes.h"
2930

3031
extern "C"
3132
{
@@ -304,7 +305,7 @@ class QgsPostgresConn : public QObject
304305
static int postgisWkbTypeDim( QGis::WkbType wkbType );
305306
static void postgisWkbType( QGis::WkbType wkbType, QString &geometryType, int &dim );
306307

307-
static QString postgisTypeFilter( QString geomCol, QGis::WkbType wkbType, bool castToGeometry );
308+
static QString postgisTypeFilter( QString geomCol, QgsWKBTypes::Type wkbType, bool castToGeometry );
308309

309310
static QGis::WkbType wkbTypeFromGeomType( QGis::GeometryType geomType );
310311
static QGis::WkbType wkbTypeFromOgcWkbType( unsigned int ogcWkbType );

‎src/providers/postgres/qgspostgresfeatureiterator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ QString QgsPostgresFeatureIterator::whereClauseRect()
319319

320320
if ( mSource->mRequestedGeomType != QGis::WKBUnknown && mSource->mRequestedGeomType != mSource->mDetectedGeomType )
321321
{
322-
whereClause += QString( " AND %1" ).arg( QgsPostgresConn::postgisTypeFilter( mSource->mGeometryColumn, mSource->mRequestedGeomType, castToGeometry ) );
322+
whereClause += QString( " AND %1" ).arg( QgsPostgresConn::postgisTypeFilter( mSource->mGeometryColumn, ( QgsWKBTypes::Type )mSource->mRequestedGeomType, castToGeometry ) );
323323
}
324324

325325
return whereClause;

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ QString QgsPostgresProvider::filterWhereClause() const
571571

572572
if ( mRequestedGeomType != QGis::WKBUnknown && mRequestedGeomType != mDetectedGeomType )
573573
{
574-
where += delim + QgsPostgresConn::postgisTypeFilter( mGeometryColumn, mRequestedGeomType, mSpatialColType == sctGeography );
574+
where += delim + QgsPostgresConn::postgisTypeFilter( mGeometryColumn, ( QgsWKBTypes::Type )mRequestedGeomType, mSpatialColType == sctGeography );
575575
delim = " AND ";
576576
}
577577

0 commit comments

Comments
 (0)
Please sign in to comment.