mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
QgsFeature and QgsGeometry serialization
This commit is contained in:
parent
e633cafc34
commit
6e3cbe3a3d
@ -252,3 +252,32 @@ int QgsFeature::fieldNameIndex( const QString& fieldName ) const
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
QDataStream& operator<<( QDataStream& out, const QgsFeature& feature )
|
||||
{
|
||||
out << feature.id();
|
||||
out << feature.attributes();
|
||||
if ( feature.geometry() )
|
||||
{
|
||||
out << *( feature.geometry() );
|
||||
}
|
||||
else
|
||||
{
|
||||
QgsGeometry geometry;
|
||||
out << geometry;
|
||||
}
|
||||
out << feature.isValid();
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream& operator>>( QDataStream& in, QgsFeature& feature )
|
||||
{
|
||||
QgsFeatureId id;
|
||||
QgsGeometry* geometry = new QgsGeometry();
|
||||
bool valid;
|
||||
in >> id >> feature.attributes() >> *geometry >> valid;
|
||||
feature.setFeatureId( id );
|
||||
feature.setGeometry( geometry );
|
||||
feature.setValid( valid );
|
||||
return in;
|
||||
}
|
||||
|
@ -64,6 +64,11 @@ class QgsFeatureId
|
||||
friend uint qHash( const QgsFeatureId &id );
|
||||
};
|
||||
|
||||
/** Writes the feature id to stream out. QGIS version compatibility is not guaranteed. */
|
||||
CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsFeatureId& featureId );
|
||||
/** Reads a feature id from stream in into feature id. QGIS version compatibility is not guaranteed. */
|
||||
CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsFeatureId& featureId );
|
||||
|
||||
inline uint qHash( const QgsFeatureId &id )
|
||||
{
|
||||
return qHash( id.mId );
|
||||
@ -313,6 +318,11 @@ class CORE_EXPORT QgsFeature
|
||||
|
||||
}; // class QgsFeature
|
||||
|
||||
/** Writes the feature to stream out. QGIS version compatibility is not guaranteed. */
|
||||
CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsFeature& feature );
|
||||
/** Reads a feature from stream in into feature. QGIS version compatibility is not guaranteed. */
|
||||
CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsFeature& feature );
|
||||
|
||||
// key = feature id, value = changed attributes
|
||||
typedef QMap<QgsFeatureId, QgsAttributeMap> QgsChangedAttributesMap;
|
||||
|
||||
|
@ -6781,3 +6781,20 @@ bool QgsGeometry::compare( const QgsMultiPolygon &p1, const QgsMultiPolygon &p2,
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QDataStream& operator<<( QDataStream& out, const QgsGeometry& geometry )
|
||||
{
|
||||
QByteArray byteArray = QByteArray::fromRawData(( char * )geometry.asWkb(), geometry.wkbSize() ); // does not copy data and does not take ownership
|
||||
out << byteArray;
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream& operator>>( QDataStream& in, QgsGeometry& geometry )
|
||||
{
|
||||
QByteArray byteArray;
|
||||
in >> byteArray;
|
||||
char *data = new char[byteArray.size()];
|
||||
memcpy( data, byteArray.data(), byteArray.size() );
|
||||
geometry.fromWkb(( unsigned char* )data, byteArray.size() );
|
||||
return in;
|
||||
}
|
||||
|
@ -721,6 +721,11 @@ class CORE_EXPORT QgsGeometry
|
||||
|
||||
Q_DECLARE_METATYPE( QgsGeometry );
|
||||
|
||||
/** Writes the geometry to stream out. QGIS version compatibility is not guaranteed. */
|
||||
CORE_EXPORT QDataStream& operator<<( QDataStream& out, const QgsGeometry& geometry );
|
||||
/** Reads a geometry from stream in into geometry. QGIS version compatibility is not guaranteed. */
|
||||
CORE_EXPORT QDataStream& operator>>( QDataStream& in, QgsGeometry& geometry );
|
||||
|
||||
class CORE_EXPORT QgsWkbPtr
|
||||
{
|
||||
mutable unsigned char *mP;
|
||||
|
Loading…
x
Reference in New Issue
Block a user