Graphics Reference
In-Depth Information
painter.drawLine(coord1.x(), coord1.y(),
coord2.x(), coord2.y())
We can then do the same for the horizontal grid lines:
for y in range(yMin, yMax+1):
coord1 = mapToPixel.transform(xMin, y)
coord2 = mapToPixel.transform(xMax, y)
painter.drawLine(coord1.x(), coord1.y(),
coord2.x(), coord2.y())
The last thing we need to do is tell QGIS that our layer was drawn successfully. We do
this by having our draw() method return True :
return True
This completes our implementation of the GridLayer class. If you want to use this class
within a QGIS script or plugin, you will need to register the class so that QGIS knows
about it. Fortunately, doing this is straightforward:
class GridLayerType(QgsPluginLayerType):
def __init__(self):
QgsPluginLayerType.__init__(self, "GridLayer")
def createLayer(self):
return GridLayer()
registry = QgsPluginLayerRegistry.instance()
registry.addPluginLayerType(GridLayerType())
If you run this program within QGIS and add the GridLayer to your project, you'll see
the grid lines drawn on the map:
Search WWH ::




Custom Search