How to avoid QGSV2 objects

المشرف العام

Administrator
طاقم الإدارة
In my plugin i get V2-objects.for example i will getqgis._core.QgsPolygoneV2 object at 0x16156800for following operation. Does it depends on my loaded packages?

poly = QgsGeometry.fromPolygon([ [ QgsPoint(1,3), QgsPoint(4,3), QgsPoint(4,1), QgsPoint(3,1), QgsPoint(3,2), QgsPoint(2,2), QgsPoint(2,1), QgsPoint(1,1), QgsPoint(1,3) ] ])My Plugin:

from qgis.gui import QgsMapToolfrom qgis.core import QgsMapLayer,QgsPoint,QgsMapToPixel,QgsRectangle, QgsFeature, QgsFeatureRequest, QgsGeometry, QgsSpatialIndex,QgsMapLayerRegistry,QgsVectorLayer from PyQt4.QtGui import QCursor, QPixmapfrom PyQt4.QtCore import Qt, QVariantfrom qgis.utils import ifaceimport itertoolsclass NearestFeatureMapTool(QgsMapTool):def __init__(self, canvas): super(QgsMapTool, self).__init__(canvas) self.canvas = canvas self.cursor = QCursor(Qt.CrossCursor)def activate(self): self.canvas.setCursor(self.cursor)def canvasReleaseEvent(self, mouseEvent): layerData = [] #resultl = QgsVectorLayer("Polygon", "result", "memory") #resultpr = resultl.dataProvider() listmixt = [] listline =[] polywithpoint=QgsFeature() index = QgsSpatialIndex() polyline=QgsFeature() for layer in self.canvas.layers(): if layer.type() != QgsMapLayer.VectorLayer: # Ignore this layer as it's not a vector continue if layer.featureCount() == 0: # There are no features - skip continue layer.removeSelection() # Determine the location of the click in real-world coords layerPoint = self.toLayerCoordinates( layer, mouseEvent.pos() ) feature_dict = {feature.id(): feature for (feature) in layer.getFeatures()} map(index.insertFeature,feature_dict.values()) #define rectangles displayrectangle = self.canvas.extent() #print displayrectangle.toString() ownrectangle = QgsRectangle(layerPoint.x(),layerPoint.y(),layerPoint.x()+200,layerPoint.y()+200) #print ownrectangle.toString() if displayrectangle.contains(ownrectangle): userectangle = ownrectangle else: userectangle = displayrectangle # Auswahl der Features innerhalb des Rechteckes for i in index.intersects(userectangle): print feature_dict.attributes() #listmixt.append(feature_dict) if feature_dict.geometry().contains(QgsGeometry.fromPoint(layerPoint)): polywithpoint = feature_dict else: listmixt.append(feature_dict) #print listmixt[10].geometry() g = polywithpoint for i in listmixt: if i.geometry().type()==1: print polywithpoint.geometry().intersection(i.geometry()).geometry()

أكثر...
 
أعلى