Skip to content

Commit 44aef47

Browse files
Stéphane Brunnermhugent
Stéphane Brunner
authored andcommitted
Copy things from WFS server to WMS server
1 parent bd62f30 commit 44aef47

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

src/mapserver/qgswmsserver.cpp

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,3 +2342,122 @@ void QgsWMSServer::convertFeatureInfoToSIA2045( QDomDocument& doc )
23422342
}
23432343
doc = SIAInfoDoc;
23442344
}
2345+
2346+
/* get from qgswfsserver.cpp */
2347+
QDomElement QgsWMSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsAttributeList attrIndexes, QSet<QString> excludedAttributes ) /*const*/
2348+
{
2349+
//gml:FeatureMember
2350+
QDomElement featureElement = doc.createElement( "gml:featureMember"/*wfs:FeatureMember*/ );
2351+
2352+
//qgs:%TYPENAME%
2353+
QDomElement typeNameElement = doc.createElement( "qgs:" + mTypeName /*qgs:%TYPENAME%*/ );
2354+
typeNameElement.setAttribute( "fid", mTypeName + "." + QString::number( feat->id() ) );
2355+
featureElement.appendChild( typeNameElement );
2356+
2357+
if ( mWithGeom )
2358+
{
2359+
//add geometry column (as gml)
2360+
QgsGeometry* geom = feat->geometry();
2361+
2362+
QDomElement geomElem = doc.createElement( "qgs:geometry" );
2363+
QDomElement gmlElem = QgsOgcUtils::geometryToGML( geom, doc );
2364+
if ( !gmlElem.isNull() )
2365+
{
2366+
QgsRectangle box = geom->boundingBox();
2367+
QDomElement bbElem = doc.createElement( "gml:boundedBy" );
2368+
QDomElement boxElem = QgsOgcUtils::rectangleToGMLBox( &box, doc );
2369+
2370+
if ( crs.isValid() )
2371+
{
2372+
boxElem.setAttribute( "srsName", crs.authid() );
2373+
gmlElem.setAttribute( "srsName", crs.authid() );
2374+
}
2375+
2376+
bbElem.appendChild( boxElem );
2377+
typeNameElement.appendChild( bbElem );
2378+
2379+
geomElem.appendChild( gmlElem );
2380+
typeNameElement.appendChild( geomElem );
2381+
}
2382+
}
2383+
2384+
//read all attribute values from the feature
2385+
QgsAttributes featureAttributes = feat->attributes();
2386+
const QgsFields* fields = feat->fields();
2387+
for ( int i = 0; i < attrIndexes.count(); ++i )
2388+
{
2389+
int idx = attrIndexes[i];
2390+
QString attributeName = fields->at( idx ).name();
2391+
//skip attribute if it is excluded from WFS publication
2392+
if ( excludedAttributes.contains( attributeName ) )
2393+
{
2394+
continue;
2395+
}
2396+
2397+
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( QString( " " ), QString( "_" ) ) );
2398+
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
2399+
fieldElem.appendChild( fieldText );
2400+
typeNameElement.appendChild( fieldElem );
2401+
}
2402+
2403+
return featureElement;
2404+
}
2405+
2406+
QDomElement QgsWMSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsAttributeList attrIndexes, QSet<QString> excludedAttributes ) /*const*/
2407+
{
2408+
//gml:FeatureMember
2409+
QDomElement featureElement = doc.createElement( "gml:featureMember"/*wfs:FeatureMember*/ );
2410+
2411+
//qgs:%TYPENAME%
2412+
QDomElement typeNameElement = doc.createElement( "qgs:" + mTypeName /*qgs:%TYPENAME%*/ );
2413+
typeNameElement.setAttribute( "gml:id", mTypeName + "." + QString::number( feat->id() ) );
2414+
featureElement.appendChild( typeNameElement );
2415+
2416+
if ( mWithGeom )
2417+
{
2418+
//add geometry column (as gml)
2419+
QgsGeometry* geom = feat->geometry();
2420+
2421+
QDomElement geomElem = doc.createElement( "qgs:geometry" );
2422+
QDomElement gmlElem = QgsOgcUtils::geometryToGML( geom, doc, "GML3" );
2423+
if ( !gmlElem.isNull() )
2424+
{
2425+
QgsRectangle box = geom->boundingBox();
2426+
QDomElement bbElem = doc.createElement( "gml:boundedBy" );
2427+
QDomElement boxElem = QgsOgcUtils::rectangleToGMLEnvelope( &box, doc );
2428+
2429+
if ( crs.isValid() )
2430+
{
2431+
boxElem.setAttribute( "srsName", crs.authid() );
2432+
gmlElem.setAttribute( "srsName", crs.authid() );
2433+
}
2434+
2435+
bbElem.appendChild( boxElem );
2436+
typeNameElement.appendChild( bbElem );
2437+
2438+
geomElem.appendChild( gmlElem );
2439+
typeNameElement.appendChild( geomElem );
2440+
}
2441+
}
2442+
2443+
//read all attribute values from the feature
2444+
QgsAttributes featureAttributes = feat->attributes();
2445+
const QgsFields* fields = feat->fields();
2446+
for ( int i = 0; i < attrIndexes.count(); ++i )
2447+
{
2448+
int idx = attrIndexes[i];
2449+
QString attributeName = fields->at( idx ).name();
2450+
//skip attribute if it is excluded from WFS publication
2451+
if ( excludedAttributes.contains( attributeName ) )
2452+
{
2453+
continue;
2454+
}
2455+
2456+
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( QString( " " ), QString( "_" ) ) );
2457+
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
2458+
fieldElem.appendChild( fieldText );
2459+
typeNameElement.appendChild( fieldElem );
2460+
}
2461+
2462+
return featureElement;
2463+
}

src/mapserver/qgswmsserver.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ class QgsWMSServer
205205
QMap<QString, QString> mParameterMap;
206206
QgsConfigParser* mConfigParser;
207207
QgsMapRenderer* mMapRenderer;
208+
209+
/* get from qgswfsserver.h */
210+
//methods to write GML2
211+
QDomElement createFeatureGML2( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs ) /*const*/;
212+
//methods to write GML3
213+
QDomElement createFeatureGML3( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs ) /*const*/;
208214
};
209215

210216
#endif

0 commit comments

Comments
 (0)