Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

i am developing a qgis plugin, while i can get the the general type of layer i.e vector or raster using this code

    vectorCount =0
pointCount=0
lineCount=0
polugonCount=0
rasterCount=0
layers = self.iface.legendInterface().layers()
for layer in layers:
    if layer.type() == QgsMapLayer.VectorLayer:
        QMessageBox.information( self.iface.mainWindow(),"Info", "count %i"%(vectorCount) )
        vectorCount=vectorCount+1
    if layer.geometryType() == Qgis.Point:
        QMessageBox.information( self.iface.mainWindow(),"Info", "count %i"%(pointCount) )
        pointCount=pointCount+1
self.iface.mapCanvas().refresh()

how i can get more specific vector layer type such as point polygon line ?

share|improve this question
    
What is your question? –  Nathan W Jun 13 '13 at 11:44
    
how i can get more specific vector layer type such as point polygon line ? basically i want to develop a plug in that will automatically arrange the layers in proper order: at base polygon then line then point. i am also wondering to use their extent or area of extent. –  Abhijit Gujar Jun 13 '13 at 11:49
add comment

2 Answers 2

up vote 2 down vote accepted
if layer.geometryType() == Qgis.Point:
        print "I'm a point layer"

http://www.qgis.org/api/classQgsVectorLayer.html#a0c6711ef5b047f27f99c4463d5390e59

share|improve this answer
    
if layer.geometryType() == qgis.point NameError: global name 'qgis' is not defined –  Abhijit Gujar Jun 13 '13 at 12:06
1  
@Nathan W said - if layer.geometryType() == Qgis.Point: print "I'm a point layer" you need a capital Q on the Qgis qualifier in the statement, I think. Your's appears to be if layer.geometryType() == qgis.point (nb qgis instead of Qgis) –  Mark Jun 13 '13 at 12:15
    
Not working vectorCount =0 pointCount=0 lineCount=0 polugonCount=0 rasterCount=0 layers = self.iface.legendInterface().layers() for layer in layers: if layer.type() == QgsMapLayer.VectorLayer: QMessageBox.information( self.iface.mainWindow(),"Info", "count %i"%(vectorCount) ) vectorCount=vectorCount+1 if layer.geometryType() == Qgis.Point: QMessageBox.information( self.iface.mainWindow(),"Info", "count %i"%(pointCount) ) pointCount=pointCount+1 self.iface.mapCanvas().refresh() –  Abhijit Gujar Jun 14 '13 at 5:43
    
i tried self.iface, Qgis.GeometryType.Point tried almost all the thing ... –  Abhijit Gujar Jun 14 '13 at 5:46
    
What is the error? –  Nathan W Jun 14 '13 at 5:50
add comment

Thanks nathan w and mark your answers gave me direction. actually 'G' in Qgis.Point:has to be capital , this is how got it to run:

    vectorCount =0
pointCount=0
lineCount=0
polygonCount=0
rasterCount=0
layers = self.iface.legendInterface().layers()
for layer in layers:
    if layer.type() == QgsMapLayer.VectorLayer:
        vectorCount=vectorCount+1
    if layer.geometryType() == QGis.Point:
        pointCount=pointCount+1
    if layer.geometryType() == QGis.Line:
        lineCount=lineCount+1
    if layer.geometryType() == QGis.Polygon:
        polygonCount=polygonCount+1 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.