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

Matthias Kuhn matthias.kuhn at gmx.ch
Sat Oct 19 11:09:31 PDT 2013


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




More information about the Qgis-developer mailing list