28 #include <QNetworkRequest> 29 #include <QNetworkReply> 30 #include <QProgressDialog> 45 const QString& geometryAttribute,
48 , mParser( typeName, geometryAttribute, fields )
49 , mTypeName( typeName )
53 if ( index != -1 && index < mTypeName.
length() )
55 mTypeName = mTypeName.
mid( index + 1 );
74 tr(
"GML Getfeature network request update failed for authcfg %1" ).arg( authcfg ),
83 request.
setRawHeader(
"Authorization",
"Basic " +
QString(
"%1:%2" ).arg( userName, password ).toAscii().toBase64() );
93 tr(
"GML Getfeature network reply update failed for authcfg %1" ).arg( authcfg ),
101 connect( reply, SIGNAL( finished() ),
this, SLOT( setFinished() ) );
102 connect( reply, SIGNAL( downloadProgress( qint64, qint64 ) ),
this, SLOT( handleProgressEvent( qint64, qint64 ) ) );
107 QWidgetList topLevelWidgets = qApp->topLevelWidgets();
108 for ( QWidgetList::const_iterator it = topLevelWidgets.constBegin(); it != topLevelWidgets.constEnd(); ++it )
110 if (( *it )->objectName() ==
"QgisApp" )
118 progressDialog =
new QProgressDialog(
tr(
"Loading GML data\n%1" ).arg( mTypeName ),
tr(
"Abort" ), 0, 0, mainWindow );
122 connect( progressDialog, SIGNAL( canceled() ),
this, SLOT( setFinished() ) );
123 progressDialog->
show();
137 if ( !mParser.
processData( readData, atEnd, errorMsg ) )
144 fillMapsFromParser();
146 QNetworkReply::NetworkError replyError = reply->
error();
150 delete progressDialog;
155 tr(
"GML Getfeature network request failed with error: %1" ).arg( replyErrorString ),
169 calculateExtentFromFeatures();
184 if ( !mParser.
processData( data,
true , errorMsg ) )
187 fillMapsFromParser();
197 void QgsGml::fillMapsFromParser()
203 const QString& gmlId = featPair.second;
204 mFeatures.
insert( feat->
id(), feat );
212 void QgsGml::setFinished()
217 void QgsGml::handleProgressEvent( qint64 progress, qint64 totalSteps )
219 if ( totalSteps < 0 )
229 void QgsGml::calculateExtentFromFeatures()
231 if ( mFeatures.
size() < 1 )
238 bool bboxInitialised =
false;
240 for (
int i = 0; i < mFeatures.
size(); ++i )
242 currentFeature = mFeatures[i];
243 if ( !currentFeature )
248 if ( currentGeometry )
250 if ( !bboxInitialised )
253 bboxInitialised =
true;
278 const QString& geometryAttribute,
281 bool invertAxisOrientation )
282 : mTypeName( typeName )
283 , mTypeNameBA( mTypeName.toUtf8() )
284 , mTypeNamePtr( mTypeNameBA.constData() )
285 , mTypeNameUTF8Len( strlen( mTypeNamePtr ) )
286 , mWkbType(
QGis::WKBUnknown )
287 , mGeometryAttribute( geometryAttribute )
288 , mGeometryAttributeBA( geometryAttribute.toUtf8() )
289 , mGeometryAttributePtr( mGeometryAttributeBA.constData() )
290 , mGeometryAttributeUTF8Len( strlen( mGeometryAttributePtr ) )
292 , mIsException( false )
293 , mTruncatedResponse( false )
295 , mFeatureTupleDepth( 0 )
296 , mCurrentFeature( nullptr )
298 , mCurrentWKB( nullptr, 0 )
299 , mBoundedByNullFound( false )
301 , mCoorMode( coordinate )
303 , mGMLNameSpaceURIPtr( nullptr )
304 , mAxisOrientationLogic( axisOrientationLogic )
305 , mInvertAxisOrientationRequest( invertAxisOrientation )
306 , mInvertAxisOrientation( invertAxisOrientation )
307 , mNumberReturned( -1 )
308 , mNumberMatched( -1 )
309 , mFoundUnhandledGeometryElement( false )
311 mThematicAttributes.
clear();
312 for (
int i = 0; i < fields.
size(); i++ )
314 mThematicAttributes.
insert( fields[i].name(), qMakePair( i, fields[i] ) );
320 if ( index != -1 && index < mTypeName.
length() )
322 mTypeName = mTypeName.
mid( index + 1 );
323 mTypeNameBA = mTypeName.
toUtf8();
325 mTypeNameUTF8Len = strlen( mTypeNamePtr );
329 XML_SetUserData( mParser,
this );
330 XML_SetElementHandler( mParser, QgsGmlStreamingParser::start, QgsGmlStreamingParser::end );
331 XML_SetCharacterDataHandler( mParser, QgsGmlStreamingParser::chars );
336 int index =
string.indexOf(
':' );
337 if ( index != -1 && index <
string.length() )
339 return string.mid( index + 1 );
348 bool invertAxisOrientation )
349 : mLayerProperties( layerProperties )
350 , mTypeNamePtr( nullptr )
351 , mTypeNameUTF8Len( 0 )
352 , mWkbType(
QGis::WKBUnknown )
353 , mGeometryAttributePtr( nullptr )
354 , mGeometryAttributeUTF8Len( 0 )
356 , mIsException( false )
357 , mTruncatedResponse( false )
359 , mFeatureTupleDepth( 0 )
360 , mCurrentFeature( nullptr )
362 , mCurrentWKB( nullptr, 0 )
363 , mBoundedByNullFound( false )
365 , mCoorMode( coordinate )
367 , mGMLNameSpaceURIPtr( nullptr )
368 , mAxisOrientationLogic( axisOrientationLogic )
369 , mInvertAxisOrientationRequest( invertAxisOrientation )
370 , mInvertAxisOrientation( invertAxisOrientation )
371 , mNumberReturned( -1 )
372 , mNumberMatched( -1 )
373 , mFoundUnhandledGeometryElement( false )
375 mThematicAttributes.
clear();
376 for (
int i = 0; i < fields.
size(); i++ )
379 if ( att_it != mapFieldNameToSrcLayerNameFieldName.
constEnd() )
381 if ( mLayerProperties.size() == 1 )
382 mThematicAttributes.
insert( att_it.
value().second, qMakePair( i, fields[i] ) );
384 mThematicAttributes.
insert(
stripNS( att_it.
value().first ) +
"|" + att_it.
value().second, qMakePair( i, fields[i] ) );
387 bool alreadyFoundGeometry =
false;
388 for (
int i = 0; i < mLayerProperties.size(); i++ )
391 if ( !mLayerProperties[i].mGeometryAttribute.
isEmpty() )
393 if ( alreadyFoundGeometry )
396 arg( mLayerProperties[i].mGeometryAttribute ).arg( mLayerProperties[i].mName ) );
397 mLayerProperties[i].mGeometryAttribute.clear();
399 alreadyFoundGeometry =
true;
401 mMapTypeNameToProperties.insert(
stripNS( mLayerProperties[i].mName ), mLayerProperties[i] );
404 if ( mLayerProperties.size() == 1 )
406 mTypeName = mLayerProperties[0].mName;
407 mGeometryAttribute = mLayerProperties[0].mGeometryAttribute;
408 mGeometryAttributeBA = mGeometryAttribute.
toUtf8();
409 mGeometryAttributePtr = mGeometryAttributeBA.
constData();
410 mGeometryAttributeUTF8Len = strlen( mGeometryAttributePtr );
412 if ( index != -1 && index < mTypeName.
length() )
414 mTypeName = mTypeName.
mid( index + 1 );
416 mTypeNameBA = mTypeName.
toUtf8();
418 mTypeNameUTF8Len = strlen( mTypeNamePtr );
424 XML_SetUserData( mParser,
this );
425 XML_SetElementHandler( mParser, QgsGmlStreamingParser::start, QgsGmlStreamingParser::end );
426 XML_SetCharacterDataHandler( mParser, QgsGmlStreamingParser::chars );
432 XML_ParserFree( mParser );
437 delete featPair.first;
440 delete mCurrentFeature;
456 if ( XML_Parse( mParser, data.
data(), data.
size(), atEnd ) == 0 )
458 XML_Error errorCode = XML_GetErrorCode( mParser );
459 errorMsg =
QObject::tr(
"Error: %1 on line %2, column %3" )
460 .
arg( XML_ErrorString( errorCode ) )
461 .
arg( XML_GetCurrentLineNumber( mParser ) )
462 .
arg( XML_GetCurrentColumnNumber( mParser ) );
473 mFeatureList.clear();
477 #define LOCALNAME_EQUALS(string_constant) \ 478 ( localNameLen == ( int )strlen( string_constant ) && memcmp(pszLocalName, string_constant, localNameLen) == 0 ) 480 void QgsGmlStreamingParser::startElement(
const XML_Char* el,
const XML_Char** attr )
482 const int elLen = ( int )strlen( el );
484 const char* pszLocalName = ( pszSep ) ? pszSep + 1 : el;
485 const int nsLen = ( pszSep ) ? (
int )( pszSep - el ) : 0;
486 const int localNameLen = ( pszSep ) ? (
int )( elLen - nsLen ) - 1 : elLen;
487 ParseMode theParseMode( mParseModeStack.isEmpty() ? none : mParseModeStack.
top() );
491 if ( !mGMLNameSpaceURIPtr && pszSep )
505 const bool isGMLNS = ( nsLen == mGMLNameSpaceURI.
size() && mGMLNameSpaceURIPtr && memcmp( el, mGMLNameSpaceURIPtr, nsLen ) == 0 );
508 if ( theParseMode == geometry || theParseMode == coordinate || theParseMode == posList ||
509 theParseMode == multiPoint || theParseMode == multiLine || theParseMode == multiPolygon )
511 mGeometryString.append(
"<", 1 );
512 mGeometryString.append( pszLocalName, localNameLen );
513 mGeometryString.append(
" ", 1 );
514 for (
const XML_Char** attrIter = attr; attrIter && *attrIter; attrIter += 2 )
516 mGeometryString.append( attrIter[0] );
517 mGeometryString.append(
"=\"", 2 );
518 mGeometryString.append( attrIter[1] );
519 mGeometryString.append(
"\" ", 2 );
522 mGeometryString.append(
">", 1 );
527 mParseModeStack.
push( coordinate );
528 mCoorMode = QgsGmlStreamingParser::coordinate;
530 mCoordinateSeparator = readAttribute(
"cs", attr );
531 if ( mCoordinateSeparator.
isEmpty() )
533 mCoordinateSeparator =
',';
535 mTupleSeparator = readAttribute(
"ts", attr );
536 if ( mTupleSeparator.
isEmpty() )
538 mTupleSeparator =
' ';
544 mParseModeStack.
push( QgsGmlStreamingParser::posList );
545 mCoorMode = QgsGmlStreamingParser::posList;
547 if ( elDimension == 0 )
549 QString srsDimension = readAttribute(
"srsDimension", attr );
551 int dimension = srsDimension.
toInt( &ok );
554 elDimension = dimension;
558 else if (( theParseMode == feature || theParseMode == featureTuple ) &&
560 localNameLen == static_cast<int>( mGeometryAttributeUTF8Len ) &&
561 memcmp( pszLocalName, mGeometryAttributePtr, localNameLen ) == 0 )
563 mParseModeStack.
push( QgsGmlStreamingParser::geometry );
564 mFoundUnhandledGeometryElement =
false;
565 mGeometryString.clear();
570 mParseModeStack.
push( QgsGmlStreamingParser::boundingBox );
572 mBoundedByNullFound =
false;
574 else if ( theParseMode == boundingBox &&
577 mParseModeStack.
push( QgsGmlStreamingParser::null );
578 mBoundedByNullFound =
true;
580 else if ( theParseMode == boundingBox &&
584 mParseModeStack.
push( QgsGmlStreamingParser::envelope );
586 else if ( theParseMode == envelope &&
589 mParseModeStack.
push( QgsGmlStreamingParser::lowerCorner );
592 else if ( theParseMode == envelope &&
595 mParseModeStack.
push( QgsGmlStreamingParser::upperCorner );
598 else if ( theParseMode == none && !mTypeNamePtr &&
601 Q_ASSERT( !mCurrentFeature );
602 mCurrentFeature =
new QgsFeature( mFeatureCount );
606 mParseModeStack.
push( QgsGmlStreamingParser::tuple );
607 mCurrentFeatureId.
clear();
609 else if ( theParseMode == tuple )
613 if ( iter != mMapTypeNameToProperties.end() )
615 mFeatureTupleDepth = mParseDepth;
616 mCurrentTypename = currentTypename;
617 mGeometryAttribute.
clear();
618 if ( mCurrentWKB.
size() == 0 )
620 mGeometryAttribute = iter.
value().mGeometryAttribute;
622 mGeometryAttributeBA = mGeometryAttribute.
toUtf8();
623 mGeometryAttributePtr = mGeometryAttributeBA.
constData();
624 mGeometryAttributeUTF8Len = strlen( mGeometryAttributePtr );
625 mParseModeStack.
push( QgsGmlStreamingParser::featureTuple );
627 if ( mGMLNameSpaceURI.
isEmpty() )
646 id = readAttribute( mGMLNameSpaceURI +
NS_SEPARATOR +
"id", attr );
647 if ( !mCurrentFeatureId.
isEmpty() )
648 mCurrentFeatureId +=
'|';
649 mCurrentFeatureId += id;
652 else if ( theParseMode == none &&
653 localNameLen == static_cast<int>( mTypeNameUTF8Len ) &&
654 memcmp( pszLocalName, mTypeNamePtr, mTypeNameUTF8Len ) == 0 )
656 Q_ASSERT( !mCurrentFeature );
657 mCurrentFeature =
new QgsFeature( mFeatureCount );
661 mParseModeStack.
push( QgsGmlStreamingParser::feature );
662 mCurrentFeatureId = readAttribute(
"fid", attr );
663 if ( mCurrentFeatureId.
isEmpty() )
668 if ( mGMLNameSpaceURI.
isEmpty() )
671 if ( !mCurrentFeatureId.
isEmpty() )
679 if ( !mCurrentFeatureId.
isEmpty() )
687 mCurrentFeatureId = readAttribute( mGMLNameSpaceURI +
NS_SEPARATOR +
"id", attr );
691 else if ( theParseMode == boundingBox && isGMLNS &&
LOCALNAME_EQUALS(
"Box" ) )
704 localNameLen == (
int )strlen(
"Polygon" ) && memcmp( pszLocalName,
"Polygon", localNameLen ) == 0 )
712 mParseModeStack.
push( QgsGmlStreamingParser::multiPoint );
719 mParseModeStack.
push( QgsGmlStreamingParser::multiLine );
726 mParseModeStack.
push( QgsGmlStreamingParser::multiPolygon );
728 else if ( theParseMode == featureTuple )
731 if ( mThematicAttributes.
contains( mCurrentTypename +
'|' + localName ) )
733 mParseModeStack.
push( QgsGmlStreamingParser::attributeTuple );
734 mAttributeName = mCurrentTypename +
'|' + localName;
738 else if ( theParseMode == feature )
741 if ( mThematicAttributes.
contains( localName ) )
743 mParseModeStack.
push( QgsGmlStreamingParser::attribute );
744 mAttributeName = localName;
751 if ( localName.
compare(
"attribute", Qt::CaseInsensitive ) == 0 )
753 QString name = readAttribute(
"name", attr );
754 if ( mThematicAttributes.
contains( name ) )
756 QString value = readAttribute(
"value", attr );
757 setAttribute( name, value );
765 if ( numberReturned.
isEmpty() )
766 numberReturned = readAttribute(
"numberOfFeatures", attr );
768 mNumberReturned = numberReturned.
toInt( &conversionOk );
770 mNumberReturned = -1;
773 mNumberMatched = numberMatched.
toInt( &conversionOk );
780 mParseModeStack.
push( QgsGmlStreamingParser::ExceptionReport );
785 mParseModeStack.
push( QgsGmlStreamingParser::ExceptionText );
790 mTruncatedResponse =
true;
792 else if ( !mGeometryString.empty() &&
808 mFoundUnhandledGeometryElement =
true;
811 if ( !mGeometryString.empty() )
814 if ( elDimension == 0 && isGeom )
818 QString srsDimension = readAttribute(
"srsDimension", attr );
820 int dimension = srsDimension.
toInt( &ok );
823 elDimension = dimension;
827 if ( elDimension != 0 )
829 mDimension = elDimension;
831 mDimensionStack.
push( mDimension );
833 if ( mEpsg == 0 && isGeom )
835 if ( readEpsgFromAttribute( mEpsg, attr ) != 0 )
848 void QgsGmlStreamingParser::endElement(
const XML_Char* el )
852 const int elLen = ( int )strlen( el );
854 const char* pszLocalName = ( pszSep ) ? pszSep + 1 : el;
855 const int nsLen = ( pszSep ) ? (
int )( pszSep - el ) : 0;
856 const int localNameLen = ( pszSep ) ? (
int )( elLen - nsLen ) - 1 : elLen;
857 ParseMode theParseMode( mParseModeStack.isEmpty() ? none : mParseModeStack.
top() );
859 mDimension = mDimensionStack.isEmpty() ? 0 : mDimensionStack.
pop() ;
861 const bool isGMLNS = ( nsLen == mGMLNameSpaceURI.
size() && mGMLNameSpaceURIPtr && memcmp( el, mGMLNameSpaceURIPtr, nsLen ) == 0 );
863 if ( theParseMode == coordinate && isGMLNS &&
LOCALNAME_EQUALS(
"coordinates" ) )
865 mParseModeStack.
pop();
867 else if ( theParseMode == posList && isGMLNS &&
870 mParseModeStack.
pop();
872 else if ( theParseMode == attributeTuple &&
873 mCurrentTypename +
'|' +
QString::fromUtf8( pszLocalName, localNameLen ) == mAttributeName )
875 mParseModeStack.
pop();
877 setAttribute( mAttributeName, mStringCash );
879 else if ( theParseMode == attribute &&
QString::fromUtf8( pszLocalName, localNameLen ) == mAttributeName )
881 mParseModeStack.
pop();
883 setAttribute( mAttributeName, mStringCash );
885 else if ( theParseMode == geometry &&
886 localNameLen == static_cast<int>( mGeometryAttributeUTF8Len ) &&
887 memcmp( pszLocalName, mGeometryAttributePtr, localNameLen ) == 0 )
889 mParseModeStack.
pop();
890 if ( mFoundUnhandledGeometryElement )
892 OGRGeometryH hGeom = OGR_G_CreateFromGML( mGeometryString.c_str() );
895 const int wkbSize = OGR_G_WkbSize( hGeom );
896 unsigned char* pabyBuffer =
new unsigned char[ wkbSize ];
897 #if GDAL_VERSION_MAJOR >= 2 898 OGR_G_ExportToIsoWkb( hGeom, wkbNDR, pabyBuffer );
900 OGR_G_ExportToWkb( hGeom, wkbNDR, pabyBuffer );
903 g->
fromWkb( pabyBuffer, wkbSize );
904 if ( mInvertAxisOrientation )
908 Q_ASSERT( mCurrentFeature );
910 OGR_G_DestroyGeometry( hGeom );
913 mGeometryString.clear();
915 else if ( theParseMode == boundingBox && isGMLNS &&
LOCALNAME_EQUALS(
"boundedBy" ) )
918 if ( mCurrentExtent.
isNull() &&
919 !mBoundedByNullFound &&
920 !createBBoxFromCoordinateString( mCurrentExtent, mStringCash ) )
924 if ( !mCurrentExtent.
isNull() && mLayerExtent.
isNull() &&
925 mCurrentFeature ==
nullptr && mFeatureCount == 0 )
927 mLayerExtent = mCurrentExtent;
931 mParseModeStack.
pop();
935 mParseModeStack.
pop();
937 else if ( theParseMode == envelope && isGMLNS &&
LOCALNAME_EQUALS(
"Envelope" ) )
939 mParseModeStack.
pop();
941 else if ( theParseMode == lowerCorner && isGMLNS &&
LOCALNAME_EQUALS(
"lowerCorner" ) )
944 pointsFromPosListString( points, mStringCash, 2 );
945 if ( points.
size() == 1 )
950 mParseModeStack.
pop();
952 else if ( theParseMode == upperCorner && isGMLNS &&
LOCALNAME_EQUALS(
"upperCorner" ) )
955 pointsFromPosListString( points, mStringCash, 2 );
956 if ( points.
size() == 1 )
961 mParseModeStack.
pop();
963 else if ( theParseMode == featureTuple && mParseDepth == mFeatureTupleDepth )
965 mParseModeStack.
pop();
966 mFeatureTupleDepth = 0;
968 else if (( theParseMode == tuple && !mTypeNamePtr &&
970 ( theParseMode == feature &&
971 localNameLen == static_cast<int>( mTypeNameUTF8Len ) &&
972 memcmp( pszLocalName, mTypeNamePtr, mTypeNameUTF8Len ) == 0 ) )
974 Q_ASSERT( mCurrentFeature );
977 if ( mCurrentWKB.
size() > 0 )
984 else if ( !mCurrentExtent.
isEmpty() )
993 mCurrentFeature =
nullptr;
995 mParseModeStack.
pop();
1000 if ( pointsFromString( pointList, mStringCash ) != 0 )
1008 if ( theParseMode == QgsGmlStreamingParser::geometry )
1011 if ( getPointWKB( mCurrentWKB, *( pointList.
constBegin() ) ) != 0 )
1024 if ( getPointWKB( wkbPtr, *( pointList.
constBegin() ) ) != 0 )
1028 if ( !mCurrentWKBFragments.
isEmpty() )
1030 mCurrentWKBFragments.
last().push_back( wkbPtr );
1044 if ( pointsFromString( pointList, mStringCash ) != 0 )
1048 if ( theParseMode == QgsGmlStreamingParser::geometry )
1050 if ( getLineWKB( mCurrentWKB, pointList ) != 0 )
1063 if ( getLineWKB( wkbPtr, pointList ) != 0 )
1067 if ( !mCurrentWKBFragments.
isEmpty() )
1069 mCurrentWKBFragments.
last().push_back( wkbPtr );
1078 else if (( theParseMode == geometry || theParseMode == multiPolygon ) &&
1082 if ( pointsFromString( pointList, mStringCash ) != 0 )
1088 if ( getRingWKB( wkbPtr, pointList ) != 0 )
1093 if ( !mCurrentWKBFragments.
isEmpty() )
1095 mCurrentWKBFragments.
last().push_back( wkbPtr );
1103 else if (( theParseMode == geometry || theParseMode == multiPolygon ) && isGMLNS &&
1111 if ( theParseMode == geometry )
1113 createPolygonFromFragments();
1116 else if ( theParseMode == multiPoint && isGMLNS &&
1120 mParseModeStack.
pop();
1121 createMultiPointFromFragments();
1123 else if ( theParseMode == multiLine && isGMLNS &&
1127 mParseModeStack.
pop();
1128 createMultiLineFromFragments();
1130 else if ( theParseMode == multiPolygon && isGMLNS &&
1134 mParseModeStack.
pop();
1135 createMultiPolygonFromFragments();
1139 mParseModeStack.
pop();
1141 else if ( theParseMode == ExceptionText &&
LOCALNAME_EQUALS(
"ExceptionText" ) )
1143 mExceptionText = mStringCash;
1144 mParseModeStack.
pop();
1147 if ( !mGeometryString.empty() )
1149 mGeometryString.append(
"</", 2 );
1150 mGeometryString.append( pszLocalName, localNameLen );
1151 mGeometryString.append(
">", 1 );
1156 void QgsGmlStreamingParser::characters(
const XML_Char* chars,
int len )
1159 if ( mParseModeStack.isEmpty() )
1164 if ( !mGeometryString.empty() )
1166 mGeometryString.append( chars, len );
1169 QgsGmlStreamingParser::ParseMode theParseMode = mParseModeStack.
top();
1170 if ( theParseMode == QgsGmlStreamingParser::attribute ||
1171 theParseMode == QgsGmlStreamingParser::attributeTuple ||
1172 theParseMode == QgsGmlStreamingParser::coordinate ||
1173 theParseMode == QgsGmlStreamingParser::posList ||
1174 theParseMode == QgsGmlStreamingParser::lowerCorner ||
1175 theParseMode == QgsGmlStreamingParser::upperCorner ||
1176 theParseMode == QgsGmlStreamingParser::ExceptionText )
1182 void QgsGmlStreamingParser::setAttribute(
const QString& name,
const QString& value )
1186 if ( att_it != mThematicAttributes.
constEnd() )
1189 switch ( att_it.
value().second.type() )
1191 case QVariant::Double:
1197 case QVariant::LongLong:
1200 case QVariant::DateTime:
1207 Q_ASSERT( mCurrentFeature );
1212 int QgsGmlStreamingParser::readEpsgFromAttribute(
int& epsgNr,
const XML_Char** attr )
1217 if ( strcmp( attr[i],
"srsName" ) == 0 )
1219 QString epsgString( attr[i+1] );
1221 bool bIsUrn =
false;
1224 epsgNrString = epsgString.
section(
'#', 1, 1 );
1227 else if ( epsgString.
startsWith(
"urn:ogc:def:crs:EPSG:" ) ||
1228 epsgString.
startsWith(
"urn:x-ogc:def:crs:EPSG:" ) )
1231 epsgNrString = epsgString.
split(
':' ).
last();
1235 epsgNrString = epsgString.
section(
':', 1, 1 );
1238 int eNr = epsgNrString.
toInt( &conversionOk );
1239 if ( !conversionOk )
1244 mSrsName = epsgString;
1252 mInvertAxisOrientation = !mInvertAxisOrientationRequest;
1263 QString QgsGmlStreamingParser::readAttribute(
const QString& attributeName,
const XML_Char** attr )
const 1268 if ( attributeName.
compare( attr[i] ) == 0 )
1277 bool QgsGmlStreamingParser::createBBoxFromCoordinateString(
QgsRectangle &r,
const QString& coordString )
const 1280 if ( pointsFromCoordinateString( points, coordString ) != 0 )
1285 if ( points.
size() < 2 )
1290 r.
set( points[0], points[1] );
1295 int QgsGmlStreamingParser::pointsFromCoordinateString(
QList<QgsPoint>& points,
const QString& coordString )
const 1298 QStringList tuples = coordString.
split( mTupleSeparator, QString::SkipEmptyParts );
1301 bool conversionSuccess;
1304 for ( tupleIterator = tuples.
constBegin(); tupleIterator != tuples.
constEnd(); ++tupleIterator )
1306 tuples_coordinates = tupleIterator->split( mCoordinateSeparator, QString::SkipEmptyParts );
1307 if ( tuples_coordinates.
size() < 2 )
1311 x = tuples_coordinates.
at( 0 ).toDouble( &conversionSuccess );
1312 if ( !conversionSuccess )
1316 y = tuples_coordinates.
at( 1 ).toDouble( &conversionSuccess );
1317 if ( !conversionSuccess )
1326 int QgsGmlStreamingParser::pointsFromPosListString(
QList<QgsPoint>& points,
const QString& coordString,
int dimension )
const 1329 QStringList coordinates = coordString.
split(
' ', QString::SkipEmptyParts );
1331 if ( coordinates.
size() % dimension != 0 )
1336 int ncoor = coordinates.
size() / dimension;
1337 for (
int i = 0; i < ncoor; i++ )
1339 bool conversionSuccess;
1340 double x = coordinates.
value( i * dimension ).toDouble( &conversionSuccess );
1341 if ( !conversionSuccess )
1345 double y = coordinates.
value( i * dimension + 1 ).toDouble( &conversionSuccess );
1346 if ( !conversionSuccess )
1357 if ( mCoorMode == QgsGmlStreamingParser::coordinate )
1359 return pointsFromCoordinateString( points, coordString );
1361 else if ( mCoorMode == QgsGmlStreamingParser::posList )
1363 return pointsFromPosListString( points, coordString, mDimension ? mDimension : 2 );
1368 int QgsGmlStreamingParser::getPointWKB(
QgsWkbPtr &wkbPtr,
const QgsPoint& point )
const 1370 int wkbSize = 1 +
sizeof( int ) + 2 *
sizeof(
double );
1371 wkbPtr =
QgsWkbPtr(
new unsigned char[wkbSize], wkbSize );
1381 int wkbSize = 1 + 2 *
sizeof( int ) + lineCoordinates.
size() * 2 *
sizeof( double );
1382 wkbPtr =
QgsWkbPtr(
new unsigned char[wkbSize], wkbSize );
1389 for ( iter = lineCoordinates.
constBegin(); iter != lineCoordinates.
constEnd(); ++iter )
1391 fillPtr << iter->x() << iter->y();
1399 int wkbSize =
sizeof( int ) + ringCoordinates.
size() * 2 *
sizeof( double );
1400 wkbPtr =
QgsWkbPtr(
new unsigned char[wkbSize], wkbSize );
1404 fillPtr << ringCoordinates.
size();
1407 for ( iter = ringCoordinates.
constBegin(); iter != ringCoordinates.
constEnd(); ++iter )
1409 fillPtr << iter->x() << iter->y();
1415 int QgsGmlStreamingParser::createMultiLineFromFragments()
1417 int size = 1 + 2 *
sizeof( int ) + totalWKBFragmentSize();
1418 mCurrentWKB =
QgsWkbPtr(
new unsigned char[size], size );
1426 for ( ; wkbIt != mCurrentWKBFragments.
constBegin()->constEnd(); ++wkbIt )
1428 memcpy( wkbPtr, *wkbIt, wkbIt->size() );
1429 wkbPtr += wkbIt->size();
1433 mCurrentWKBFragments.
clear();
1438 int QgsGmlStreamingParser::createMultiPointFromFragments()
1440 int size = 1 + 2 *
sizeof( int ) + totalWKBFragmentSize();
1441 mCurrentWKB =
QgsWkbPtr(
new unsigned char[size], size );
1447 for ( ; wkbIt != mCurrentWKBFragments.
constBegin()->constEnd(); ++wkbIt )
1449 memcpy( wkbPtr, *wkbIt, wkbIt->size() );
1450 wkbPtr += wkbIt->size();
1454 mCurrentWKBFragments.
clear();
1460 int QgsGmlStreamingParser::createPolygonFromFragments()
1462 int size = 1 + 2 *
sizeof( int ) + totalWKBFragmentSize();
1463 mCurrentWKB =
QgsWkbPtr(
new unsigned char[size], size );
1469 for ( ; wkbIt != mCurrentWKBFragments.
constBegin()->constEnd(); ++wkbIt )
1471 memcpy( wkbPtr, *wkbIt, wkbIt->size() );
1472 wkbPtr += wkbIt->size();
1476 mCurrentWKBFragments.
clear();
1481 int QgsGmlStreamingParser::createMultiPolygonFromFragments()
1484 size += 1 + 2 *
sizeof( int );
1485 size += totalWKBFragmentSize();
1486 size += mCurrentWKBFragments.
size() * ( 1 + 2 *
sizeof( int ) );
1488 mCurrentWKB =
QgsWkbPtr(
new unsigned char[size], size );
1496 for ( ; outerWkbIt != mCurrentWKBFragments.
constEnd(); ++outerWkbIt )
1502 for ( ; innerWkbIt != outerWkbIt->
constEnd(); ++innerWkbIt )
1504 memcpy( wkbPtr, *innerWkbIt, innerWkbIt->size() );
1505 wkbPtr += innerWkbIt->size();
1506 delete[] *innerWkbIt;
1510 mCurrentWKBFragments.
clear();
1515 int QgsGmlStreamingParser::totalWKBFragmentSize()
const
void unionRect(const QgsRectangle &rect)
Updates rectangle to include passed argument.
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
int getEPSGCode() const
Return the EPSG code, or 0 if unknown.
A rectangle specified with double values.
QString & append(QChar ch)
QgsCoordinateReferenceSystem crsByOgcWmsCrs(const QString &ogcCrs) const
Returns the CRS from a given OGC WMS-format Coordinate Reference System string.
int size() const
Return number of items.
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
bool contains(const Key &key) const
static QgsAuthManager * instance()
Enforce singleton pattern.
AxisOrientationLogic
Axis orientation logic.
void setXMaximum(double x)
Set the maximum x value.
void push_back(const T &value)
void fromWkb(unsigned char *wkb, int length)
Set the geometry, feeding in the buffer containing OGC Well-Known Binary and the buffer's length...
QString errorString() const
int numberReturned() const
Return WFS 2.0 "numberReturned" or WFS 1.1 "numberOfFeatures" attribute, or -1 if invalid/not found...
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
const T & at(int i) const
int numberMatched() const
Return WFS 2.0 "numberMatched" attribute, or -1 if invalid/not found.
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
WkbType
Used for symbology operations.
static const char * GML32_NAMESPACE
void dataReadProgress(int progress)
const_iterator constFind(const Key &key) const
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
The QGis class provides global constants for use throughout the application.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
double toDouble(bool *ok) const
static endian_t endian()
Returns whether this machine uses big or little endian.
QString tr(const char *sourceText, const char *disambiguation, int n)
#define LOCALNAME_EQUALS(string_constant)
double y() const
Get the y value of the point.
void totalStepsUpdate(int totalSteps)
void set(const QgsPoint &p1, const QgsPoint &p2)
Set the rectangle from two QgsPoints.
void setGeometry(const QgsGeometry &geom)
Set this feature's geometry from another QgsGeometry object.
void processEvents(QFlags< QEventLoop::ProcessEventsFlag > flags)
void append(const T &value)
QString fromUtf8(const char *str, int size)
int getFeatures(const QString &uri, QGis::WkbType *wkbType, QgsRectangle *extent=nullptr, const QString &userName=QString(), const QString &password=QString(), const QString &authcfg=QString())
Does the Http GET request to the wfs server Supports only UTF-8, UTF-16, ISO-8859-1, ISO-8859-1 XML encodings.
void dataProgressAndSteps(int progress, int totalSteps)
static QString stripNS(const QString &string)
bool isEmpty() const
test if rectangle is empty.
QgsGml(const QString &typeName, const QString &geometryAttribute, const QgsFields &fields)
int toInt(bool *ok, int base) const
void setYMinimum(double y)
Set the minimum y value.
const_iterator constEnd() const
const char * constData() const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
Honour EPSG axis order only if srsName is of the form urn:ogc:def:crs:EPSG:
QVector< QgsGmlFeaturePtrGmlIdPair > getAndStealReadyFeatures()
Returns the list of features that have been completely parsed.
QPair< QgsFeature *, QString > QgsGmlFeaturePtrGmlIdPair
A class to represent a point.
Q_DECL_DEPRECATED void setFields(const QgsFields *fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
QgsFeatureId id() const
Get the feature ID for this feature.
QDateTime fromString(const QString &string, Qt::DateFormat format)
QgsGeometry * geometry()
Get the geometry object associated with this feature.
void setValid(bool validity)
Sets the validity of the feature.
QString mid(int position, int n) const
bool updateNetworkRequest(QNetworkRequest &request, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QNetworkRequest with an authentication config.
static QgsNetworkAccessManager * instance()
returns a pointer to the single instance
void setYMaximum(double y)
Set the maximum y value.
bool processData(const QByteArray &data, bool atEnd, QString &errorMsg)
Process a new chunk of data.
QgsRectangle boundingBox() const
Returns the bounding box of this feature.
Class for storing a coordinate reference system (CRS)
bool isNull() const
test if the rectangle is null (all coordinates zero or after call to setMinimal()).
static QgsGeometry * fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
QgsGmlStreamingParser(const QString &typeName, const QString &geometryAttribute, const QgsFields &fields, AxisOrientationLogic axisOrientationLogic=Honour_EPSG_if_urn, bool invertAxisOrientation=false)
Constructor.
static const char * GML_NAMESPACE
int transform(const QgsCoordinateTransform &ct)
Transform this geometry as described by CoordinateTransform ct.
QString section(QChar sep, int start, int end, QFlags< QString::SectionFlag > flags) const
NetworkError error() const
QgsCoordinateReferenceSystem crs() const
Returns features spatial reference system.
QGis::WkbType wkbType() const
Return the geometry type.
iterator insert(const Key &key, const T &value)
static const char NS_SEPARATOR
QNetworkReply * get(const QNetworkRequest &request)
bool updateNetworkReply(QNetworkReply *reply, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QNetworkReply with an authentication config (used to skip known SSL errors...
const_iterator constEnd() const
const_iterator constBegin() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
int compare(const QString &other) const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
static QgsCRSCache * instance()
Returns a pointer to the QgsCRSCache singleton.
qlonglong toLongLong(bool *ok, int base) const
double x() const
Get the x value of the point.
void setXMinimum(double x)
Set the minimum x value.
bool axisInverted() const
Returns whether axis is inverted (eg.
const T value(const Key &key) const
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QByteArray toUtf8() const