void QgsWFSServer::sendGetFeature( QgsRequestHandler& request, const QString& format, QgsFeature* feat, int featIdx, QgsCoordinateReferenceSystem& crs, QMap< int, QgsField > fields, QSet<QString> hiddenAttributes ) /*const*/ { QByteArray result; if ( format == "GeoJSON" ) { QString fcString; if ( featIdx == 0 ) fcString += " "; else fcString += " ,"; fcString += createFeatureGeoJSON( feat, crs, fields, hiddenAttributes ); fcString += "\n"; result = fcString.toUtf8(); request.sendGetFeatureResponse( &result ); fcString = ""; } else { QDomDocument gmlDoc; QDomElement featureElement = createFeatureElem( feat, gmlDoc, crs, fields, hiddenAttributes ); gmlDoc.appendChild( featureElement ); result = gmlDoc.toByteArray(); request.sendGetFeatureResponse( &result ); gmlDoc.removeChild( featureElement ); } }
void QgsWFSServer::startGetFeature( QgsRequestHandler& request, const QString& format, QgsCoordinateReferenceSystem& crs, QgsRectangle* rect ) { QByteArray result; QString fcString; if ( format == "GeoJSON" ) { fcString = "{\"type\": \"FeatureCollection\",\n"; fcString += " \"bbox\": [ " + QString::number( rect->xMinimum(), 'f', 6 ).remove( QRegExp( "[0]{1,5}$" ) ) + ", " + QString::number( rect->yMinimum(), 'f', 6 ).remove( QRegExp( "[0]{1,5}$" ) ) + ", " + QString::number( rect->xMaximum(), 'f', 6 ).remove( QRegExp( "[0]{1,5}$" ) ) + ", " + QString::number( rect->yMaximum(), 'f', 6 ).remove( QRegExp( "[0]{1,5}$" ) ) + "],\n"; fcString += " \"features\": [\n"; result = fcString.toUtf8(); request.startGetFeatureResponse( &result, format ); } else { //Prepare url //Some client requests already have http://<SERVER_NAME> in the REQUEST_URI variable QString hrefString; QString requestUrl = getenv( "REQUEST_URI" ); QUrl mapUrl( requestUrl ); mapUrl.setHost( QString( getenv( "SERVER_NAME" ) ) ); //Add non-default ports to url QString portString = getenv( "SERVER_PORT" ); if ( !portString.isEmpty() ) { bool portOk; int portNumber = portString.toInt( &portOk ); if ( portOk ) { if ( portNumber != 80 ) { mapUrl.setPort( portNumber ); } } } if ( QString( getenv( "HTTPS" ) ).compare( "on", Qt::CaseInsensitive ) == 0 ) { mapUrl.setScheme( "https" ); } else { mapUrl.setScheme( "http" ); } QList<QPair<QString, QString> > queryItems = mapUrl.queryItems(); QList<QPair<QString, QString> >::const_iterator queryIt = queryItems.constBegin(); for ( ; queryIt != queryItems.constEnd(); ++queryIt ) { if ( queryIt->first.compare( "REQUEST", Qt::CaseInsensitive ) == 0 ) { mapUrl.removeQueryItem( queryIt->first ); mapUrl.addQueryItem( queryIt->first, "DescribeFeatureType" ); } else if ( queryIt->first.compare( "FORMAT", Qt::CaseInsensitive ) == 0 ) { mapUrl.removeQueryItem( queryIt->first ); } else if ( queryIt->first.compare( "OUTPUTFORMAT", Qt::CaseInsensitive ) == 0 ) { mapUrl.removeQueryItem( queryIt->first ); } else if ( queryIt->first.compare( "BBOX", Qt::CaseInsensitive ) == 0 ) { mapUrl.removeQueryItem( queryIt->first ); } else if ( queryIt->first.compare( "FEATUREID", Qt::CaseInsensitive ) == 0 ) { mapUrl.removeQueryItem( queryIt->first ); } else if ( queryIt->first.compare( "FILTER", Qt::CaseInsensitive ) == 0 ) { mapUrl.removeQueryItem( queryIt->first ); } else if ( queryIt->first.compare( "MAXFEATURES", Qt::CaseInsensitive ) == 0 ) { mapUrl.removeQueryItem( queryIt->first ); } else if ( queryIt->first.compare( "PROPERTYNAME", Qt::CaseInsensitive ) == 0 ) { mapUrl.removeQueryItem( queryIt->first ); } else if ( queryIt->first.compare( "_DC", Qt::CaseInsensitive ) == 0 ) { mapUrl.removeQueryItem( queryIt->first ); } } mapUrl.addQueryItem( "OUTPUTFORMAT", "XMLSCHEMA" ); hrefString = mapUrl.toString(); //wfs:FeatureCollection fcString = "<wfs:FeatureCollection"; fcString += " xmlns:wfs=\"http://www.opengis.net/wfs\""; fcString += " xmlns:ogc=\"http://www.opengis.net/ogc\""; fcString += " xmlns:gml=\"http://www.opengis.net/gml\""; fcString += " xmlns:ows=\"http://www.opengis.net/ows\""; fcString += " xmlns:xlink=\"http://www.w3.org/1999/xlink\""; fcString += " xmlns:qgs=\"http://www.qgis.org/gml\""; fcString += " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""; fcString += " xsi:schemaLocation=\"http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://www.qgis.org/gml " + hrefString.replace( "&", "&" ) + "\""; fcString += ">"; result = fcString.toUtf8(); request.startGetFeatureResponse( &result, format ); QDomDocument doc; QDomElement bbElem = doc.createElement( "gml:boundedBy" ); QDomElement boxElem = createBoxElem( rect, doc ); if ( !boxElem.isNull() ) { if ( crs.isValid() ) { boxElem.setAttribute( "srsName", crs.authid() ); } bbElem.appendChild( boxElem ); doc.appendChild( bbElem ); } result = doc.toByteArray(); request.sendGetFeatureResponse( &result ); } fcString = ""; }