15
15
#include " qgswfsdata.h"
16
16
#include " qgsrectangle.h"
17
17
#include " qgscoordinatereferencesystem.h"
18
+ #include " qgsgeometry.h"
18
19
#include " qgshttptransaction.h"
19
20
#include " qgslogger.h"
20
21
#include < QBuffer>
@@ -79,6 +80,11 @@ int QgsWFSData::getWFSData()
79
80
XML_SetElementHandler ( p, QgsWFSData::start, QgsWFSData::end );
80
81
XML_SetCharacterDataHandler ( p, QgsWFSData::chars );
81
82
83
+ // start with empty extent
84
+ if (mExtent )
85
+ {
86
+ mExtent ->set (0 , 0 , 0 , 0 );
87
+ }
82
88
83
89
// separate host from query string
84
90
QUrl requestUrl ( mUri );
@@ -133,6 +139,15 @@ int QgsWFSData::getWFSData()
133
139
134
140
delete progressDialog;
135
141
142
+ if (mExtent )
143
+ {
144
+ if (mExtent ->isEmpty ())
145
+ {
146
+ // reading of bbox from the server failed, so we calculate it less efficiently by evaluating the features
147
+ calculateExtentFromFeatures ();
148
+ }
149
+ }
150
+
136
151
return 0 ; // soon
137
152
}
138
153
@@ -159,7 +174,7 @@ void QgsWFSData::handleProgressEvent( int progress, int totalSteps )
159
174
void QgsWFSData::startElement ( const XML_Char* el, const XML_Char** attr )
160
175
{
161
176
QString elementName ( el );
162
- QString localName = elementName.section ( NS_SEPARATOR, 1 , 1 );
177
+ QString localName = elementName.section ( NS_SEPARATOR, 1 , 1 );
163
178
if ( elementName == GML_NAMESPACE + NS_SEPARATOR + " coordinates" )
164
179
{
165
180
mParseModeStack .push ( QgsWFSData::coordinate );
@@ -797,3 +812,37 @@ QWidget* QgsWFSData::findMainWindow() const
797
812
}
798
813
return mainWindow;
799
814
}
815
+
816
+ void QgsWFSData::calculateExtentFromFeatures () const
817
+ {
818
+ if (mFeatures .size () < 1 )
819
+ {
820
+ return ;
821
+ }
822
+
823
+ QgsRectangle bbox;
824
+
825
+ QgsFeature* currentFeature = 0 ;
826
+ QgsGeometry* currentGeometry = 0 ;
827
+ for (int i = 0 ; i < mFeatures .size (); ++i)
828
+ {
829
+ currentFeature = mFeatures [i];
830
+ if (!currentFeature)
831
+ {
832
+ continue ;
833
+ }
834
+ currentGeometry = currentFeature->geometry ();
835
+ if (currentGeometry)
836
+ {
837
+ if (bbox.isEmpty ())
838
+ {
839
+ bbox = currentGeometry->boundingBox ();
840
+ }
841
+ else
842
+ {
843
+ bbox.unionRect (currentGeometry->boundingBox ());
844
+ }
845
+ }
846
+ }
847
+ (*mExtent ) = bbox;
848
+ }
0 commit comments