Skip to content

Commit aedddc2

Browse files
palmerjmhugent
authored andcommittedOct 4, 2012
Support plain tables from WFS sources
1 parent c8a05c1 commit aedddc2

File tree

4 files changed

+50
-20
lines changed

4 files changed

+50
-20
lines changed
 

‎src/app/qgslabelinggui.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
6969
case QGis::Polygon:
7070
stackedPlacement->setCurrentWidget( pagePolygon );
7171
break;
72+
case QGis::NoGeometry:
73+
break;
7274
default:
7375
Q_ASSERT( 0 && "NOOOO!" );
7476
}

‎src/providers/wfs/qgswfsdata.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ int QgsWFSData::getWFSData()
127127
delete reply;
128128
delete progressDialog;
129129

130-
if ( mExtent )
130+
if ( mExtent && *mWkbType != QGis::WKBNoGeometry )
131131
{
132132
if ( mExtent->isEmpty() )
133133
{
@@ -317,7 +317,10 @@ void QgsWFSData::endElement( const XML_Char* el )
317317
}
318318

319319

320-
mCurrentFeature->setGeometryAndOwnership( mCurrentWKB, mCurrentWKBSize );
320+
if ( mCurrentWKBSize > 0 )
321+
{
322+
mCurrentFeature->setGeometryAndOwnership( mCurrentWKB, mCurrentWKBSize );
323+
}
321324
mFeatures.insert( mCurrentFeature->id(), mCurrentFeature );
322325
if ( !mCurrentFeatureId.isEmpty() )
323326
{

‎src/providers/wfs/qgswfsprovider.cpp

+42-17
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,14 @@ void QgsWFSProvider::copyFeature( QgsFeature* f, QgsFeature& feature, bool fetch
153153

154154
//copy the geometry
155155
QgsGeometry* geometry = f->geometry();
156-
unsigned char *geom = geometry->asWkb();
157-
int geomSize = geometry->wkbSize();
158-
unsigned char* copiedGeom = new unsigned char[geomSize];
159-
memcpy( copiedGeom, geom, geomSize );
160-
feature.setGeometryAndOwnership( copiedGeom, geomSize );
156+
if ( geometry )
157+
{
158+
unsigned char *geom = geometry->asWkb();
159+
int geomSize = geometry->wkbSize();
160+
unsigned char* copiedGeom = new unsigned char[geomSize];
161+
memcpy( copiedGeom, geom, geomSize );
162+
feature.setGeometryAndOwnership( copiedGeom, geomSize );
163+
}
161164

162165
//and the attributes
163166
const QgsAttributeMap& attributes = f->attributeMap();
@@ -210,7 +213,7 @@ bool QgsWFSProvider::nextFeature( QgsFeature& feature )
210213
continue;
211214
}
212215

213-
copyFeature( f, feature, true, mAttributesToFetch );
216+
copyFeature( f, feature, mFetchGeom, mAttributesToFetch );
214217

215218
if ( mUseIntersect )
216219
{
@@ -277,6 +280,12 @@ void QgsWFSProvider::select( QgsAttributeList fetchAttributes,
277280
bool fetchGeometry,
278281
bool useIntersect )
279282
{
283+
284+
if ( geometryType() == QGis::WKBNoGeometry )
285+
{
286+
fetchGeometry = false;
287+
}
288+
280289
mUseIntersect = useIntersect;
281290
mAttributesToFetch = fetchAttributes;
282291
mFetchGeom = fetchGeometry;
@@ -789,10 +798,13 @@ int QgsWFSProvider::getFeatureGET( const QString& uri, const QString& geometryAt
789798
QgsDebugMsg( QString( "feature count after request is: %1" ).arg( mFeatures.size() ) );
790799
QgsDebugMsg( QString( "mExtent after request is: %1" ).arg( mExtent.toString() ) );
791800

792-
for ( QMap<QgsFeatureId, QgsFeature*>::iterator it = mFeatures.begin(); it != mFeatures.end(); ++it )
801+
if (mWKBType != QGis::WKBNoGeometry)
793802
{
794-
QgsDebugMsg( "feature " + FID_TO_STRING(( *it )->id() ) );
795-
mSpatialIndex->insertFeature( *( it.value() ) );
803+
for ( QMap<QgsFeatureId, QgsFeature*>::iterator it = mFeatures.begin(); it != mFeatures.end(); ++it )
804+
{
805+
QgsDebugMsg( "feature " + FID_TO_STRING(( *it )->id() ) );
806+
mSpatialIndex->insertFeature( *( it.value() ) );
807+
}
796808
}
797809

798810
mFeatureCount = mFeatures.size();
@@ -820,7 +832,7 @@ int QgsWFSProvider::getFeatureFILE( const QString& uri, const QString& geometryA
820832

821833
QDomElement featureCollectionElement = gmlDoc.documentElement();
822834
//get and set Extent
823-
if ( getExtentFromGML2( &mExtent, featureCollectionElement ) != 0 )
835+
if ( mWKBType != QGis::WKBNoGeometry && QGis::WKBNoGeometry && getExtentFromGML2( &mExtent, featureCollectionElement ) != 0 )
824836
{
825837
return 3;
826838
}
@@ -905,7 +917,7 @@ int QgsWFSProvider::describeFeatureTypeFile( const QString& uri, QString& geomet
905917
std::list<QString> thematicAttributes;
906918

907919
//if this fails (e.g. no schema file), try to guess the geometry attribute and the names of the thematic attributes from the .gml file
908-
if ( guessAttributesFromFile( uri, geometryAttribute, thematicAttributes ) != 0 )
920+
if ( guessAttributesFromFile( uri, geometryAttribute, thematicAttributes, geomType ) != 0 )
909921
{
910922
return 1;
911923
}
@@ -985,6 +997,8 @@ int QgsWFSProvider::readAttributesFromSchema( QDomDocument& schemaDoc, QString&
985997
return 5;
986998
}
987999

1000+
bool foundGeometryAttribute = false;
1001+
9881002
for ( uint i = 0; i < attributeNodeList.length(); ++i )
9891003
{
9901004
QDomElement attributeElement = attributeNodeList.at( i ).toElement();
@@ -998,6 +1012,7 @@ int QgsWFSProvider::readAttributesFromSchema( QDomDocument& schemaDoc, QString&
9981012
QRegExp gmlPT( "gml:(.*)PropertyType" );
9991013
if ( type.indexOf( gmlPT ) == 0 || name.isEmpty() )
10001014
{
1015+
foundGeometryAttribute = true;
10011016
geometryAttribute = name;
10021017
geomType = geomTypeFromPropertyType( geometryAttribute, gmlPT.cap( 1 ) );
10031018
}
@@ -1019,10 +1034,15 @@ int QgsWFSProvider::readAttributesFromSchema( QDomDocument& schemaDoc, QString&
10191034
fields[fields.size()] = QgsField( name, attributeType, type );
10201035
}
10211036
}
1037+
if ( !foundGeometryAttribute )
1038+
{
1039+
geomType = QGis::WKBNoGeometry;
1040+
}
1041+
10221042
return 0;
10231043
}
10241044

1025-
int QgsWFSProvider::guessAttributesFromFile( const QString& uri, QString& geometryAttribute, std::list<QString>& thematicAttributes ) const
1045+
int QgsWFSProvider::guessAttributesFromFile( const QString& uri, QString& geometryAttribute, std::list<QString>& thematicAttributes, QGis::WkbType& geomType ) const
10261046
{
10271047
QFile gmlFile( uri );
10281048
if ( !gmlFile.open( QIODevice::ReadOnly ) )
@@ -1056,6 +1076,7 @@ int QgsWFSProvider::guessAttributesFromFile( const QString& uri, QString& geomet
10561076
QString attributeText;
10571077
QDomElement attributeChildElement;
10581078
QString attributeChildLocalName;
1079+
bool foundGeometryAttribute = false;
10591080

10601081
while ( !attributeNode.isNull() )//loop over attributes
10611082
{
@@ -1083,6 +1104,11 @@ int QgsWFSProvider::guessAttributesFromFile( const QString& uri, QString& geomet
10831104
attributeNode = attributeNode.nextSibling();
10841105
}
10851106

1107+
if ( !foundGeometryAttribute )
1108+
{
1109+
geomType = QGis::WKBNoGeometry;
1110+
}
1111+
10861112
return 0;
10871113
}
10881114

@@ -1232,7 +1258,6 @@ int QgsWFSProvider::getFeaturesFromGML2( const QDomElement& wfsCollectionElement
12321258
QDomElement layerNameElem;
12331259
QDomNode currentAttributeChild;
12341260
QDomElement currentAttributeElement;
1235-
int counter = 0;
12361261
QgsFeature* f = 0;
12371262
unsigned char* wkb = 0;
12381263
int wkbSize = 0;
@@ -1241,7 +1266,7 @@ int QgsWFSProvider::getFeaturesFromGML2( const QDomElement& wfsCollectionElement
12411266

12421267
for ( int i = 0; i < featureTypeNodeList.size(); ++i )
12431268
{
1244-
f = new QgsFeature( counter );
1269+
f = new QgsFeature( mFeatureCount );
12451270
currentFeatureMemberElem = featureTypeNodeList.at( i ).toElement();
12461271
//the first child element is always <namespace:layer>
12471272
layerNameElem = currentFeatureMemberElem.firstChild().toElement();
@@ -1281,10 +1306,10 @@ int QgsWFSProvider::getFeaturesFromGML2( const QDomElement& wfsCollectionElement
12811306
{
12821307
//insert bbox and pointer to feature into search tree
12831308
mSpatialIndex->insertFeature( *f );
1284-
mFeatures.insert( f->id(), f );
1285-
++mFeatureCount;
12861309
}
1287-
++counter;
1310+
1311+
mFeatures.insert( f->id(), f );
1312+
++mFeatureCount;
12881313
}
12891314
return 0;
12901315
}

‎src/providers/wfs/qgswfsprovider.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class QgsWFSProvider: public QgsVectorDataProvider
217217
/**Reads the name of the geometry attribute, the thematic attributes and their types from a dom document. Returns 0 in case of success*/
218218
int readAttributesFromSchema( QDomDocument& schemaDoc, QString& geometryAttribute, QgsFieldMap& fields, QGis::WkbType& geomType );
219219
/**This method tries to guess the geometry attribute and the other attribute names from the .gml file if no schema is present. Returns 0 in case of success*/
220-
int guessAttributesFromFile( const QString& uri, QString& geometryAttribute, std::list<QString>& thematicAttributes ) const;
220+
int guessAttributesFromFile( const QString& uri, QString& geometryAttribute, std::list<QString>& thematicAttributes, QGis::WkbType& geomType ) const;
221221

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

0 commit comments

Comments
 (0)
Please sign in to comment.