Beispiel #1
0
 def test_SagaVectorAlgorithmWithSelection(self):
     layer = processing.getObject(polygons2());
     feature = layer.getFeatures().next()
     selected = [feature.id()]
     layer.setSelectedFeatures(selected)
     outputs=processing.runalg("saga:polygoncentroids",polygons2(),True,None)
     layer.setSelectedFeatures([])
     output=outputs['CENTROIDS']
     layer=dataobjects.getObjectFromUri(output, True)
     fields=layer.pendingFields()
     expectednames=['ID','POLY_NUM_B','POLY_ST_B']
     expectedtypes=['Real','Real','String']
     names=[str(f.name()) for f in fields]
     types=[str(f.typeName()) for f in fields]
     self.assertEqual(expectednames, names)
     self.assertEqual(expectedtypes, types)
     features=processing.features(layer)
     self.assertEqual(1, len(features))
     feature=features.next()
     attrs=feature.attributes()
     expectedvalues=["2","1","string a"]
     values=[str(attr) for attr in attrs]
     self.assertEqual(expectedvalues, values)
     wkt='POINT(270806.69221918 4458924.97720492)'
     self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
Beispiel #2
0
 def test_SagaVectorAlgorithmWithSelection(self):
     layer = processing.getObject(polygons2())
     feature = layer.getFeatures().next()
     selected = [feature.id()]
     layer.setSelectedFeatures(selected)
     outputs = processing.runalg('saga:polygoncentroids', polygons2(),
                                 True, None)
     layer.setSelectedFeatures([])
     output = outputs['CENTROIDS']
     layer = dataobjects.getObjectFromUri(output, True)
     fields = layer.pendingFields()
     expectednames = ['ID', 'POLY_NUM_B', 'POLY_ST_B']
     expectedtypes = ['Real', 'Real', 'String']
     names = [unicode(f.name()) for f in fields]
     types = [unicode(f.typeName()) for f in fields]
     self.assertEqual(expectednames, names)
     self.assertEqual(expectedtypes, types)
     features = processing.features(layer)
     self.assertEqual(1, len(features))
     feature = features.next()
     attrs = feature.attributes()
     expectedvalues = ['2', '1', 'string a']
     values = [unicode(attr) for attr in attrs]
     self.assertEqual(expectedvalues, values)
     wkt = 'POINT(270806.69221918 4458924.97720492)'
     self.assertEqual(wkt, unicode(feature.geometry().exportToWkt()))