Skip to content

File tree

2 files changed

+44
-23
lines changed

2 files changed

+44
-23
lines changed
 

‎src/providers/wfs/qgswfsdata.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,15 @@ int QgsWFSData::readEpsgFromAttribute(int& epsgNr, const XML_Char** attr) const
357357
if(strcmp(attr[i], "srsName") == 0)
358358
{
359359
QString epsgString(attr[i+1]);
360-
QString epsgNrString = epsgString.section(":", 1, 1);
360+
QString epsgNrString;
361+
if(epsgString.startsWith("http")) //e.g. geoserver: "http://www.opengis.net/gml/srs/epsg.xml#4326"
362+
{
363+
epsgNrString = epsgString.section("#", 1, 1);
364+
}
365+
else //e.g. umn mapserver: "EPSG:4326">
366+
{
367+
epsgNrString = epsgString.section(":", 1, 1);
368+
}
361369
bool conversionOk;
362370
int eNr = epsgNrString.toInt(&conversionOk);
363371
if(!conversionOk)

‎src/providers/wfs/qgswfsprovider.cpp

+35-22
Original file line numberDiff line numberDiff line change
@@ -501,33 +501,46 @@ int QgsWFSProvider::readAttributesFromSchema(QDomDocument& schemaDoc, QString& g
501501
return 1;
502502
}
503503
QDomElement schemaElement = schemaNodeList.at(0).toElement();
504-
505-
//find <element name="tname" type = ...>
506-
QString complexTypeType;
507-
QDomNodeList typeElementNodeList = schemaElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "element");
508-
QDomElement typeElement = typeElementNodeList.at(0).toElement();
509-
complexTypeType = typeElement.attribute("type");
504+
QDomElement complexTypeElement; //the <complexType> element corresponding to the feature type
510505

511-
if(complexTypeType.isEmpty())
512-
{
513-
return 3;
514-
}
506+
//find out, on which lines the first <element> or the first <complexType> occur. If <element> occurs first (mapserver), read the type of the relevant <complexType> tag. If <complexType> occurs first (geoserver), search for information about the feature type directly under this first complexType element
507+
508+
int firstElementTagPos = schemaElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "element").at(0).toElement().columnNumber();
509+
int firstComplexTypeTagPos = schemaElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "complexType").at(0).toElement().columnNumber();
515510

516-
//remove the namespace on complexTypeType
517-
if(complexTypeType.contains(":"))
511+
if(firstComplexTypeTagPos < firstElementTagPos)
518512
{
519-
complexTypeType = complexTypeType.section(":", 1, 1);
513+
//geoserver
514+
complexTypeElement = schemaElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "complexType").at(0).toElement();
520515
}
521-
522-
//find <complexType name=complexTypeType
523-
QDomElement complexTypeElement;
524-
QDomNodeList complexTypeNodeList = schemaElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "complexType");
525-
for(int i = 0; i < complexTypeNodeList.length(); ++i)
516+
else
526517
{
527-
if(complexTypeNodeList.at(i).toElement().attribute("name") == complexTypeType)
518+
//UMN mapserver
519+
QString complexTypeType;
520+
QDomNodeList typeElementNodeList = schemaElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "element");
521+
QDomElement typeElement = typeElementNodeList.at(0).toElement();
522+
complexTypeType = typeElement.attribute("type");
523+
524+
if(complexTypeType.isEmpty())
528525
{
529-
complexTypeElement = complexTypeNodeList.at(i).toElement();
530-
break;
526+
return 3;
527+
}
528+
529+
//remove the namespace on complexTypeType
530+
if(complexTypeType.contains(":"))
531+
{
532+
complexTypeType = complexTypeType.section(":", 1, 1);
533+
}
534+
535+
//find <complexType name=complexTypeType
536+
QDomNodeList complexTypeNodeList = schemaElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "complexType");
537+
for(int i = 0; i < complexTypeNodeList.length(); ++i)
538+
{
539+
if(complexTypeNodeList.at(i).toElement().attribute("name") == complexTypeType)
540+
{
541+
complexTypeElement = complexTypeNodeList.at(i).toElement();
542+
break;
543+
}
531544
}
532545
}
533546

@@ -536,7 +549,7 @@ int QgsWFSProvider::readAttributesFromSchema(QDomDocument& schemaDoc, QString& g
536549
return 4;
537550
}
538551

539-
//now create the attributes
552+
//we have the relevant <complexType> element. Now find out the geometry and the thematic attributes
540553
QDomNodeList attributeNodeList = complexTypeElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "element");
541554
if(attributeNodeList.size() < 1)
542555
{

0 commit comments

Comments
 (0)
Please sign in to comment.