Skip to content
Permalink
Browse files

wfs related fixes:

- wfs server: only filter by bbox if there was one given (fixes #8287)
- wfs provider: make feature attribute field types stick to the values
- vector layer properties, field properties: add (Qt) type column
- attribute table: sort Date and DateTime as such
- spatialindex: return false when an exception on insertion occured
  • Loading branch information
jef-n committed Jul 15, 2013
1 parent c77a48a commit 133398b390cc6e8641e7eb29b579067c6cbe460a
@@ -294,6 +294,7 @@ void QgsFieldsProperties::loadRows()
mAttributesList->setHorizontalHeaderItem( attrIdCol, new QTableWidgetItem( tr( "Id" ) ) );
mAttributesList->setHorizontalHeaderItem( attrNameCol, new QTableWidgetItem( tr( "Name" ) ) );
mAttributesList->setHorizontalHeaderItem( attrTypeCol, new QTableWidgetItem( tr( "Type" ) ) );
mAttributesList->setHorizontalHeaderItem( attrTypeNameCol, new QTableWidgetItem( tr( "Type name" ) ) );
mAttributesList->setHorizontalHeaderItem( attrLengthCol, new QTableWidgetItem( tr( "Length" ) ) );
mAttributesList->setHorizontalHeaderItem( attrPrecCol, new QTableWidgetItem( tr( "Precision" ) ) );
mAttributesList->setHorizontalHeaderItem( attrCommentCol, new QTableWidgetItem( tr( "Comment" ) ) );
@@ -319,7 +320,8 @@ void QgsFieldsProperties::setRow( int row, int idx, const QgsField &field )
mAttributesList->setItem( row, attrIdCol, new QTableWidgetItem( idx ) );
mIndexedWidgets.insert( idx, mAttributesList->item( row, 0 ) );
mAttributesList->setItem( row, attrNameCol, new QTableWidgetItem( field.name() ) );
mAttributesList->setItem( row, attrTypeCol, new QTableWidgetItem( field.typeName() ) );
mAttributesList->setItem( row, attrTypeCol, new QTableWidgetItem( QVariant::typeToName( field.type() ) ) );
mAttributesList->setItem( row, attrTypeNameCol, new QTableWidgetItem( field.typeName() ) );
mAttributesList->setItem( row, attrLengthCol, new QTableWidgetItem( QString::number( field.length() ) ) );
mAttributesList->setItem( row, attrPrecCol, new QTableWidgetItem( QString::number( field.precision() ) ) );
mAttributesList->setItem( row, attrCommentCol, new QTableWidgetItem( field.comment() ) );
@@ -138,6 +138,7 @@ class QgsFieldsProperties : public QWidget, private Ui_QgsFieldsPropertiesBase
attrIdCol = 0,
attrNameCol,
attrTypeCol,
attrTypeNameCol,
attrLengthCol,
attrPrecCol,
attrCommentCol,
@@ -111,6 +111,7 @@ bool QgsSpatialIndex::insertFeature( QgsFeature& f )
try
{
mRTree->insertData( 0, 0, r, FID_TO_NUMBER( id ) );
return true;
}
catch ( Tools::Exception &e )
{
@@ -127,7 +128,7 @@ bool QgsSpatialIndex::insertFeature( QgsFeature& f )
QgsDebugMsg( "unknown spatial index exception caught" );
}

return true;
return false;
}

bool QgsSpatialIndex::deleteFeature( QgsFeature& f )
@@ -78,6 +78,12 @@ bool QgsAttributeTableFilterModel::lessThan( const QModelIndex &left, const QMod
case QVariant::Double:
return leftData.toDouble() < rightData.toDouble();

case QVariant::Date:
return leftData.toDate() < rightData.toDate();

case QVariant::DateTime:
return leftData.toDateTime() < rightData.toDateTime();

default:
return leftData.toString().localeAwareCompare( rightData.toString() ) < 0;
}
@@ -415,7 +415,6 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format

QgsFeatureIterator fit = layer->getFeatures(
QgsFeatureRequest()
.setFilterRect( searchRect )
.setFlags( QgsFeatureRequest::ExactIntersect | ( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) )
.setSubsetOfAttributes( attrIndexes ) );

