QGIS/python/core/qgsfeature.sip

195 lines
5.3 KiB
Plaintext
Raw Normal View History

// key = field index, value = field value
typedef QMap<int, QVariant> QgsAttributeMap;
typedef QVector<QVariant> QgsAttributes;
// key = feature id, value = changed attributes
2011-06-16 02:24:26 +02:00
typedef QMap<qint64, QMap<int, QVariant> > QgsChangedAttributesMap;
// key = feature id, value = changed geometry
2011-06-16 02:24:26 +02:00
typedef QMap<qint64, QgsGeometry> QgsGeometryMap;
// key = field index, value = field name
typedef QMap<int, QString> QgsFieldNameMap;
typedef QList<QgsFeature> QgsFeatureList;
2012-10-09 20:57:35 +02:00
typedef QMap<int, QgsField> QgsFieldMap;
class QgsFeature
{
%TypeHeaderCode
#include <qgsfeature.h>
2012-01-08 19:04:52 +01:00
#if (SIP_VERSION >= 0x040900 && SIP_VERSION < 0x040c01)
#define sipClass_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant))
#endif
%End
public:
SIP_PYOBJECT __getitem__(int key);
%MethodCode
const QgsAttributes& attrs = sipCpp->attributes();
if (a0 < 0 || a0 >= attrs.count())
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
else
{
QVariant* v = new QVariant(attrs[a0]);
sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
}
%End
SIP_PYOBJECT __getitem__(const QString& name);
%MethodCode
int fieldIdx = sipCpp->fieldNameIndex(*a0);
if (fieldIdx == -1)
PyErr_SetString(PyExc_KeyError, a0->toAscii());
else
{
QVariant* v = new QVariant( sipCpp->attribute(fieldIdx) );
sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
}
%End
void __setitem__(int key, QVariant value);
%MethodCode
sipCpp->setAttribute(a0, *a1);
%End
void __setitem__(const QString& key, QVariant value);
%MethodCode
int fieldIdx = sipCpp->fieldNameIndex(*a0);
if (fieldIdx == -1)
PyErr_SetString(PyExc_KeyError, a0->toAscii());
else
{
sipCpp->setAttribute(fieldIdx, *a1);
}
%End
void __delitem__(int key);
%MethodCode
if (a0 >= 0 && a0 < sipCpp->attributes().count())
sipCpp->deleteAttribute(a0);
else
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
%End
void __delitem__(const QString& name);
%MethodCode
int fieldIdx = sipCpp->fieldNameIndex(*a0);
if (fieldIdx == -1)
PyErr_SetString(PyExc_KeyError, a0->toAscii());
else
sipCpp->deleteAttribute(fieldIdx);
%End
//! Constructor
QgsFeature( qint64 id = 0 );
/** copy ctor needed due to internal pointer */
QgsFeature( const QgsFeature & rhs );
//! Destructor
~QgsFeature();
/**
* Get the feature id for this feature
* @return Feature id
*/
2011-06-16 02:24:26 +02:00
qint64 id() const;
/**
* Set the feature id for this feature
* @param id Feature id
*/
void setFeatureId( qint64 id );
const QgsAttributes& attributes() const;
//QgsAttributes& attributes();
void setAttributes(const QgsAttributes& attrs);
void setAttribute( int field, const QVariant& attr );
void initAttributes( int fieldCount );
/**Deletes an attribute and its value*/
void deleteAttribute( int field );
/**
* Return the validity of this feature. This is normally set by
* the provider to indicate some problem that makes the feature
* invalid or to indicate a null feature.
*/
bool isValid() const;
/**
* Set the validity of the feature.
*/
void setValid( bool validity );
/**
* Get the geometry object associated with this feature
*/
QgsGeometry *geometry();
/**
* Get the geometry object associated with this feature
* The caller assumes responsibility for the QgsGeometry*'s destruction.
*/
QgsGeometry *geometryAndOwnership() /Factory/;
/** Set this feature's geometry from another QgsGeometry object (deep copy)
*/
void setGeometry( const QgsGeometry& geom );
/** Set this feature's geometry (takes geometry ownership)
* @note not available in python bindings
*/
// void setGeometry( QgsGeometry* geom /Transfer/ );
/**
* Set this feature's geometry from WKB
*
* This feature assumes responsibility for destroying geom.
*/
void setGeometryAndOwnership( unsigned char * geom /Transfer/, size_t length );
/** Assign a field map with the feature to allow attribute access by attribute name
* @note added in 2.0
*/
void setFields( const QgsFields* fields );
/** Get associated field map. may be NULL
* @note added in 2.0
*/
const QgsFields* fields() const;
/** Insert a value into attribute. Returns false if attribute name could not be converted to index.
* Field map must be associated to make this work.
* @note added in 2.0
*/
bool setAttribute( const QString& name, QVariant value );
/** Remove an attribute value. Returns false if attribute name could not be converted to index.
* Field map must be associated to make this work.
* @note added in 2.0
*/
bool deleteAttribute( const QString& name );
/** Lookup attribute value from attribute name. Returns invalid variant if attribute name could not be converted to index.
* Field map must be associated to make this work.
* @note added in 2.0
*/
QVariant attribute( const QString& name ) const;
/** Utility method to get attribute index from name. Returns -1 if field does not exist or field map is not associated.
* Field map must be associated to make this work.
* @note added in 2.0
*/
int fieldNameIndex( const QString& fieldName ) const;
}; // class QgsFeature