2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
|
2010-12-27 21:27:01 +00:00
|
|
|
// key = field index, value = field value
|
|
|
|
typedef QMap<int, QVariant> QgsAttributeMap;
|
|
|
|
|
2012-10-19 00:31:03 +02:00
|
|
|
typedef QVector<QVariant> QgsAttributes;
|
|
|
|
|
2010-12-27 21:27:01 +00:00
|
|
|
// key = feature id, value = changed attributes
|
2011-06-16 02:24:26 +02:00
|
|
|
typedef QMap<qint64, QMap<int, QVariant> > QgsChangedAttributesMap;
|
2010-12-27 21:27:01 +00:00
|
|
|
|
|
|
|
// key = feature id, value = changed geometry
|
2011-06-16 02:24:26 +02:00
|
|
|
typedef QMap<qint64, QgsGeometry> QgsGeometryMap;
|
2010-12-27 21:27:01 +00:00
|
|
|
|
|
|
|
// 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;
|
2010-12-27 21:27:01 +00:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
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
|
2007-01-09 02:39:15 +00:00
|
|
|
%End
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
public:
|
|
|
|
|
2010-02-04 21:08:33 +00:00
|
|
|
SIP_PYOBJECT __getitem__(int key);
|
|
|
|
%MethodCode
|
2012-10-19 00:31:03 +02:00
|
|
|
const QgsAttributes& attrs = sipCpp->attributes();
|
|
|
|
if (a0 < 0 || a0 >= attrs.count())
|
2010-02-04 21:08:33 +00:00
|
|
|
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
|
|
|
|
else
|
|
|
|
{
|
2012-10-19 00:31:03 +02:00
|
|
|
QVariant* v = new QVariant(attrs[a0]);
|
2010-02-04 21:08:33 +00:00
|
|
|
sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
|
|
|
|
}
|
|
|
|
%End
|
|
|
|
|
2012-05-13 00:53:50 +02:00
|
|
|
SIP_PYOBJECT __getitem__(const QString& name);
|
|
|
|
%MethodCode
|
|
|
|
int fieldIdx = sipCpp->fieldNameIndex(*a0);
|
|
|
|
if (fieldIdx == -1)
|
|
|
|
PyErr_SetString(PyExc_KeyError, a0->toAscii());
|
|
|
|
else
|
|
|
|
{
|
2012-10-19 00:31:03 +02:00
|
|
|
QVariant* v = new QVariant( sipCpp->attribute(fieldIdx) );
|
2012-05-13 00:53:50 +02:00
|
|
|
sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
|
|
|
|
}
|
|
|
|
%End
|
|
|
|
|
2010-02-04 21:08:33 +00:00
|
|
|
void __setitem__(int key, QVariant value);
|
|
|
|
%MethodCode
|
2012-10-19 00:31:03 +02:00
|
|
|
sipCpp->setAttribute(a0, *a1);
|
2010-02-04 21:08:33 +00:00
|
|
|
%End
|
|
|
|
|
2012-05-13 00:53:50 +02:00
|
|
|
void __setitem__(const QString& key, QVariant value);
|
|
|
|
%MethodCode
|
|
|
|
int fieldIdx = sipCpp->fieldNameIndex(*a0);
|
|
|
|
if (fieldIdx == -1)
|
|
|
|
PyErr_SetString(PyExc_KeyError, a0->toAscii());
|
|
|
|
else
|
|
|
|
{
|
2012-10-19 00:31:03 +02:00
|
|
|
sipCpp->setAttribute(fieldIdx, *a1);
|
2012-05-13 00:53:50 +02:00
|
|
|
}
|
|
|
|
%End
|
|
|
|
|
2010-02-04 21:08:33 +00:00
|
|
|
void __delitem__(int key);
|
|
|
|
%MethodCode
|
2012-10-19 00:31:03 +02:00
|
|
|
if (a0 >= 0 && a0 < sipCpp->attributes().count())
|
2010-02-04 21:08:33 +00:00
|
|
|
sipCpp->deleteAttribute(a0);
|
|
|
|
else
|
|
|
|
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
|
|
|
|
%End
|
|
|
|
|
2012-05-13 00:53:50 +02:00
|
|
|
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
|
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
//! Constructor
|
2012-10-13 13:06:57 +02:00
|
|
|
QgsFeature( qint64 id = 0 );
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/** copy ctor needed due to internal pointer */
|
2012-09-24 02:28:15 +02:00
|
|
|
QgsFeature( const QgsFeature & rhs );
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
//! Destructor
|
|
|
|
~QgsFeature();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the feature id for this feature
|
|
|
|
* @return Feature id
|
|
|
|
*/
|
2011-06-16 02:24:26 +02:00
|
|
|
qint64 id() const;
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the feature id for this feature
|
|
|
|
* @param id Feature id
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void setFeatureId( qint64 id );
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2012-10-19 00:31:03 +02:00
|
|
|
const QgsAttributes& attributes() const;
|
|
|
|
//QgsAttributes& attributes();
|
|
|
|
void setAttributes(const QgsAttributes& attrs);
|
|
|
|
void setAttribute( int field, const QVariant& attr );
|
|
|
|
void initAttributes( int fieldCount );
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**Deletes an attribute and its value*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void deleteAttribute( int field );
|
2007-01-09 02:39:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
/**
|
2007-01-09 02:39:15 +00:00
|
|
|
* Set the validity of the feature.
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void setValid( bool validity );
|
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
/**
|
|
|
|
* Get the geometry object associated with this feature
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
QgsGeometry *geometry();
|
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
/**
|
|
|
|
* Get the geometry object associated with this feature
|
|
|
|
* The caller assumes responsibility for the QgsGeometry*'s destruction.
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
QgsGeometry *geometryAndOwnership() /Factory/;
|
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
/** Set this feature's geometry from another QgsGeometry object (deep copy)
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void setGeometry( const QgsGeometry& geom );
|
|
|
|
|
2007-04-11 11:46:35 +00:00
|
|
|
/** Set this feature's geometry (takes geometry ownership)
|
2012-09-24 02:28:15 +02:00
|
|
|
* @note not available in python bindings
|
2007-04-11 11:46:35 +00:00
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
// void setGeometry( QgsGeometry* geom /Transfer/ );
|
|
|
|
|
|
|
|
/**
|
2007-01-09 02:39:15 +00:00
|
|
|
* Set this feature's geometry from WKB
|
|
|
|
*
|
|
|
|
* This feature assumes responsibility for destroying geom.
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void setGeometryAndOwnership( unsigned char * geom /Transfer/, size_t length );
|
|
|
|
|
2012-05-13 00:53:50 +02:00
|
|
|
/** Assign a field map with the feature to allow attribute access by attribute name
|
|
|
|
* @note added in 2.0
|
|
|
|
*/
|
2012-10-20 22:19:55 +02:00
|
|
|
void setFields( const QgsFields* fields );
|
2012-05-13 00:53:50 +02:00
|
|
|
|
|
|
|
/** Get associated field map. may be NULL
|
|
|
|
* @note added in 2.0
|
|
|
|
*/
|
2012-10-20 22:19:55 +02:00
|
|
|
const QgsFields* fields() const;
|
2012-05-13 00:53:50 +02:00
|
|
|
|
|
|
|
/** 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
|
|
|
|
*/
|
2012-10-19 00:31:03 +02:00
|
|
|
bool setAttribute( const QString& name, QVariant value );
|
2012-05-13 00:53:50 +02:00
|
|
|
|
|
|
|
/** 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;
|
|
|
|
|
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
}; // class QgsFeature
|
|
|
|
|