Skip to content

Commit

Permalink
Fix for wfsprovider to better read geoserver data
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@6443 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jan 19, 2007
1 parent 521060d commit 1a661ae
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
10 changes: 9 additions & 1 deletion src/providers/wfs/qgswfsdata.cpp
Expand Up @@ -357,7 +357,15 @@ int QgsWFSData::readEpsgFromAttribute(int& epsgNr, const XML_Char** attr) const
if(strcmp(attr[i], "srsName") == 0)
{
QString epsgString(attr[i+1]);
QString epsgNrString = epsgString.section(":", 1, 1);
QString epsgNrString;
if(epsgString.startsWith("http")) //e.g. geoserver: "http://www.opengis.net/gml/srs/epsg.xml#4326"
{
epsgNrString = epsgString.section("#", 1, 1);
}
else //e.g. umn mapserver: "EPSG:4326">
{
epsgNrString = epsgString.section(":", 1, 1);
}
bool conversionOk;
int eNr = epsgNrString.toInt(&conversionOk);
if(!conversionOk)
Expand Down
57 changes: 35 additions & 22 deletions src/providers/wfs/qgswfsprovider.cpp
Expand Up @@ -501,33 +501,46 @@ int QgsWFSProvider::readAttributesFromSchema(QDomDocument& schemaDoc, QString& g
return 1;
}
QDomElement schemaElement = schemaNodeList.at(0).toElement();

//find <element name="tname" type = ...>
QString complexTypeType;
QDomNodeList typeElementNodeList = schemaElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "element");
QDomElement typeElement = typeElementNodeList.at(0).toElement();
complexTypeType = typeElement.attribute("type");
QDomElement complexTypeElement; //the <complexType> element corresponding to the feature type

if(complexTypeType.isEmpty())
{
return 3;
}
//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

int firstElementTagPos = schemaElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "element").at(0).toElement().columnNumber();
int firstComplexTypeTagPos = schemaElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "complexType").at(0).toElement().columnNumber();

//remove the namespace on complexTypeType
if(complexTypeType.contains(":"))
if(firstComplexTypeTagPos < firstElementTagPos)
{
complexTypeType = complexTypeType.section(":", 1, 1);
//geoserver
complexTypeElement = schemaElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "complexType").at(0).toElement();
}

//find <complexType name=complexTypeType
QDomElement complexTypeElement;
QDomNodeList complexTypeNodeList = schemaElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "complexType");
for(int i = 0; i < complexTypeNodeList.length(); ++i)
else
{
if(complexTypeNodeList.at(i).toElement().attribute("name") == complexTypeType)
//UMN mapserver
QString complexTypeType;
QDomNodeList typeElementNodeList = schemaElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "element");
QDomElement typeElement = typeElementNodeList.at(0).toElement();
complexTypeType = typeElement.attribute("type");

if(complexTypeType.isEmpty())
{
complexTypeElement = complexTypeNodeList.at(i).toElement();
break;
return 3;
}

//remove the namespace on complexTypeType
if(complexTypeType.contains(":"))
{
complexTypeType = complexTypeType.section(":", 1, 1);
}

//find <complexType name=complexTypeType
QDomNodeList complexTypeNodeList = schemaElement.elementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "complexType");
for(int i = 0; i < complexTypeNodeList.length(); ++i)
{
if(complexTypeNodeList.at(i).toElement().attribute("name") == complexTypeType)
{
complexTypeElement = complexTypeNodeList.at(i).toElement();
break;
}
}
}

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

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

0 comments on commit 1a661ae

Please sign in to comment.