Skip to content
Permalink
Browse files

Move more wkb type code to QgsWKBTypes. Fix possibility to load curve…

…d geometries into QGIS
  • Loading branch information
mhugent committed May 29, 2015
1 parent dd53fda commit abe9fd039915f668d311cab9bdc0148aa0d0575c
@@ -470,13 +470,16 @@ void QgsCompoundCurveV2::drawAsPolygon( QPainter& p ) const
bool QgsCompoundCurveV2::insertVertex( const QgsVertexId& position, const QgsPointV2& vertex )
{
QList< QPair<int, QgsVertexId> > curveIds = curveVertexId( position );
QList< QPair<int, QgsVertexId> >::const_iterator idIt = curveIds.constBegin();
for ( ; idIt != curveIds.constEnd(); ++idIt )
if ( curveIds.size() < 1 )
{
//return after first result
return mCurves[idIt->first]->insertVertex( idIt->second, vertex );
return false;
}
return false;
int curveId = curveIds.at( 0 ).first;
if ( curveId >= mCurves.size() )
{
return false;
}
return mCurves[curveId]->insertVertex( curveIds.at( 0 ).second, vertex );
}

bool QgsCompoundCurveV2::moveVertex( const QgsVertexId& position, const QgsPointV2& newPos )
@@ -139,35 +139,7 @@ QgsDataSourceURI::QgsDataSourceURI( QString uri )
}
else if ( pname == "type" )
{
QString geomTypeUpper = pval.toUpper();
if ( geomTypeUpper == "POINT" )
{
mWkbType = QGis::WKBPoint;
}
else if ( geomTypeUpper == "LINESTRING" || geomTypeUpper == "LINE" )
{
mWkbType = QGis::WKBLineString;
}
else if ( geomTypeUpper == "POLYGON" )
{
mWkbType = QGis::WKBPolygon;
}
else if ( geomTypeUpper == "MULTIPOINT" )
{
mWkbType = QGis::WKBMultiPoint;
}
else if ( geomTypeUpper == "MULTILINESTRING" )
{
mWkbType = QGis::WKBMultiLineString;
}
else if ( geomTypeUpper == "MULTIPOLYGON" )
{
mWkbType = QGis::WKBMultiPolygon;
}
else
{
mWkbType = QGis::WKBUnknown;
}
mWkbType = ( QGis::WkbType )QgsWKBTypes::parseType( pval );
}
else if ( pname == "selectatid" )
{
@@ -1474,38 +1474,26 @@ QString QgsPostgresConn::postgisWkbTypeName( QGis::WkbType wkbType )
return geometryType;
}

QString QgsPostgresConn::postgisTypeFilter( QString geomCol, QGis::WkbType geomType, bool castToGeometry )
QString QgsPostgresConn::postgisTypeFilter( QString geomCol, QgsWKBTypes::Type wkbType, bool castToGeometry )
{
geomCol = quotedIdentifier( geomCol );
if ( castToGeometry )
geomCol += "::geometry";

QgsWKBTypes::GeometryType geomType = QgsWKBTypes::geometryType( wkbType );
switch ( geomType )
{
case QGis::WKBPoint:
case QGis::WKBPoint25D:
case QGis::WKBMultiPoint:
case QGis::WKBMultiPoint25D:
return QString( "upper(geometrytype(%1)) IN ('POINT','MULTIPOINT','POINTM','MULTIPOINTM')" ).arg( geomCol );
case QGis::WKBLineString:
case QGis::WKBLineString25D:
case QGis::WKBMultiLineString:
case QGis::WKBMultiLineString25D:
return QString( "upper(geometrytype(%1)) IN ('LINESTRING','MULTILINESTRING','LINESTRINGM','MULTILINESTRINGM')" ).arg( geomCol );
case QGis::WKBPolygon:
case QGis::WKBPolygon25D:
case QGis::WKBMultiPolygon:
case QGis::WKBMultiPolygon25D:
return QString( "upper(geometrytype(%1)) IN ('POLYGON','MULTIPOLYGON','POLYGONM','MULTIPOLYGONM','POLYHEDRALSURFACE','TIN')" ).arg( geomCol );
case QGis::WKBNoGeometry:
case QgsWKBTypes::PointGeometry:
return QString( "upper(geometrytype(%1)) IN ('POINT','POINTZ','POINTM','POINTZM','MULTIPOINT','MULTIPOINTZ','MULTIPOINTM','MULTIPOINTZM')" ).arg( geomCol );
case QgsWKBTypes::LineGeometry:
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 );
case QgsWKBTypes::PolygonGeometry:
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 );
case QgsWKBTypes::NullGeometry:
return QString( "geometrytype(%1) IS NULL" ).arg( geomCol );
case QGis::WKBUnknown:
Q_ASSERT( !"unknown geometry unexpected" );
default: //unknown geometry
return QString::null;
}

Q_ASSERT( !"unexpected geomType" );
return QString::null;
}

int QgsPostgresConn::postgisWkbTypeDim( QGis::WkbType wkbType )
@@ -26,6 +26,7 @@

#include "qgis.h"
#include "qgsdatasourceuri.h"
#include "qgswkbtypes.h"

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

static QString postgisTypeFilter( QString geomCol, QGis::WkbType wkbType, bool castToGeometry );
static QString postgisTypeFilter( QString geomCol, QgsWKBTypes::Type wkbType, bool castToGeometry );

static QGis::WkbType wkbTypeFromGeomType( QGis::GeometryType geomType );
static QGis::WkbType wkbTypeFromOgcWkbType( unsigned int ogcWkbType );
@@ -319,7 +319,7 @@ QString QgsPostgresFeatureIterator::whereClauseRect()

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

return whereClause;
@@ -571,7 +571,7 @@ QString QgsPostgresProvider::filterWhereClause() const

if ( mRequestedGeomType != QGis::WKBUnknown && mRequestedGeomType != mDetectedGeomType )
{
where += delim + QgsPostgresConn::postgisTypeFilter( mGeometryColumn, mRequestedGeomType, mSpatialColType == sctGeography );
where += delim + QgsPostgresConn::postgisTypeFilter( mGeometryColumn, ( QgsWKBTypes::Type )mRequestedGeomType, mSpatialColType == sctGeography );
delim = " AND ";
}

0 comments on commit abe9fd0

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