Graphics Reference
In-Depth Information
This is very similar to the ExploreTool we implemented in the previous chapter as
part of the Lex application. The only difference is that, instead of displaying information
about the clicked-on feature, we tell the map layer to select it.
Note that we check to see if the Shift key is held down. If so, the clicked-on feature is ad-
ded to the current selection; otherwise, the current selection will be replaced with the
newly selected feature. Also, if the user clicks on the background of the map, the current
selection will be removed. These are all standard user interface conventions the user will
be familiar with.
Once we have a selection, it is quite straightforward to get the selected features from the
map layer. For example:
if layer.selectedFeatureCount() == 0:
QMessageBox.information(self, "Info",
"There is nothing selected.")
else:
msg = []
msg.append("Selected Features:")
for feature in layer.selectedFeatures():
msg.append(" " + feature.attribute("NAME"))
QMessageBox.information(self, "Info", "\n".join(msg))
If you want to see all this in action, you can download and run the SelectionExplorer pro-
gram, which is included in the sample code of this chapter.
Search WWH ::




Custom Search