[Qgis-developer] What's the difference between provider.geometryType() and layer.geometryType()

Alexander Bruy alexander.bruy at gmail.com
Sun Oct 20 01:15:49 PDT 2013


If we start to talk about inconsistencies I also want to propose
to use same approach for retrieving selected features as we use
for all features — iterator.

Now getFeatures() method returns iterator, while selectedFeatures()
returns a list. It will be good to have same approach for both method.
This can be done as introducing new method (or updating existing) for
getting selected features or, alternatively, by introducing special flag to
existing getFeaures() method.


2013/10/19 Matthias Kuhn <matthias.kuhn at gmx.ch>:
> Hi,
>
> Currently we have:
>
> QgsVectorLayer:
>  * geometryType() returns QGIS geometry type (coarse)
>  * wkbType() returns WKB type (fine)
>
> QgsVectorDataProvider:
>  * geometryType() returns WKB type (fine)
>
> Unfortunate indeed.
>
> To not break existing code, a new method geomType() could be
> introduced, which returns the QGIS geometry type and the method
> wkbType() could be implemented for the dataprovider as well. The
> current methods could be deprecated, but left for a transition period
> (IMO, there is no need to force people to change working code too fast)
>
> Apart from this, a couple of other methods could also be called the
> same in data provider, vector layer and fields.
>
> QgsVectorLayer
>  * int fieldNameIndex( fieldName )
>  * QgsFields pendingFields()
>
> QgsDataProvider
>  * int fieldNameIndex( fieldName )
>  * QgsFields fields()
>  * QMap<QString, int> fieldNameMap()
>
> QgsFields
>  * int indexFromName( name )
>  * QgsField field( name )
>
> I would even argue, that QgsVectorLayer should have a common interface
> (base class) with QgsVectorDataProvider. A lot of code could perfectly
> be run against any of the two, and with such an interface, this could
> be done. Just like we don't care if we are working with an iterator
> from a vector layer or a data provider.
>
> Regards,
> Matthias
>
> On Sam 19 Okt 2013 17:33:09 CEST, Martin Dobias wrote:
>> Hi Anita
>>
>> looking into the code... the unintuitive part is that these
>> geometryType() methods return values from different enumerations:
>> - provider's geometryType() returns value from WKBType enumeration
>> - layer's geometryType() returns value from GeometryType enumeration
>> (translated from provider's geometryType())
>>
>> GeometryType has just coarse differentiation (Point, Line, Polygon,
>> UnknownGeometry, NoGeometry), while WKBType is more fine grained
>> (WKBPoint, WKBPoint2D, WKBMultiPoint, ...)
>>
>> I totally agree that it is confusing... they should be at least called
>> differently (e.g. geometryWkbType vs geometryType).
>>
>> Regards
>> Martin
>>
>>
>> On Sat, Oct 19, 2013 at 9:46 PM, Anita Graser <anitagraser at gmx.at> wrote:
>>> Hi Victor,
>>>
>>> I've been porting one of my scripts to the new Processing. Everything seems
>>> fine but I'm confused about one issue:
>>> It seems like almost everything can be accessed via the layer now, e.g.
>>> crs(), pendingFields(), etc. However, if I try to use layer.geometryType()
>>> in the VectorWriter constructor, I get an error. It only works if I do:
>>>
>>> writer = VectorWriter(output, None, fields, provider.geometryType(),
>>> layer.crs() )
>>>
>>> What's the reason for this unintuitive behavior?
>>>
>>> Thanks and best wishes,
>>> Anita
>>> _______________________________________________
>>> Qgis-developer mailing list
>>> Qgis-developer at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>> _______________________________________________
>> Qgis-developer mailing list
>> Qgis-developer at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer



-- 
Alexander Bruy


More information about the Qgis-developer mailing list