23 #include <QNetworkRequest>
24 #include <QNetworkReply>
25 #include <QProgressDialog>
51 for (
int i = 0; i <
mFields.size(); i++ )
53 if (
mFields[i].name() == name )
return i;
63 <<
"LineString" <<
"MultiLineString"
64 <<
"Polygon" <<
"MultiPolygon";
75 while ( attr[i] != NULL )
77 if ( attributeName.compare( attr[i] ) == 0 )
79 return QString( attr[i+1] );
92 if ( !dom.setContent( xml,
false, &errorMsg, &errorLine, &errorColumn ) )
98 QDomElement docElem = dom.documentElement();
100 QList<QDomElement> elementElements =
domElements( docElem,
"element" );
104 foreach ( QDomElement elementElement, elementElements )
106 QString name = elementElement.attribute(
"name" );
107 QString type = elementElement.attribute(
"type" );
116 if ( gmlBaseType ==
"AbstractFeatureType" )
132 QDomElement complexTypeElement =
domElement( element,
"complexType",
"name", typeName );
133 if ( complexTypeElement.isNull() )
return false;
136 QDomElement extrest =
domElement( complexTypeElement,
"complexContent.extension" );
137 if ( extrest.isNull() )
139 extrest =
domElement( complexTypeElement,
"complexContent.restriction" );
141 if ( extrest.isNull() )
return false;
143 QString extrestName = extrest.attribute(
"base" );
144 if ( extrestName ==
"gml:AbstractFeatureType" )
157 QStringList geometryPropertyTypes;
160 geometryPropertyTypes << geom +
"PropertyType";
163 QStringList geometryAliases;
164 geometryAliases <<
"location" <<
"centerOf" <<
"position" <<
"extentOf"
165 <<
"coverage" <<
"edgeOf" <<
"centerLineOf" <<
"multiLocation"
166 <<
"multiCenterOf" <<
"multiPosition" <<
"multiCenterLineOf"
167 <<
"multiEdgeOf" <<
"multiCoverage" <<
"multiExtentOf";
170 QList<QDomElement> sequenceElements =
domElements( extrest,
"sequence.element" );
171 foreach ( QDomElement sequenceElement, sequenceElements )
173 QString fieldName = sequenceElement.attribute(
"name" );
174 QString fieldTypeName =
stripNS( sequenceElement.attribute(
"type" ) );
175 QString ref = sequenceElement.attribute(
"ref" );
178 if ( !ref.isEmpty() )
180 if ( ref.startsWith(
"gml:" ) )
182 if ( geometryAliases.contains(
stripNS( ref ) ) )
188 QgsDebugMsg( QString(
"Unknown referenced GML element: %1" ).arg( ref ) );
194 QgsDebugMsg( QString(
"field %1.%2 is referencing %3 - not supported" ).arg( typeName ).arg( fieldName ) );
199 if ( fieldName.isEmpty() )
201 QgsDebugMsg( QString(
"field in %1 without name" ).arg( typeName ) );
206 if ( fieldTypeName.isEmpty() )
209 QDomElement sequenceElementRestriction =
domElement( sequenceElement,
"simpleType.restriction" );
210 fieldTypeName =
stripNS( sequenceElementRestriction.attribute(
"base" ) );
213 QVariant::Type fieldType = QVariant::String;
214 if ( fieldTypeName.isEmpty() )
216 QgsDebugMsg( QString(
"Cannot get %1.%2 field type" ).arg( typeName ).arg( fieldName ) );
220 if ( geometryPropertyTypes.contains( fieldTypeName ) )
227 if ( fieldTypeName ==
"decimal" )
229 fieldType = QVariant::Double;
231 else if ( fieldTypeName ==
"integer" )
233 fieldType = QVariant::Int;
237 QgsField field( fieldName, fieldType );
238 featureClass.
fields().append( field );
247 QDomElement complexTypeElement =
domElement( element,
"complexType",
"name", name );
248 if ( complexTypeElement.isNull() )
return "";
250 QDomElement extrest =
domElement( complexTypeElement,
"complexContent.extension" );
251 if ( extrest.isNull() )
253 extrest =
domElement( complexTypeElement,
"complexContent.restriction" );
255 if ( extrest.isNull() )
return "";
257 QString extrestName = extrest.attribute(
"base" );
258 if ( extrestName.startsWith(
"gml:" ) )
269 return name.contains(
":" ) ? name.section(
':', 1 ) : name;
274 QList<QDomElement> list;
276 QStringList names = path.split(
"." );
277 if ( names.size() == 0 )
return list;
278 QString name = names.value( 0 );
281 QDomNode n1 = element.firstChild();
282 while ( !n1.isNull() )
284 QDomElement el = n1.toElement();
287 QString tagName =
stripNS( el.tagName() );
288 if ( tagName == name )
290 if ( names.size() == 0 )
296 list.append(
domElements( el, names.join(
"." ) ) );
300 n1 = n1.nextSibling();
313 QList<QDomElement> list;
314 foreach ( QDomElement el, elements )
316 if ( el.attribute( attr ) == attrVal )
324 QDomElement
QgsGmlSchema::domElement(
const QDomElement &element,
const QString & path,
const QString & attr,
const QString & attrVal )
326 QList<QDomElement> list =
domElements( element, path );
327 return domElements( list, attr, attrVal ).value( 0 );
335 XML_Parser p = XML_ParserCreateNS( NULL,
NS_SEPARATOR );
336 XML_SetUserData( p,
this );
340 XML_Parse( p, data.constData(), data.size(), atEnd );
349 QString elementName( el );
361 QStringList splitName = elementName.split(
NS_SEPARATOR );
362 QString localName = splitName.last();
363 QString ns = splitName.size() > 1 ? splitName.first() :
"";
377 else if ( localName.endsWith(
"member", Qt::CaseInsensitive ) )
382 else if ( elementName.endsWith(
"_layer" ) )
388 else if ( elementName.endsWith(
"_feature" )
421 QString elementName( el );
436 QStringList splitName = elementName.split(
NS_SEPARATOR );
437 QString localName = splitName.last();
438 QString ns = splitName.size() > 1 ? splitName.first() :
"";
453 QVariant::Type type = QVariant::String;
456 type = QVariant::Int;
463 type = QVariant::Double;
470 if ( fieldIndex == -1 )
473 fields.append( field );
477 QgsField &field = fields[fieldIndex];
479 if (( field.
type() == QVariant::Int && ( type == QVariant::String || type == QVariant::Double ) ) ||
480 ( field.
type() == QVariant::Double && type == QVariant::String ) )
491 else if ( localName.endsWith(
"member", Qt::CaseInsensitive ) )
512 mStringCash.append( QString::fromUtf8( chars, len ) );