[Qgis-developer] QgsMapLayerRegistry (and QgsMapCanvas) problem

Carson Farmer carson.farmer at gmail.com
Fri Oct 17 10:39:15 EDT 2008


Hello gang,

According to the API, QgsMapLayerRegistry.instance().mapLayers() should 
return (in the case of python) a dict with the following format:
{ layer0 : QgsMapLayer, layer1: QgsMapLayer }
However, what I appear to be getting is slightly different. Instead of 
QgsMapLayers, I get QgsVectorLayers and QgsRasterLayers. This also 
occurs when trying to get a QgsMapLayer from the map canvas. Is this 
intended, and if so then this creates a problem:

QgsMapLayer.type() returns (as of 9490-ish) either VectorLayer (0) or 
RasterLayer (1) [ QgsMapLayer.LayerType ]
QgsVectorLayer,type() returns either Point (0), Line (1), Polygon (2), 
or UnknownGeometry (3) [ QGis.geometryType ]
QgsRasterLayer.type() returns (as far as I can tell) the same as 
QgsMapLayer.type(), so: RasterLayer (1)

So the problem is this:
If we are trying to check what type of layers we have in our 
QgsMapLayerRegistry, if it's a raster, we will be told that it's a 
raster by returning QgsMapLayer.RasterLayer (or 1), however, if it's a 
vector, then we will get QgsVectorLayer.type() instead of 
QgsMapLayer.type().

I see three solutions to this problem:
a) I'm doing this all wrong, and hopefully someone will tell me this,
b) My favoured solution: Since QgsVectorLayer inherits QgsMapLayer, 
QgsVectorLayer.type() should be changed to QgsVectorLayer.vectorType()
c) All of these enumerators should return something other than numbers?

Clear as mud?

Thanks,

Carson

-- 
Carson J.Q. Farmer
PhD Fellow
National Centre for Geocomputation (NCG),
John Hume Building,
National University of Ireland, Maynooth,
Co. Kildare,
Ireland.
http://www.carsonfarmer.com
http://www.ftools.ca



More information about the Qgis-developer mailing list