2007-01-09 02:39:15 +00:00
|
|
|
|
2013-01-28 01:39:58 +01:00
|
|
|
typedef qint64 QgsFeatureId;
|
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;
|
2013-06-10 13:29:27 +02:00
|
|
|
// QgsAttributes is implemented as a Python list of Python objects.
|
|
|
|
%MappedType QgsAttributes /DocType="list-of-attributes"/
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qvector.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
%ConvertFromTypeCode
|
|
|
|
// Create the list.
|
|
|
|
PyObject *l;
|
|
|
|
|
2013-08-28 12:09:11 +02:00
|
|
|
if ( ( l = PyList_New(sipCpp->size() ) ) == NULL )
|
2013-06-10 13:29:27 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// Set the list elements.
|
2013-08-28 12:09:11 +02:00
|
|
|
for ( int i = 0; i < sipCpp->size(); ++i )
|
2013-06-10 13:29:27 +02:00
|
|
|
{
|
2013-08-28 12:09:11 +02:00
|
|
|
QVariant* v = new QVariant( sipCpp->at( i ) );
|
2013-06-10 13:29:27 +02:00
|
|
|
PyObject *tobj;
|
|
|
|
|
2013-08-28 12:09:11 +02:00
|
|
|
if ( ( tobj = sipConvertFromNewType( v, sipType_QVariant,Py_None ) ) == NULL )
|
2013-06-10 13:29:27 +02:00
|
|
|
{
|
2013-08-28 12:09:11 +02:00
|
|
|
Py_DECREF( l );
|
2013-06-15 11:37:34 +02:00
|
|
|
delete v;
|
2013-08-28 12:09:11 +02:00
|
|
|
|
2013-06-10 13:29:27 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-28 12:09:11 +02:00
|
|
|
PyList_SET_ITEM( l, i, tobj );
|
2013-06-10 13:29:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return l;
|
|
|
|
%End
|
|
|
|
|
|
|
|
%ConvertToTypeCode
|
|
|
|
// Check the type if that is all that is required.
|
|
|
|
if (sipIsErr == NULL)
|
|
|
|
{
|
|
|
|
if (!PyList_Check(sipPy))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (SIP_SSIZE_T i = 0; i < PyList_GET_SIZE(sipPy); ++i)
|
|
|
|
if (!sipCanConvertToType(PyList_GET_ITEM(sipPy, i), sipType_QVariant, SIP_NOT_NONE))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVector<QVariant> *qv = new QVector<QVariant>;
|
|
|
|
|
|
|
|
for (SIP_SSIZE_T i = 0; i < PyList_GET_SIZE(sipPy); ++i)
|
|
|
|
{
|
|
|
|
int state;
|
|
|
|
PyObject* obj = PyList_GET_ITEM(sipPy, i);
|
|
|
|
QVariant *t;
|
|
|
|
if ( obj == Py_None )
|
|
|
|
{
|
|
|
|
t = new QVariant( QVariant::Int );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
t = reinterpret_cast<QVariant *>(sipConvertToType(obj, sipType_QVariant, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
|
|
|
|
|
|
|
|
if (*sipIsErr)
|
|
|
|
{
|
|
|
|
sipReleaseType(t, sipType_QVariant, state);
|
|
|
|
|
|
|
|
delete qv;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qv->append(*t);
|
|
|
|
|
|
|
|
sipReleaseType(t, sipType_QVariant, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
*sipCppPtr = qv;
|
|
|
|
|
|
|
|
return sipGetState(sipTransferObj);
|
|
|
|
%End
|
|
|
|
};
|
2012-10-19 00:31:03 +02:00
|
|
|
|
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
|
|
|
|
2014-01-26 18:35:21 +01:00
|
|
|
/** \ingroup core
|
|
|
|
* The feature class encapsulates a single feature including its id,
|
|
|
|
* geometry and a list of field/values attributes.
|
|
|
|
*
|
|
|
|
* @author Gary E.Sherman
|
|
|
|
*/
|
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:
|
|
|
|
|
2013-08-03 22:42:13 +10:00
|
|
|
SIP_PYOBJECT __iter__();
|
|
|
|
%MethodCode
|
|
|
|
PyObject *attrs = sipConvertFromType( &sipCpp->attributes(), sipType_QgsAttributes, Py_None );
|
|
|
|
sipRes = PyObject_GetIter(attrs);
|
|
|
|
%End
|
|
|
|
|
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())
|
2013-06-10 13:29:27 +02:00
|
|
|
{
|
2010-02-04 21:08:33 +00:00
|
|
|
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
|
2013-06-10 13:29:27 +02:00
|
|
|
sipIsErr = 1;
|
|
|
|
}
|
2010-02-04 21:08:33 +00:00
|
|
|
else
|
|
|
|
{
|
2013-08-28 12:09:11 +02:00
|
|
|
QVariant* v = new QVariant( attrs.at(a0) );
|
|
|
|
sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
|
2010-02-04 21:08:33 +00:00
|
|
|
}
|
|
|
|
%End
|
|
|
|
|
2012-05-13 00:53:50 +02:00
|
|
|
SIP_PYOBJECT __getitem__(const QString& name);
|
|
|
|
%MethodCode
|
|
|
|
int fieldIdx = sipCpp->fieldNameIndex(*a0);
|
|
|
|
if (fieldIdx == -1)
|
2013-06-10 13:29:27 +02:00
|
|
|
{
|
2012-05-13 00:53:50 +02:00
|
|
|
PyErr_SetString(PyExc_KeyError, a0->toAscii());
|
2013-06-10 13:29:27 +02:00
|
|
|
sipIsErr = 1;
|
|
|
|
}
|
2012-05-13 00:53:50 +02:00
|
|
|
else
|
|
|
|
{
|
2013-08-28 12:09:11 +02:00
|
|
|
QVariant* v = new QVariant( sipCpp->attribute(fieldIdx) );
|
|
|
|
sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
|
2012-05-13 00:53:50 +02:00
|
|
|
}
|
|
|
|
%End
|
|
|
|
|
2013-06-10 13:29:27 +02:00
|
|
|
void __setitem__(int key, QVariant value /GetWrapper/);
|
2010-02-04 21:08:33 +00:00
|
|
|
%MethodCode
|
2013-06-10 13:29:27 +02:00
|
|
|
bool rv;
|
|
|
|
|
|
|
|
if ( a1Wrapper == Py_None )
|
|
|
|
{
|
|
|
|
rv = sipCpp->setAttribute(a0, QVariant( QVariant::Int ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rv = sipCpp->setAttribute(a0, *a1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !rv )
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
|
|
|
|
sipIsErr = 1;
|
|
|
|
}
|
2010-02-04 21:08:33 +00:00
|
|
|
%End
|
|
|
|
|
2013-06-10 13:29:27 +02:00
|
|
|
void __setitem__(const QString& key, QVariant value /GetWrapper/);
|
2012-05-13 00:53:50 +02:00
|
|
|
%MethodCode
|
|
|
|
int fieldIdx = sipCpp->fieldNameIndex(*a0);
|
|
|
|
if (fieldIdx == -1)
|
2013-06-10 13:29:27 +02:00
|
|
|
{
|
2012-05-13 00:53:50 +02:00
|
|
|
PyErr_SetString(PyExc_KeyError, a0->toAscii());
|
2013-06-10 13:29:27 +02:00
|
|
|
sipIsErr = 1;
|
|
|
|
}
|
2012-05-13 00:53:50 +02:00
|
|
|
else
|
|
|
|
{
|
2013-06-10 13:29:27 +02:00
|
|
|
if ( a1Wrapper == Py_None )
|
|
|
|
{
|
2013-06-12 08:09:57 +10:00
|
|
|
sipCpp->setAttribute(*a0, QVariant( QVariant::Int ) );
|
2013-06-10 13:29:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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
|
2013-06-10 13:29:27 +02:00
|
|
|
{
|
2010-02-04 21:08:33 +00:00
|
|
|
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
|
2013-06-10 13:29:27 +02:00
|
|
|
sipIsErr = 1;
|
|
|
|
}
|
2010-02-04 21:08:33 +00:00
|
|
|
%End
|
|
|
|
|
2012-05-13 00:53:50 +02:00
|
|
|
void __delitem__(const QString& name);
|
|
|
|
%MethodCode
|
|
|
|
int fieldIdx = sipCpp->fieldNameIndex(*a0);
|
|
|
|
if (fieldIdx == -1)
|
2013-06-10 13:29:27 +02:00
|
|
|
{
|
2012-05-13 00:53:50 +02:00
|
|
|
PyErr_SetString(PyExc_KeyError, a0->toAscii());
|
2013-06-10 13:29:27 +02:00
|
|
|
sipIsErr = 1;
|
|
|
|
}
|
2012-05-13 00:53:50 +02:00
|
|
|
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
|
|
|
|
2013-03-30 12:51:55 +10:00
|
|
|
QgsFeature( const QgsFields& fields, 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();
|
2014-11-21 01:17:21 +01:00
|
|
|
void setAttributes( const QgsAttributes& attrs );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set an attribute by id
|
|
|
|
*
|
|
|
|
* @param field The index of the field to set
|
|
|
|
* @param attr The value of the attribute
|
|
|
|
*
|
|
|
|
* @return false, if the field id does not exist
|
|
|
|
*
|
|
|
|
* @note For Python: raises a KeyError exception instead of returning false
|
|
|
|
*/
|
2013-06-10 13:29:27 +02:00
|
|
|
bool setAttribute( int field, const QVariant& attr /GetWrapper/);
|
|
|
|
%MethodCode
|
|
|
|
bool rv;
|
|
|
|
|
|
|
|
if ( a1Wrapper == Py_None )
|
|
|
|
{
|
|
|
|
rv = sipCpp->setAttribute(a0, QVariant( QVariant::Int ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rv = sipCpp->setAttribute(a0, *a1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !rv )
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
|
|
|
|
sipIsErr = 1;
|
|
|
|
}
|
|
|
|
%End
|
|
|
|
|
2014-01-26 18:35:21 +01:00
|
|
|
/**
|
|
|
|
* Initialize this feature with the given number of fields. Discard any previously set attribute data.
|
|
|
|
* @param fieldCount Number of fields to initialize
|
|
|
|
*/
|
2012-10-19 00:31:03 +02:00
|
|
|
void initAttributes( int fieldCount );
|
2007-01-09 02:39:15 +00:00
|
|
|
|
2014-01-26 18:35:21 +01:00
|
|
|
/**
|
|
|
|
* Deletes an attribute and its value
|
|
|
|
*
|
|
|
|
* @param field The index of the field
|
|
|
|
*
|
|
|
|
* @note For Python: raises a KeyError exception if the field is not found
|
|
|
|
*/
|
2012-09-24 02:28:15 +02:00
|
|
|
void deleteAttribute( int field );
|
2013-06-10 13:29:27 +02:00
|
|
|
%MethodCode
|
|
|
|
if ( a0 >= 0 && a0 < sipCpp->attributes().count() )
|
|
|
|
sipCpp->deleteAttribute(a0);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
|
|
|
|
sipIsErr = 1;
|
|
|
|
}
|
|
|
|
%End
|
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
|
|
|
|
*/
|
2015-05-11 19:46:32 +10:00
|
|
|
QgsGeometry* geometry() const;
|
|
|
|
|
|
|
|
/** Gets a const pointer to the geometry object associated with this feature
|
|
|
|
* @note added in QGIS 2.9
|
|
|
|
*/
|
|
|
|
const QgsGeometry* constGeometry() const;
|
2012-09-24 02:28:15 +02:00
|
|
|
|
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 );
|
|
|
|
|
2014-01-26 18:35:21 +01:00
|
|
|
/** Assign a field map with the feature to allow attribute access by attribute name
|
2013-06-05 11:59:50 +02:00
|
|
|
*
|
2014-01-26 18:35:21 +01:00
|
|
|
* @param fields The attribute fields which this feature holds. When used from python, make sure
|
|
|
|
* a copy of the fields is held by python, as ownership stays there.
|
|
|
|
* I.e. Do not call feature.setFields( myDataProvider.fields() ) but instead call
|
|
|
|
* myFields = myDataProvider.fields()
|
|
|
|
* feature.setFields( myFields )
|
|
|
|
* @param initAttributes If true, attributes are initialized. Clears any data previously assigned.
|
2013-06-05 11:59:50 +02:00
|
|
|
* C++: Defaults to false
|
|
|
|
* Python: Defaults to true
|
2014-05-27 23:22:50 +02:00
|
|
|
*
|
|
|
|
* TODO: QGIS3 - take reference, not pointer
|
2012-05-13 00:53:50 +02:00
|
|
|
*/
|
2014-01-28 00:26:03 +01:00
|
|
|
void setFields( const QgsFields* fields, bool initAttributes = true );
|
2012-05-13 00:53:50 +02:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
/** Get associated field map.
|
|
|
|
*
|
|
|
|
* TODO: QGIS 3 - return reference or value, not pointer
|
2012-05-13 00:53:50 +02:00
|
|
|
*/
|
2012-10-20 22:19:55 +02:00
|
|
|
const QgsFields* fields() const;
|
2012-05-13 00:53:50 +02:00
|
|
|
|
2014-01-26 18:35:21 +01:00
|
|
|
/** Insert a value into attribute. Returns false if attribute name could not be converted to index.
|
2012-05-13 00:53:50 +02:00
|
|
|
* Field map must be associated to make this work.
|
2014-01-26 18:35:21 +01:00
|
|
|
*
|
|
|
|
* @param name The name of the field to set
|
|
|
|
* @param value The value to set
|
|
|
|
*
|
|
|
|
* @return false if attribute name could not be converted to index (C++ only)
|
|
|
|
*
|
|
|
|
* @note For Python: raises a KeyError exception instead of returning false
|
2012-05-13 00:53:50 +02:00
|
|
|
*/
|
2013-06-10 13:29:27 +02:00
|
|
|
void setAttribute( const QString& name, QVariant value /GetWrapper/ );
|
|
|
|
%MethodCode
|
|
|
|
int fieldIdx = sipCpp->fieldNameIndex(*a0);
|
|
|
|
if (fieldIdx == -1)
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_KeyError, a0->toAscii());
|
|
|
|
sipIsErr = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( a1Wrapper == Py_None )
|
|
|
|
{
|
2013-06-12 08:09:57 +10:00
|
|
|
sipCpp->setAttribute(*a0, QVariant( QVariant::Int ) );
|
2013-06-10 13:29:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sipCpp->setAttribute(fieldIdx, *a1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
%End
|
|
|
|
/** Remove an attribute value.
|
2014-01-26 18:35:21 +01:00
|
|
|
* Returns false if attribute name could not be converted to index.
|
2012-05-13 00:53:50 +02:00
|
|
|
* Field map must be associated to make this work.
|
2014-01-26 18:35:21 +01:00
|
|
|
*
|
|
|
|
* @param name The name of the field to delete
|
|
|
|
*
|
|
|
|
* @return false if attribute name could not be converted to index (C++ only)
|
|
|
|
*
|
|
|
|
* @note For Python: raises a KeyError exception instead of returning false
|
2012-05-13 00:53:50 +02:00
|
|
|
*/
|
2014-01-26 18:35:21 +01:00
|
|
|
bool deleteAttribute( const QString& name );
|
2013-06-10 13:29:27 +02:00
|
|
|
%MethodCode
|
|
|
|
int fieldIdx = sipCpp->fieldNameIndex(*a0);
|
|
|
|
if (fieldIdx == -1)
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_KeyError, a0->toAscii());
|
|
|
|
sipIsErr = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sipCpp->deleteAttribute( fieldIdx );
|
|
|
|
}
|
|
|
|
%End
|
|
|
|
/** Lookup attribute value from attribute name.
|
2014-01-26 18:35:21 +01:00
|
|
|
* Returns invalid variant if attribute name could not be converted to index (C++ only)
|
2012-05-13 00:53:50 +02:00
|
|
|
* Field map must be associated to make this work.
|
2014-01-26 18:35:21 +01:00
|
|
|
*
|
|
|
|
* @param name The name of the attribute to get
|
|
|
|
*
|
|
|
|
* @return The value of the attribute (C++: Invalid variant if no such name exists )
|
|
|
|
*
|
|
|
|
* @note For Python: raises a KeyError exception if field is not found
|
2012-05-13 00:53:50 +02:00
|
|
|
*/
|
2013-06-10 13:29:27 +02:00
|
|
|
SIP_PYOBJECT attribute( const QString& name ) const;
|
|
|
|
%MethodCode
|
|
|
|
int fieldIdx = sipCpp->fieldNameIndex(*a0);
|
|
|
|
if (fieldIdx == -1)
|
|
|
|
{
|
|
|
|
PyErr_SetString(PyExc_KeyError, a0->toAscii());
|
|
|
|
sipIsErr = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-28 12:09:11 +02:00
|
|
|
QVariant* v = new QVariant( sipCpp->attribute(fieldIdx) );
|
|
|
|
sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
|
2013-06-10 13:29:27 +02:00
|
|
|
}
|
|
|
|
%End
|
2012-05-13 00:53:50 +02:00
|
|
|
/** 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.
|
|
|
|
*/
|
|
|
|
int fieldNameIndex( const QString& fieldName ) const;
|
|
|
|
|
2007-01-09 02:39:15 +00:00
|
|
|
}; // class QgsFeature
|
|
|
|
|
2013-01-28 01:39:58 +01:00
|
|
|
typedef QSet<QgsFeatureId> QgsFeatureIds;
|