@@ -778,8 +777,15 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QgsFeatureRequest req;
if ( layer->wkbType() != QGis::WKBNoGeometry )
{
req.setFilterRect( searchRect )
.setFlags( QgsFeatureRequest::ExactIntersect | ( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) );
if ( bboxOk )
{
req.setFilterRect( searchRect );
req.setFlags( QgsFeatureRequest::ExactIntersect | ( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) );
}
else
{
req.setFlags( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry );
}
}
else
{
@@ -898,8 +904,14 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QgsFeatureRequest req;
if ( layer->wkbType() != QGis::WKBNoGeometry )
{
req.setFilterRect( searchRect )
.setFlags( QgsFeatureRequest::ExactIntersect | ( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) );
if ( bboxOk )
{
req.setFilterRect( searchRect ).setFlags( QgsFeatureRequest::ExactIntersect | ( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) );
}
else
{
req.setFlags( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry );
}
}
else
{
@@ -935,8 +947,14 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QgsFeatureRequest req;
if ( layer->wkbType() != QGis::WKBNoGeometry )
{
req.setFilterRect( searchRect )
.setFlags( QgsFeatureRequest::ExactIntersect | ( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) );
if ( bboxOk )
{
req.setFilterRect( searchRect ).setFlags( QgsFeatureRequest::ExactIntersect | ( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) );
}
else
{
req.setFlags( mWithGeom ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry );
}
}
else
{
@@ -74,16 +74,7 @@ bool QgsWFSFeatureIterator::nextFeature( QgsFeature& f )
}
QgsFeature* fet = it.value();

QgsAttributeList attributes;
if ( mRequest.flags() & QgsFeatureRequest::SubsetOfAttributes )
{
attributes = mRequest.subsetOfAttributes();
}
else
{
attributes = mProvider->attributeIndexes();
}
mProvider->copyFeature( fet, f, !( mRequest.flags() & QgsFeatureRequest::NoGeometry ), attributes );
mProvider->copyFeature( fet, f, !( mRequest.flags() & QgsFeatureRequest::NoGeometry ) );
++mFeatureIterator;
return true;
}
@@ -153,7 +153,7 @@ void QgsWFSProvider::deleteData()
mFeatures.clear();
}

void QgsWFSProvider::copyFeature( QgsFeature* f, QgsFeature& feature, bool fetchGeometry, QgsAttributeList fetchAttributes )
void QgsWFSProvider::copyFeature( QgsFeature* f, QgsFeature& feature, bool fetchGeometry )
{
Q_UNUSED( fetchGeometry );

@@ -178,14 +178,14 @@ void QgsWFSProvider::copyFeature( QgsFeature* f, QgsFeature& feature, bool fetch
}

//and the attributes
const QgsAttributes& attributes = f->attributes();
feature.setAttributes( attributes );

int i = 0;
for ( QgsAttributeList::const_iterator it = fetchAttributes.begin(); it != fetchAttributes.end(); ++it )
feature.initAttributes( mFields.size() );
for ( int i = 0; i < mFields.size(); i++ )
{
feature.setAttribute( i, attributes[*it] );
++i;
const QVariant &v = f->attributes().value( i );
if ( v.type() != mFields[i].type() )
feature.setAttribute( i, convertValue( mFields[i].type(), v.toString() ) );
else
feature.setAttribute( i, v );
}

//id and valid
@@ -1206,32 +1206,32 @@ int QgsWFSProvider::getFeaturesFromGML2( const QDomElement& wfsCollectionElement

for ( int i = 0; i < featureTypeNodeList.size(); ++i )
{
f = new QgsFeature( mFeatureCount );
f = new QgsFeature( fields(), mFeatureCount );
currentFeatureMemberElem = featureTypeNodeList.at( i ).toElement();
//the first child element is always <namespace:layer>
layerNameElem = currentFeatureMemberElem.firstChild().toElement();
//the children are the attributes
currentAttributeChild = layerNameElem.firstChild();
int attr = 0;
bool numeric = false;

while ( !currentAttributeChild.isNull() )
{
currentAttributeElement = currentAttributeChild.toElement();

if ( currentAttributeElement.localName() != "boundedBy" )
{
currentAttributeElement.text().toDouble( &numeric );

if (( currentAttributeElement.localName() ) != geometryAttribute ) //a normal attribute
{
if ( numeric )
int attr = fieldNameIndex( currentAttributeElement.localName() );
if ( attr < 0 )
{
f->setAttribute( attr++, QVariant( currentAttributeElement.text().toDouble() ) );
}
else
{
f->setAttribute( attr++, QVariant( currentAttributeElement.text() ) );
QgsDebugMsg( QString( "attribute %1 not found in fields" ).arg( currentAttributeElement.localName() ) );
continue;
}

const QgsField &fld = mFields[attr];
QgsDebugMsg( QString( "set attribute %1: type=%2 value=%3" ).arg( attr ).arg( QVariant::typeToName( fld.type() ) ).arg( currentAttributeElement.text() ) );
f->setAttribute( attr, convertValue( fld.type(), currentAttributeElement.text() ) );
}
else //a geometry attribute
{
@@ -190,7 +190,7 @@ class QgsWFSProvider: public QgsVectorDataProvider
int guessAttributesFromFile( const QString& uri, QString& geometryAttribute, std::list<QString>& thematicAttributes, QGis::WkbType& geomType ) const;

/**Copies feature attributes / geometry from f to feature*/
void copyFeature( QgsFeature* f, QgsFeature& feature, bool fetchGeometry, QgsAttributeList fetchAttributes );
void copyFeature( QgsFeature* f, QgsFeature& feature, bool fetchGeometry );

//GML2 specific methods
int getExtentFromGML2( QgsRectangle* extent, const QDomElement& wfsCollectionElement ) const;

0 comments on commit 133398b

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