2010-03-10 01:11:11 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from PyQt4.QtCore import *
|
2009-02-01 15:44:02 +00:00
|
|
|
from PyQt4.QtGui import *
|
2010-03-10 01:11:11 +00:00
|
|
|
import ftools_utils
|
2009-02-01 15:44:02 +00:00
|
|
|
from qgis.core import *
|
2009-08-16 22:40:48 +00:00
|
|
|
from ui_frmPointsInPolygon import Ui_Dialog
|
2009-02-01 15:44:02 +00:00
|
|
|
|
2009-01-20 22:54:27 +00:00
|
|
|
class Dialog(QDialog, Ui_Dialog):
|
|
|
|
|
2010-03-10 01:11:11 +00:00
|
|
|
def __init__(self, iface):
|
|
|
|
QDialog.__init__(self)
|
|
|
|
self.iface = iface
|
|
|
|
# Set up the user interface from Designer.
|
|
|
|
self.setupUi(self)
|
2010-05-13 22:55:59 +00:00
|
|
|
self.buttonOk = self.buttonBox_2.button( QDialogButtonBox.Ok )
|
2009-01-20 22:54:27 +00:00
|
|
|
|
2010-03-10 01:11:11 +00:00
|
|
|
# populate layer list
|
|
|
|
self.progressBar.setValue(0)
|
|
|
|
mapCanvas = self.iface.mapCanvas()
|
|
|
|
layers = ftools_utils.getLayerNames([QGis.Point, QGis.Line, QGis.Polygon])
|
|
|
|
self.inPolygon.addItems(layers)
|
|
|
|
self.inPoint.addItems(layers)
|
|
|
|
self.updateUI()
|
|
|
|
self.cmbModify.addItems([self.tr("creating new selection"), self.tr("adding to current selection"), self.tr("removing from current selection")])
|
2009-01-20 22:54:27 +00:00
|
|
|
|
2010-03-10 01:11:11 +00:00
|
|
|
def updateUI(self):
|
|
|
|
self.label_5.setVisible(False)
|
|
|
|
self.lnField.setVisible(False)
|
|
|
|
self.outShape.setVisible(False)
|
|
|
|
self.toolOut.setVisible(False)
|
|
|
|
self.label_2.setVisible(False)
|
|
|
|
self.setWindowTitle(self.tr("Select by location"))
|
|
|
|
self.label_3.setText(self.tr("Select features in:"))
|
|
|
|
self.label_4.setText(self.tr("that intersect features in:"))
|
|
|
|
self.label_mod = QLabel(self)
|
|
|
|
self.label_mod.setObjectName("label_mod")
|
|
|
|
self.label_mod.setText(self.tr("Modify current selection by:"))
|
|
|
|
self.cmbModify = QComboBox(self)
|
|
|
|
self.cmbModify.setObjectName("cmbModify")
|
|
|
|
self.gridLayout.addWidget(self.label_mod,2,0,1,1)
|
|
|
|
self.gridLayout.addWidget(self.cmbModify,3,0,1,1)
|
|
|
|
self.resize(381, 100)
|
2009-01-20 22:54:27 +00:00
|
|
|
|
2010-03-10 01:11:11 +00:00
|
|
|
def accept(self):
|
2010-05-13 22:55:59 +00:00
|
|
|
self.buttonOk.setEnabled( False )
|
2010-03-10 01:11:11 +00:00
|
|
|
if self.inPolygon.currentText() == "":
|
|
|
|
QMessageBox.information(self, self.tr("Select by location"), self.tr( "Please specify input layer"))
|
|
|
|
elif self.inPoint.currentText() == "":
|
|
|
|
QMessageBox.information(self, self.tr("Select by location"), self.tr("Please specify select layer"))
|
|
|
|
else:
|
|
|
|
inPoly = self.inPolygon.currentText()
|
|
|
|
inPts = self.inPoint.currentText()
|
|
|
|
self.compute(inPoly, inPts, self.cmbModify.currentText())
|
|
|
|
self.progressBar.setValue(0)
|
2010-05-13 22:55:59 +00:00
|
|
|
self.buttonOk.setEnabled( True )
|
2010-03-08 19:57:34 +00:00
|
|
|
|
2010-03-10 01:11:11 +00:00
|
|
|
def compute(self, inPoly, inPts, modify):
|
|
|
|
inputLayer = ftools_utils.getVectorLayerByName(inPoly)
|
|
|
|
selectLayer = ftools_utils.getVectorLayerByName(inPts)
|
|
|
|
inputProvider = inputLayer.dataProvider()
|
2010-03-30 22:01:01 +00:00
|
|
|
allAttrs = inputProvider.attributeIndexes()
|
|
|
|
inputProvider.select(allAttrs)
|
2010-03-10 01:11:11 +00:00
|
|
|
selectProvider = selectLayer.dataProvider()
|
2010-03-30 22:01:01 +00:00
|
|
|
allAttrs = selectProvider.attributeIndexes()
|
|
|
|
selectProvider.select(allAttrs)
|
2010-03-10 01:11:11 +00:00
|
|
|
feat = QgsFeature()
|
2010-03-30 22:01:01 +00:00
|
|
|
infeat = QgsFeature()
|
2010-03-10 01:11:11 +00:00
|
|
|
geom = QgsGeometry()
|
|
|
|
selectedSet = []
|
2010-03-30 22:01:01 +00:00
|
|
|
index = ftools_utils.createIndex(inputProvider)
|
|
|
|
#selectProvider.nextFeature(feat)
|
|
|
|
#geomLayer = QgsGeometry(feat.geometry())
|
|
|
|
self.progressBar.setMaximum(selectProvider.featureCount())
|
|
|
|
|
2010-03-10 01:11:11 +00:00
|
|
|
while selectProvider.nextFeature(feat):
|
|
|
|
geom = QgsGeometry(feat.geometry())
|
2010-03-30 22:01:01 +00:00
|
|
|
intersects = index.intersects(geom.boundingBox())
|
|
|
|
for id in intersects:
|
|
|
|
inputProvider.featureAtId(int(id), infeat, True)
|
|
|
|
tmpGeom = QgsGeometry( infeat.geometry() )
|
|
|
|
if geom.intersects(tmpGeom):
|
|
|
|
selectedSet.append(infeat.id())
|
|
|
|
self.progressBar.setValue(self.progressBar.value()+1)
|
2010-03-10 01:11:11 +00:00
|
|
|
if modify == self.tr("adding to current selection"):
|
|
|
|
selectedSet = list(set(inputLayer.selectedFeaturesIds()).union(selectedSet))
|
|
|
|
elif modify == self.tr("removing from current selection"):
|
|
|
|
selectedSet = list(set(inputLayer.selectedFeaturesIds()).difference(selectedSet))
|
|
|
|
inputLayer.setSelectedFeatures(selectedSet)
|