24 #include <QNetworkRequest>
25 #include <QNetworkReply>
26 #include <QProgressDialog>
52 for (
int i = 0; i <
mFields.size(); i++ )
54 if (
mFields[i].name() == name )
return i;
64 <<
"LineString" <<
"MultiLineString"
65 <<
"Polygon" <<
"MultiPolygon";
76 while ( attr[i] != NULL )
78 if ( attributeName.compare( attr[i] ) == 0 )
80 return QString( attr[i+1] );
93 if ( !dom.setContent( xml,
false, &errorMsg, &errorLine, &errorColumn ) )
99 QDomElement docElem = dom.documentElement();
101 QList<QDomElement> elementElements =
domElements( docElem,
"element" );
105 foreach ( QDomElement elementElement, elementElements )
107 QString name = elementElement.attribute(
"name" );
108 QString type = elementElement.attribute(
"type" );
117 if ( gmlBaseType ==
"AbstractFeatureType" )
133 QDomElement complexTypeElement =
domElement( element,
"complexType",
"name", typeName );
134 if ( complexTypeElement.isNull() )
return false;
137 QDomElement extrest =
domElement( complexTypeElement,
"complexContent.extension" );
138 if ( extrest.isNull() )
140 extrest =
domElement( complexTypeElement,
"complexContent.restriction" );
142 if ( extrest.isNull() )
return false;
144 QString extrestName = extrest.attribute(
"base" );
145 if ( extrestName ==
"gml:AbstractFeatureType" )
158 QStringList geometryPropertyTypes;
161 geometryPropertyTypes << geom +
"PropertyType";
164 QStringList geometryAliases;
165 geometryAliases <<
"location" <<
"centerOf" <<
"position" <<
"extentOf"
166 <<
"coverage" <<
"edgeOf" <<
"centerLineOf" <<
"multiLocation"
167 <<
"multiCenterOf" <<
"multiPosition" <<
"multiCenterLineOf"
168 <<
"multiEdgeOf" <<
"multiCoverage" <<
"multiExtentOf";
171 QList<QDomElement> sequenceElements =
domElements( extrest,
"sequence.element" );
172 foreach ( QDomElement sequenceElement, sequenceElements )
174 QString fieldName = sequenceElement.attribute(
"name" );
175 QString fieldTypeName =
stripNS( sequenceElement.attribute(
"type" ) );
176 QString ref = sequenceElement.attribute(
"ref" );
179 if ( !ref.isEmpty() )
181 if ( ref.startsWith(
"gml:" ) )
183 if ( geometryAliases.contains(
stripNS( ref ) ) )
189 QgsDebugMsg( QString(
"Unknown referenced GML element: %1" ).arg( ref ) );
195 QgsDebugMsg( QString(
"field %1.%2 is referencing %3 - not supported" ).arg( typeName ).arg( fieldName ) );
200 if ( fieldName.isEmpty() )
202 QgsDebugMsg( QString(
"field in %1 without name" ).arg( typeName ) );
207 if ( fieldTypeName.isEmpty() )
210 QDomElement sequenceElementRestriction =
domElement( sequenceElement,
"simpleType.restriction" );
211 fieldTypeName =
stripNS( sequenceElementRestriction.attribute(
"base" ) );
214 QVariant::Type fieldType = QVariant::String;
215 if ( fieldTypeName.isEmpty() )
217 QgsDebugMsg( QString(
"Cannot get %1.%2 field type" ).arg( typeName ).arg( fieldName ) );
221 if ( geometryPropertyTypes.contains( fieldTypeName ) )
228 if ( fieldTypeName ==
"decimal" )
230 fieldType = QVariant::Double;
232 else if ( fieldTypeName ==
"integer" )
234 fieldType = QVariant::Int;
238 QgsField field( fieldName, fieldType, fieldTypeName );
239 featureClass.
fields().append( field );
248 QDomElement complexTypeElement =
domElement( element,
"complexType",
"name", name );
249 if ( complexTypeElement.isNull() )
return "";
251 QDomElement extrest =
domElement( complexTypeElement,
"complexContent.extension" );
252 if ( extrest.isNull() )
254 extrest =
domElement( complexTypeElement,
"complexContent.restriction" );
256 if ( extrest.isNull() )
return "";
258 QString extrestName = extrest.attribute(
"base" );
259 if ( extrestName.startsWith(
"gml:" ) )
270 return name.contains(
":" ) ? name.section(
':', 1 ) : name;
275 QList<QDomElement> list;
277 QStringList names = path.split(
"." );
278 if ( names.size() == 0 )
return list;
279 QString name = names.value( 0 );
282 QDomNode n1 = element.firstChild();
283 while ( !n1.isNull() )
285 QDomElement el = n1.toElement();
288 QString tagName =
stripNS( el.tagName() );
289 if ( tagName == name )
291 if ( names.size() == 0 )
297 list.append(
domElements( el, names.join(
"." ) ) );
301 n1 = n1.nextSibling();
314 QList<QDomElement> list;
315 foreach ( QDomElement el, elements )
317 if ( el.attribute( attr ) == attrVal )
325 QDomElement
QgsGmlSchema::domElement(
const QDomElement &element,
const QString & path,
const QString & attr,
const QString & attrVal )
327 QList<QDomElement> list =
domElements( element, path );
328 return domElements( list, attr, attrVal ).value( 0 );
336 XML_Parser p = XML_ParserCreateNS( NULL,
NS_SEPARATOR );
337 XML_SetUserData( p,
this );
341 int res = XML_Parse( p, data.constData(), data.size(), atEnd );
345 QString err = QString( XML_ErrorString( XML_GetErrorCode( p ) ) );
346 QgsDebugMsg( QString(
"XML_Parse returned %1 error %2" ).arg( res ).arg( err ) );
359 QString elementName( el );
371 QStringList splitName = elementName.split(
NS_SEPARATOR );
372 QString localName = splitName.last();
373 QString ns = splitName.size() > 1 ? splitName.first() :
"";
383 else if ( localName.compare(
"featureMembers", Qt::CaseInsensitive ) == 0 )
391 else if ( localName.endsWith(
"member", Qt::CaseInsensitive ) )
396 else if ( elementName.endsWith(
"_layer" ) )
402 else if ( elementName.endsWith(
"_feature" )
436 QString elementName( el );
451 QStringList splitName = elementName.split(
NS_SEPARATOR );
452 QString localName = splitName.last();
453 QString ns = splitName.size() > 1 ? splitName.first() :
"";
472 QVariant::Type type = QVariant::String;
475 type = QVariant::Int;
482 type = QVariant::Double;
489 if ( fieldIndex == -1 )
492 fields.append( field );
496 QgsField &field = fields[fieldIndex];
498 if (( field.
type() == QVariant::Int && ( type == QVariant::String || type == QVariant::Double ) ) ||
499 ( field.
type() == QVariant::Double && type == QVariant::String ) )
510 else if ( localName.endsWith(
"member", Qt::CaseInsensitive ) )
530 mStringCash.append( QString::fromUtf8( chars, len ) );