mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Simplifying QgsOgcUtils
After commit 7d66529d7884b73070dbce80b1d4060d841a6933 Add GML3 to QgsOgcUtils, I have to simplify this class to only have : * geometryFromGML : read GML2 or GML3 * geometryToGML : create GML2 (as default) or GML3
This commit is contained in:
parent
a915c41a7c
commit
93e0259843
@ -8,42 +8,32 @@ class QgsOgcUtils
|
||||
|
||||
public:
|
||||
|
||||
/** static method that creates geometry from GML2
|
||||
/** static method that creates geometry from GML
|
||||
@param XML representation of the geometry. GML elements are expected to be
|
||||
in default namespace (<Point>...</Point>) or in "gml" namespace (<gml:Point>...</gml:Point>)
|
||||
@note added in 1.9
|
||||
*/
|
||||
static QgsGeometry* geometryFromGML2( const QString& xmlString ) /Factory/;
|
||||
static QgsGeometry* geometryFromGML( const QString& xmlString ) /Factory/;
|
||||
|
||||
/** static method that creates geometry from GML2
|
||||
/** static method that creates geometry from GML
|
||||
@note added in 1.9
|
||||
*/
|
||||
static QgsGeometry* geometryFromGML2( const QDomNode& geometryNode ) /Factory/;
|
||||
|
||||
/** Exports the geometry to mGML2
|
||||
@return true in case of success and false else
|
||||
*/
|
||||
static QDomElement geometryToGML2( QgsGeometry* geometry, QDomDocument& doc );
|
||||
static QgsGeometry* geometryFromGML( const QDomNode& geometryNode ) /Factory/;
|
||||
|
||||
/** read rectangle from GML2 Box */
|
||||
static QgsRectangle rectangleFromGMLBox( const QDomNode& boxNode );
|
||||
|
||||
|
||||
/** static method that creates geometry from GML3
|
||||
@param XML representation of the geometry. GML elements are expected to be
|
||||
in default namespace (<Point>...</Point>) or in "gml" namespace (<gml:Point>...</gml:Point>)
|
||||
*/
|
||||
static QgsGeometry* geometryFromGML3( const QString& xmlString );
|
||||
|
||||
/** static method that creates geometry from GML2
|
||||
*/
|
||||
static QgsGeometry* geometryFromGML3( const QDomNode& geometryNode );
|
||||
/** Exports the geometry to mGML3
|
||||
@return true in case of success and false else
|
||||
*/
|
||||
static QDomElement geometryToGML3( QgsGeometry* geometry, QDomDocument& doc );
|
||||
|
||||
/** read rectangle from GML3 Envelope */
|
||||
static QgsRectangle rectangleFromGMLEnvelope( const QDomNode& envelopeNode );
|
||||
|
||||
/** Exports the geometry to GML2
|
||||
@return QDomElement
|
||||
*/
|
||||
static QDomElement geometryToGML( QgsGeometry* geometry, QDomDocument& doc );
|
||||
|
||||
/** Exports the geometry to GML2 or GML3
|
||||
@return QDomElement
|
||||
*/
|
||||
static QDomElement geometryToGML( QgsGeometry* geometry, QDomDocument& doc, QString Format );
|
||||
};
|
||||
|
||||
|
@ -797,7 +797,7 @@ static QVariant fcnGeomFromWKT( const QVariantList& values, QgsFeature*, QgsExpr
|
||||
static QVariant fcnGeomFromGML2( const QVariantList& values, QgsFeature*, QgsExpression* parent )
|
||||
{
|
||||
QString gml = getStringValue( values.at( 0 ), parent );
|
||||
QgsGeometry* geom = QgsOgcUtils::geometryFromGML2( gml );
|
||||
QgsGeometry* geom = QgsOgcUtils::geometryFromGML( gml );
|
||||
|
||||
if ( geom )
|
||||
return QVariant::fromValue( *geom );
|
||||
@ -2271,7 +2271,7 @@ void QgsExpression::NodeFunction::toOgcFilter( QDomDocument &doc, QDomElement &e
|
||||
{
|
||||
QgsGeometry* geom = QgsGeometry::fromWkt( childElem.firstChildElement().text() );
|
||||
if ( geom )
|
||||
funcElem.appendChild( QgsOgcUtils::geometryToGML2( geom, doc ) );
|
||||
funcElem.appendChild( QgsOgcUtils::geometryToGML( geom, doc ) );
|
||||
delete geom;
|
||||
}
|
||||
else if ( childElem.attribute( "name" ) == "geomFromGML2" )
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,6 +7,7 @@ class QDomDocument;
|
||||
class QString;
|
||||
|
||||
#include <list>
|
||||
#include <QVector>
|
||||
|
||||
class QgsGeometry;
|
||||
class QgsPoint;
|
||||
@ -26,78 +27,78 @@ class CORE_EXPORT QgsOgcUtils
|
||||
public:
|
||||
|
||||
|
||||
/** static method that creates geometry from GML2
|
||||
/** static method that creates geometry from GML
|
||||
@param XML representation of the geometry. GML elements are expected to be
|
||||
in default namespace (<Point>...</Point>) or in "gml" namespace (<gml:Point>...</gml:Point>)
|
||||
*/
|
||||
static QgsGeometry* geometryFromGML2( const QString& xmlString );
|
||||
static QgsGeometry* geometryFromGML( const QString& xmlString );
|
||||
|
||||
/** static method that creates geometry from GML2
|
||||
/** static method that creates geometry from GML
|
||||
*/
|
||||
static QgsGeometry* geometryFromGML2( const QDomNode& geometryNode );
|
||||
|
||||
/** Exports the geometry to mGML2
|
||||
@return true in case of success and false else
|
||||
*/
|
||||
static QDomElement geometryToGML2( QgsGeometry* geometry, QDomDocument& doc );
|
||||
static QgsGeometry* geometryFromGML( const QDomNode& geometryNode );
|
||||
|
||||
/** read rectangle from GML2 Box */
|
||||
static QgsRectangle rectangleFromGMLBox( const QDomNode& boxNode );
|
||||
|
||||
|
||||
/** static method that creates geometry from GML3
|
||||
@param XML representation of the geometry. GML elements are expected to be
|
||||
in default namespace (<Point>...</Point>) or in "gml" namespace (<gml:Point>...</gml:Point>)
|
||||
*/
|
||||
static QgsGeometry* geometryFromGML3( const QString& xmlString );
|
||||
|
||||
/** static method that creates geometry from GML2
|
||||
*/
|
||||
static QgsGeometry* geometryFromGML3( const QDomNode& geometryNode );
|
||||
/** Exports the geometry to mGML3
|
||||
@return true in case of success and false else
|
||||
*/
|
||||
static QDomElement geometryToGML3( QgsGeometry* geometry, QDomDocument& doc );
|
||||
|
||||
/** read rectangle from GML3 Envelope */
|
||||
static QgsRectangle rectangleFromGMLEnvelope( const QDomNode& envelopeNode );
|
||||
|
||||
/** Exports the geometry to GML2 or GML3
|
||||
@return QDomELement
|
||||
*/
|
||||
static QDomElement geometryToGML( QgsGeometry* geometry, QDomDocument& doc, QString format );
|
||||
|
||||
/** Exports the geometry to GML2
|
||||
@return QDomElement
|
||||
*/
|
||||
static QDomElement geometryToGML( QgsGeometry* geometry, QDomDocument& doc );
|
||||
|
||||
/** Exports the rectangle to GML2 Box
|
||||
@return QDomElement
|
||||
*/
|
||||
static QDomElement rectangleToGMLBox( QgsRectangle* box, QDomDocument& doc );
|
||||
|
||||
/** Exports the rectangle to GML2 Envelope
|
||||
@return QDomElement
|
||||
*/
|
||||
static QDomElement rectangleToGMLEnvelope( QgsRectangle* env, QDomDocument& doc );
|
||||
|
||||
private:
|
||||
/** static method that creates geometry from GML2 Point */
|
||||
static QgsGeometry* geometryFromGML2Point( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML2 LineString */
|
||||
static QgsGeometry* geometryFromGML2LineString( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML2 Polygon */
|
||||
static QgsGeometry* geometryFromGML2Polygon( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML2 MultiPoint */
|
||||
static QgsGeometry* geometryFromGML2MultiPoint( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML2 MultiLineString */
|
||||
static QgsGeometry* geometryFromGML2MultiLineString( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML2 MultiPolygon */
|
||||
static QgsGeometry* geometryFromGML2MultiPolygon( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML Point */
|
||||
static QgsGeometry* geometryFromGMLPoint( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML LineString */
|
||||
static QgsGeometry* geometryFromGMLLineString( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML Polygon */
|
||||
static QgsGeometry* geometryFromGMLPolygon( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML MultiPoint */
|
||||
static QgsGeometry* geometryFromGMLMultiPoint( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML MultiLineString */
|
||||
static QgsGeometry* geometryFromGMLMultiLineString( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML MultiPolygon */
|
||||
static QgsGeometry* geometryFromGMLMultiPolygon( const QDomElement& geometryElement );
|
||||
/** Reads the <gml:coordinates> element and extracts the coordinates as points
|
||||
@param coords list where the found coordinates are appended
|
||||
@param elem the <gml:coordinates> element
|
||||
@return boolean for success*/
|
||||
static bool readGML2Coordinates( std::list<QgsPoint>& coords, const QDomElement elem );
|
||||
|
||||
/** static method that creates geometry from GML3 Point */
|
||||
static QgsGeometry* geometryFromGML3Point( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML3 LineString */
|
||||
static QgsGeometry* geometryFromGML3LineString( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML3 Polygon */
|
||||
static QgsGeometry* geometryFromGML3Polygon( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML3 MultiPoint */
|
||||
static QgsGeometry* geometryFromGML3MultiPoint( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML3 MultiLineString */
|
||||
static QgsGeometry* geometryFromGML3MultiLineString( const QDomElement& geometryElement );
|
||||
/** static method that creates geometry from GML3 MultiPolygon */
|
||||
static QgsGeometry* geometryFromGML3MultiPolygon( const QDomElement& geometryElement );
|
||||
static bool readGMLCoordinates( std::list<QgsPoint>& coords, const QDomElement elem );
|
||||
/** Reads the <gml:pos> or <gml:posList> element and extracts the coordinates as points
|
||||
@param coords list where the found coordinates are appended
|
||||
@param elem the <gml:pos> or <gml:posList> element
|
||||
@return boolean for success*/
|
||||
static bool readGML3Positions( std::list<QgsPoint>& coords, const QDomElement elem );
|
||||
static bool readGMLPositions( std::list<QgsPoint>& coords, const QDomElement elem );
|
||||
|
||||
|
||||
/**Create a GML coordinates element from a point list.
|
||||
@param points list of data points
|
||||
@param the GML document
|
||||
@return QDomElement */
|
||||
static QDomElement createGMLCoordinates( const QVector<QgsPoint> points, QDomDocument& doc );
|
||||
|
||||
/**Create a GML pos or posList element from a point list.
|
||||
@param points list of data points
|
||||
@param the GML document
|
||||
@return QDomElement */
|
||||
static QDomElement createGMLPositions( const QVector<QgsPoint> points, QDomDocument& doc );
|
||||
};
|
||||
|
||||
#endif // QGSOGCUTILS_H
|
||||
|
@ -131,7 +131,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
|
||||
if ( gNodes.size() > 0 )
|
||||
{
|
||||
QDomElement gElem = gNodes.at( 0 ).toElement();
|
||||
geom = QgsOgcUtils::geometryFromGML2( gElem );
|
||||
geom = QgsOgcUtils::geometryFromGML( gElem );
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
|
||||
if ( gNodes.size() > 0 )
|
||||
{
|
||||
QDomElement gElem = gNodes.at( 0 ).toElement();
|
||||
geom = QgsOgcUtils::geometryFromGML2( gElem );
|
||||
geom = QgsOgcUtils::geometryFromGML( gElem );
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
|
||||
if ( gNodes.size() > 0 )
|
||||
{
|
||||
QDomElement gElem = gNodes.at( 0 ).toElement();
|
||||
geom = QgsOgcUtils::geometryFromGML2( gElem );
|
||||
geom = QgsOgcUtils::geometryFromGML( gElem );
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
|
||||
if ( gNodes.size() > 0 )
|
||||
{
|
||||
QDomElement gElem = gNodes.at( 0 ).toElement();
|
||||
geom = QgsOgcUtils::geometryFromGML2( gElem );
|
||||
geom = QgsOgcUtils::geometryFromGML( gElem );
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
|
||||
if ( gNodes.size() > 0 )
|
||||
{
|
||||
QDomElement gElem = gNodes.at( 0 ).toElement();
|
||||
geom = QgsOgcUtils::geometryFromGML2( gElem );
|
||||
geom = QgsOgcUtils::geometryFromGML( gElem );
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,7 +181,7 @@ QgsFilter* QgsFilter::createFilterFromXml( const QDomElement& filterElem, QgsVec
|
||||
if ( gNodes.size() > 0 )
|
||||
{
|
||||
QDomElement gElem = gNodes.at( 0 ).toElement();
|
||||
geom = QgsOgcUtils::geometryFromGML2( gElem );
|
||||
geom = QgsOgcUtils::geometryFromGML( gElem );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -517,7 +517,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
|
||||
}
|
||||
else if ( childElem.tagName() != "PropertyName" )
|
||||
{
|
||||
QgsGeometry *geom = QgsOgcUtils::geometryFromGML2( childElem );
|
||||
QgsGeometry *geom = QgsOgcUtils::geometryFromGML( childElem );
|
||||
req.setFilterRect( geom->boundingBox() );
|
||||
delete geom;
|
||||
}
|
||||
@ -900,7 +900,7 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
|
||||
}
|
||||
else if ( childElem.tagName() != "PropertyName" )
|
||||
{
|
||||
QgsGeometry* geom = QgsOgcUtils::geometryFromGML2( childElem );
|
||||
QgsGeometry* geom = QgsOgcUtils::geometryFromGML( childElem );
|
||||
req.setFilterRect( geom->boundingBox() );
|
||||
delete geom;
|
||||
}
|
||||
@ -1097,7 +1097,7 @@ void QgsWFSServer::startGetFeature( QgsRequestHandler& request, const QString& f
|
||||
QDomElement bbElem = doc.createElement( "gml:boundedBy" );
|
||||
if ( format == "GML3" )
|
||||
{
|
||||
QDomElement envElem = createEnvelopeGML3( rect, doc );
|
||||
QDomElement envElem = QgsOgcUtils::rectangleToGMLEnvelope( rect, doc );
|
||||
if ( !envElem.isNull() )
|
||||
{
|
||||
if ( crs.isValid() )
|
||||
@ -1110,7 +1110,7 @@ void QgsWFSServer::startGetFeature( QgsRequestHandler& request, const QString& f
|
||||
}
|
||||
else
|
||||
{
|
||||
QDomElement boxElem = createBoxGML2( rect, doc );
|
||||
QDomElement boxElem = QgsOgcUtils::rectangleToGMLBox( rect, doc );
|
||||
if ( !boxElem.isNull() )
|
||||
{
|
||||
if ( crs.isValid() )
|
||||
@ -1364,7 +1364,7 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
|
||||
|
||||
if ( !geometryElem.isNull() )
|
||||
{
|
||||
if ( !layer->changeGeometry( *fidIt, QgsOgcUtils::geometryFromGML2( geometryElem ) ) )
|
||||
if ( !layer->changeGeometry( *fidIt, QgsOgcUtils::geometryFromGML( geometryElem ) ) )
|
||||
throw QgsMapServiceException( "RequestNotWellFormed", "Error in change geometry" );
|
||||
}
|
||||
}
|
||||
@ -1480,7 +1480,7 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
|
||||
}
|
||||
else //a geometry attribute
|
||||
{
|
||||
f->setGeometry( QgsOgcUtils::geometryFromGML2( currentAttributeElement ) );
|
||||
f->setGeometry( QgsOgcUtils::geometryFromGML( currentAttributeElement ) );
|
||||
}
|
||||
}
|
||||
currentAttributeChild = currentAttributeChild.nextSibling();
|
||||
@ -1678,12 +1678,12 @@ QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc
|
||||
QgsGeometry* geom = feat->geometry();
|
||||
|
||||
QDomElement geomElem = doc.createElement( "qgs:geometry" );
|
||||
QDomElement gmlElem = QgsOgcUtils::geometryToGML2( geom, doc );
|
||||
QDomElement gmlElem = QgsOgcUtils::geometryToGML( geom, doc );
|
||||
if ( !gmlElem.isNull() )
|
||||
{
|
||||
QgsRectangle box = geom->boundingBox();
|
||||
QDomElement bbElem = doc.createElement( "gml:boundedBy" );
|
||||
QDomElement boxElem = createBoxGML2( &box, doc );
|
||||
QDomElement boxElem = QgsOgcUtils::rectangleToGMLBox( &box, doc );
|
||||
|
||||
if ( crs.isValid() )
|
||||
{
|
||||
@ -1720,27 +1720,6 @@ QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc
|
||||
return featureElement;
|
||||
}
|
||||
|
||||
QDomElement QgsWFSServer::createBoxGML2( QgsRectangle* box, QDomDocument& doc ) /*const*/
|
||||
{
|
||||
if ( !box )
|
||||
{
|
||||
return QDomElement();
|
||||
}
|
||||
|
||||
QDomElement boxElem = doc.createElement( "gml:Box" );
|
||||
QVector<QgsPoint> v;
|
||||
QgsPoint p1;
|
||||
p1.set( box->xMinimum(), box->yMinimum() );
|
||||
v.append( p1 );
|
||||
QgsPoint p2;
|
||||
p2.set( box->xMaximum(), box->yMaximum() );
|
||||
v.append( p2 );
|
||||
QDomElement coordElem = createCoordinateGML2( v, doc );
|
||||
boxElem.appendChild( coordElem );
|
||||
|
||||
return boxElem;
|
||||
}
|
||||
|
||||
QDomElement QgsWFSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/
|
||||
{
|
||||
//gml:FeatureMember
|
||||
@ -1757,12 +1736,12 @@ QDomElement QgsWFSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc
|
||||
QgsGeometry* geom = feat->geometry();
|
||||
|
||||
QDomElement geomElem = doc.createElement( "qgs:geometry" );
|
||||
QDomElement gmlElem = QgsOgcUtils::geometryToGML3( geom, doc );
|
||||
QDomElement gmlElem = QgsOgcUtils::geometryToGML( geom, doc, "GML3" );
|
||||
if ( !gmlElem.isNull() )
|
||||
{
|
||||
QgsRectangle box = geom->boundingBox();
|
||||
QDomElement bbElem = doc.createElement( "gml:boundedBy" );
|
||||
QDomElement boxElem = createEnvelopeGML3( &box, doc );
|
||||
QDomElement boxElem = QgsOgcUtils::rectangleToGMLEnvelope( &box, doc );
|
||||
|
||||
if ( crs.isValid() )
|
||||
{
|
||||
@ -1799,55 +1778,3 @@ QDomElement QgsWFSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc
|
||||
return featureElement;
|
||||
}
|
||||
|
||||
QDomElement QgsWFSServer::createCoordinateGML2( const QVector<QgsPoint> points, QDomDocument& doc ) const
|
||||
{
|
||||
QDomElement coordElem = doc.createElement( "gml:coordinates" );
|
||||
coordElem.setAttribute( "cs", "," );
|
||||
coordElem.setAttribute( "ts", " " );
|
||||
|
||||
QString coordString;
|
||||
QVector<QgsPoint>::const_iterator pointIt = points.constBegin();
|
||||
for ( ; pointIt != points.constEnd(); ++pointIt )
|
||||
{
|
||||
if ( pointIt != points.constBegin() )
|
||||
{
|
||||
coordString += " ";
|
||||
}
|
||||
coordString += QString::number( pointIt->x(), 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
|
||||
coordString += ",";
|
||||
coordString += QString::number( pointIt->y(), 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
|
||||
}
|
||||
|
||||
QDomText coordText = doc.createTextNode( coordString );
|
||||
coordElem.appendChild( coordText );
|
||||
return coordElem;
|
||||
}
|
||||
|
||||
QDomElement QgsWFSServer::createEnvelopeGML3( QgsRectangle* env, QDomDocument& doc ) /*const*/
|
||||
{
|
||||
if ( !env )
|
||||
{
|
||||
return QDomElement();
|
||||
}
|
||||
|
||||
QDomElement envElem = doc.createElement( "gml:Envelope" );
|
||||
QString posList;
|
||||
|
||||
QDomElement lowerCornerElem = doc.createElement( "gml:lowerCorner" );
|
||||
posList = QString::number( env->xMinimum(), 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
|
||||
posList += " ";
|
||||
posList = QString::number( env->yMinimum(), 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
|
||||
QDomText lowerCornerText = doc.createTextNode( posList );
|
||||
lowerCornerElem.appendChild( lowerCornerText );
|
||||
envElem.appendChild( lowerCornerElem );
|
||||
|
||||
QDomElement upperCornerElem = doc.createElement( "gml:upperCorner" );
|
||||
posList = QString::number( env->xMaximum(), 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
|
||||
posList += " ";
|
||||
posList = QString::number( env->yMaximum(), 'f', 8 ).remove( QRegExp( "[0]{1,7}$" ) );
|
||||
QDomText upperCornerText = doc.createTextNode( posList );
|
||||
upperCornerElem.appendChild( upperCornerText );
|
||||
envElem.appendChild( upperCornerElem );
|
||||
|
||||
return envElem;
|
||||
}
|
||||
|
@ -107,18 +107,9 @@ class QgsWFSServer
|
||||
|
||||
//methods to write GML2
|
||||
QDomElement createFeatureGML2( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/;
|
||||
|
||||
QDomElement createBoxGML2( QgsRectangle* box, QDomDocument& doc ) /* const */;
|
||||
|
||||
/**Create a GML coordinate string from a point list.
|
||||
@param points list of data points
|
||||
@param coordString out: GML coord string
|
||||
@return 0 in case of success*/
|
||||
QDomElement createCoordinateGML2( const QVector<QgsPoint> points, QDomDocument& doc ) const;
|
||||
|
||||
|
||||
//methods to write GML3
|
||||
QDomElement createFeatureGML3( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QgsFields fields, QSet<QString> excludedAttributes ) /*const*/;
|
||||
QDomElement createEnvelopeGML3( QgsRectangle* env, QDomDocument& doc ) /* const */;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -420,7 +420,7 @@ bool QgsWFSProvider::addFeatures( QgsFeatureList &flist )
|
||||
|
||||
//add geometry column (as gml)
|
||||
QDomElement geomElem = transactionDoc.createElementNS( mWfsNamespace, mGeometryAttribute );
|
||||
QDomElement gmlElem = QgsOgcUtils::geometryToGML2( featureIt->geometry(), transactionDoc );
|
||||
QDomElement gmlElem = QgsOgcUtils::geometryToGML( featureIt->geometry(), transactionDoc );
|
||||
if ( !gmlElem.isNull() )
|
||||
{
|
||||
geomElem.appendChild( gmlElem );
|
||||
@ -571,7 +571,7 @@ bool QgsWFSProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
|
||||
nameElem.appendChild( nameText );
|
||||
propertyElem.appendChild( nameElem );
|
||||
QDomElement valueElem = transactionDoc.createElementNS( "http://www.opengis.net/wfs", "Value" );
|
||||
QDomElement gmlElem = QgsOgcUtils::geometryToGML2( &geomIt.value(), transactionDoc );
|
||||
QDomElement gmlElem = QgsOgcUtils::geometryToGML( &geomIt.value(), transactionDoc );
|
||||
valueElem.appendChild( gmlElem );
|
||||
propertyElem.appendChild( valueElem );
|
||||
updateElem.appendChild( propertyElem );
|
||||
@ -1289,7 +1289,7 @@ int QgsWFSProvider::getFeaturesFromGML2( const QDomElement& wfsCollectionElement
|
||||
}
|
||||
else //a geometry attribute
|
||||
{
|
||||
f->setGeometry( QgsOgcUtils::geometryFromGML2( currentAttributeElement ) );
|
||||
f->setGeometry( QgsOgcUtils::geometryFromGML( currentAttributeElement ) );
|
||||
}
|
||||
}
|
||||
currentAttributeChild = currentAttributeChild.nextSibling();
|
||||
|
@ -36,21 +36,23 @@ class TestQgsOgcUtils : public QObject
|
||||
|
||||
void TestQgsOgcUtils::testGeometryFromGML()
|
||||
{
|
||||
QgsGeometry* geom = QgsOgcUtils::geometryFromGML2( "<Point><coordinates>123,456</coordinates></Point>" );
|
||||
// Test GML2
|
||||
QgsGeometry* geom = QgsOgcUtils::geometryFromGML( "<Point><coordinates>123,456</coordinates></Point>" );
|
||||
QVERIFY( geom );
|
||||
QVERIFY( geom->wkbType() == QGis::WKBPoint );
|
||||
QVERIFY( geom->asPoint() == QgsPoint( 123, 456 ) );
|
||||
|
||||
QgsGeometry* geomBox = QgsOgcUtils::geometryFromGML2( "<gml:Box srsName=\"foo\"><gml:coordinates>135.2239,34.4879 135.8578,34.8471</gml:coordinates></gml:Box>" );
|
||||
QgsGeometry* geomBox = QgsOgcUtils::geometryFromGML( "<gml:Box srsName=\"foo\"><gml:coordinates>135.2239,34.4879 135.8578,34.8471</gml:coordinates></gml:Box>" );
|
||||
QVERIFY( geomBox );
|
||||
QVERIFY( geomBox->wkbType() == QGis::WKBPolygon );
|
||||
|
||||
geom = QgsOgcUtils::geometryFromGML3( "<Point><pos>123 456</pos></Point>" );
|
||||
// Test GML3
|
||||
geom = QgsOgcUtils::geometryFromGML( "<Point><pos>123 456</pos></Point>" );
|
||||
QVERIFY( geom );
|
||||
QVERIFY( geom->wkbType() == QGis::WKBPoint );
|
||||
QVERIFY( geom->asPoint() == QgsPoint( 123, 456 ) );
|
||||
|
||||
geomBox = QgsOgcUtils::geometryFromGML3( "<gml:Envelope srsName=\"foo\"><gml:lowerCorner>135.2239 34.4879</gml:lowerCorner><gml:upperCorner>135.8578 34.8471</gml:upperCorner></gml:Envelope>" );
|
||||
geomBox = QgsOgcUtils::geometryFromGML( "<gml:Envelope srsName=\"foo\"><gml:lowerCorner>135.2239 34.4879</gml:lowerCorner><gml:upperCorner>135.8578 34.8471</gml:upperCorner></gml:Envelope>" );
|
||||
QVERIFY( geomBox );
|
||||
QVERIFY( geomBox->wkbType() == QGis::WKBPolygon );
|
||||
|
||||
@ -61,29 +63,47 @@ void TestQgsOgcUtils::testGeometryFromGML()
|
||||
void TestQgsOgcUtils::testGeometryToGML()
|
||||
{
|
||||
QDomDocument doc;
|
||||
QgsGeometry* geomPoint = QgsGeometry::fromPoint( QgsPoint( 111, 222 ) );
|
||||
QgsGeometry* geomLine = QgsGeometry::fromWkt( "LINESTRING(111 222, 222 222)" );
|
||||
|
||||
QDomElement elemInvalid = QgsOgcUtils::geometryToGML2( 0, doc );
|
||||
// Test GML2
|
||||
QDomElement elemInvalid = QgsOgcUtils::geometryToGML( 0, doc );
|
||||
QVERIFY( elemInvalid.isNull() );
|
||||
|
||||
QgsGeometry* geomPoint = QgsGeometry::fromPoint( QgsPoint( 111, 222 ) );
|
||||
QDomElement elemPoint = QgsOgcUtils::geometryToGML2( geomPoint, doc );
|
||||
QDomElement elemPoint = QgsOgcUtils::geometryToGML( geomPoint, doc );
|
||||
QVERIFY( !elemPoint.isNull() );
|
||||
|
||||
doc.appendChild( elemPoint );
|
||||
QCOMPARE( doc.toString( -1 ), QString( "<gml:Point><gml:coordinates cs=\",\" ts=\" \">111.0,222.0</gml:coordinates></gml:Point>" ) );
|
||||
doc.removeChild( elemPoint );
|
||||
|
||||
elemInvalid = QgsOgcUtils::geometryToGML3( 0, doc );
|
||||
QDomElement elemLine = QgsOgcUtils::geometryToGML( geomLine, doc );
|
||||
QVERIFY( !elemLine.isNull() );
|
||||
|
||||
doc.appendChild( elemLine );
|
||||
QCOMPARE( doc.toString( -1 ), QString( "<gml:LineString><gml:coordinates cs=\",\" ts=\" \">111.0,222.0 222.0,222.0</gml:coordinates></gml:LineString>" ) );
|
||||
doc.removeChild( elemLine );
|
||||
|
||||
// Test GML3
|
||||
elemInvalid = QgsOgcUtils::geometryToGML( 0, doc, "GML3" );
|
||||
QVERIFY( elemInvalid.isNull() );
|
||||
|
||||
elemPoint = QgsOgcUtils::geometryToGML3( geomPoint, doc );
|
||||
elemPoint = QgsOgcUtils::geometryToGML( geomPoint, doc, "GML3" );
|
||||
QVERIFY( !elemPoint.isNull() );
|
||||
|
||||
doc.appendChild( elemPoint );
|
||||
QCOMPARE( doc.toString( -1 ), QString( "<gml:Point><gml:pos srsDimension=\"2\">111.0 222.0</gml:pos></gml:Point>" ) );
|
||||
doc.removeChild( elemPoint );
|
||||
|
||||
elemLine = QgsOgcUtils::geometryToGML( geomLine, doc, "GML3" );
|
||||
QVERIFY( !elemLine.isNull() );
|
||||
|
||||
doc.appendChild( elemLine );
|
||||
QCOMPARE( doc.toString( -1 ), QString( "<gml:LineString><gml:posList srsDimension=\"2\">111.0 222.0 222.0 222.0</gml:posList></gml:LineString>" ) );
|
||||
doc.removeChild( elemLine );
|
||||
|
||||
delete geomPoint;
|
||||
delete geomLine;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user