@@ -153,11 +153,14 @@ void QgsWFSProvider::copyFeature( QgsFeature* f, QgsFeature& feature, bool fetch
153
153
154
154
// copy the geometry
155
155
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
+ }
161
164
162
165
// and the attributes
163
166
const QgsAttributeMap& attributes = f->attributeMap ();
@@ -210,7 +213,7 @@ bool QgsWFSProvider::nextFeature( QgsFeature& feature )
210
213
continue ;
211
214
}
212
215
213
- copyFeature ( f, feature, true , mAttributesToFetch );
216
+ copyFeature ( f, feature, mFetchGeom , mAttributesToFetch );
214
217
215
218
if ( mUseIntersect )
216
219
{
@@ -277,6 +280,12 @@ void QgsWFSProvider::select( QgsAttributeList fetchAttributes,
277
280
bool fetchGeometry,
278
281
bool useIntersect )
279
282
{
283
+
284
+ if ( geometryType () == QGis::WKBNoGeometry )
285
+ {
286
+ fetchGeometry = false ;
287
+ }
288
+
280
289
mUseIntersect = useIntersect;
281
290
mAttributesToFetch = fetchAttributes;
282
291
mFetchGeom = fetchGeometry;
@@ -789,10 +798,13 @@ int QgsWFSProvider::getFeatureGET( const QString& uri, const QString& geometryAt
789
798
QgsDebugMsg ( QString ( " feature count after request is: %1" ).arg ( mFeatures .size () ) );
790
799
QgsDebugMsg ( QString ( " mExtent after request is: %1" ).arg ( mExtent .toString () ) );
791
800
792
- for ( QMap<QgsFeatureId, QgsFeature*>::iterator it = mFeatures . begin (); it != mFeatures . end (); ++it )
801
+ if ( mWKBType != QGis::WKBNoGeometry )
793
802
{
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
+ }
796
808
}
797
809
798
810
mFeatureCount = mFeatures .size ();
@@ -820,7 +832,7 @@ int QgsWFSProvider::getFeatureFILE( const QString& uri, const QString& geometryA
820
832
821
833
QDomElement featureCollectionElement = gmlDoc.documentElement ();
822
834
// get and set Extent
823
- if ( getExtentFromGML2 ( &mExtent , featureCollectionElement ) != 0 )
835
+ if ( mWKBType != QGis::WKBNoGeometry && QGis::WKBNoGeometry && getExtentFromGML2 ( &mExtent , featureCollectionElement ) != 0 )
824
836
{
825
837
return 3 ;
826
838
}
@@ -905,7 +917,7 @@ int QgsWFSProvider::describeFeatureTypeFile( const QString& uri, QString& geomet
905
917
std::list<QString> thematicAttributes;
906
918
907
919
// 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 )
909
921
{
910
922
return 1 ;
911
923
}
@@ -985,6 +997,8 @@ int QgsWFSProvider::readAttributesFromSchema( QDomDocument& schemaDoc, QString&
985
997
return 5 ;
986
998
}
987
999
1000
+ bool foundGeometryAttribute = false ;
1001
+
988
1002
for ( uint i = 0 ; i < attributeNodeList.length (); ++i )
989
1003
{
990
1004
QDomElement attributeElement = attributeNodeList.at ( i ).toElement ();
@@ -998,6 +1012,7 @@ int QgsWFSProvider::readAttributesFromSchema( QDomDocument& schemaDoc, QString&
998
1012
QRegExp gmlPT ( " gml:(.*)PropertyType" );
999
1013
if ( type.indexOf ( gmlPT ) == 0 || name.isEmpty () )
1000
1014
{
1015
+ foundGeometryAttribute = true ;
1001
1016
geometryAttribute = name;
1002
1017
geomType = geomTypeFromPropertyType ( geometryAttribute, gmlPT.cap ( 1 ) );
1003
1018
}
@@ -1019,10 +1034,15 @@ int QgsWFSProvider::readAttributesFromSchema( QDomDocument& schemaDoc, QString&
1019
1034
fields[fields.size ()] = QgsField ( name, attributeType, type );
1020
1035
}
1021
1036
}
1037
+ if ( !foundGeometryAttribute )
1038
+ {
1039
+ geomType = QGis::WKBNoGeometry;
1040
+ }
1041
+
1022
1042
return 0 ;
1023
1043
}
1024
1044
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
1026
1046
{
1027
1047
QFile gmlFile ( uri );
1028
1048
if ( !gmlFile.open ( QIODevice::ReadOnly ) )
@@ -1056,6 +1076,7 @@ int QgsWFSProvider::guessAttributesFromFile( const QString& uri, QString& geomet
1056
1076
QString attributeText;
1057
1077
QDomElement attributeChildElement;
1058
1078
QString attributeChildLocalName;
1079
+ bool foundGeometryAttribute = false ;
1059
1080
1060
1081
while ( !attributeNode.isNull () )// loop over attributes
1061
1082
{
@@ -1083,6 +1104,11 @@ int QgsWFSProvider::guessAttributesFromFile( const QString& uri, QString& geomet
1083
1104
attributeNode = attributeNode.nextSibling ();
1084
1105
}
1085
1106
1107
+ if ( !foundGeometryAttribute )
1108
+ {
1109
+ geomType = QGis::WKBNoGeometry;
1110
+ }
1111
+
1086
1112
return 0 ;
1087
1113
}
1088
1114
@@ -1232,7 +1258,6 @@ int QgsWFSProvider::getFeaturesFromGML2( const QDomElement& wfsCollectionElement
1232
1258
QDomElement layerNameElem;
1233
1259
QDomNode currentAttributeChild;
1234
1260
QDomElement currentAttributeElement;
1235
- int counter = 0 ;
1236
1261
QgsFeature* f = 0 ;
1237
1262
unsigned char * wkb = 0 ;
1238
1263
int wkbSize = 0 ;
@@ -1241,7 +1266,7 @@ int QgsWFSProvider::getFeaturesFromGML2( const QDomElement& wfsCollectionElement
1241
1266
1242
1267
for ( int i = 0 ; i < featureTypeNodeList.size (); ++i )
1243
1268
{
1244
- f = new QgsFeature ( counter );
1269
+ f = new QgsFeature ( mFeatureCount );
1245
1270
currentFeatureMemberElem = featureTypeNodeList.at ( i ).toElement ();
1246
1271
// the first child element is always <namespace:layer>
1247
1272
layerNameElem = currentFeatureMemberElem.firstChild ().toElement ();
@@ -1281,10 +1306,10 @@ int QgsWFSProvider::getFeaturesFromGML2( const QDomElement& wfsCollectionElement
1281
1306
{
1282
1307
// insert bbox and pointer to feature into search tree
1283
1308
mSpatialIndex ->insertFeature ( *f );
1284
- mFeatures .insert ( f->id (), f );
1285
- ++mFeatureCount ;
1286
1309
}
1287
- ++counter;
1310
+
1311
+ mFeatures .insert ( f->id (), f );
1312
+ ++mFeatureCount ;
1288
1313
}
1289
1314
return 0 ;
1290
1315
}
0 commit comments