Exemplo n.º 1
0
    def processAlgorithm(self, progress):
        layer = dataobjects.getObjectFromUri(
            self.getParameterValue(self.INPUT))
        fieldName = self.getParameterValue(self.FIELD)
        directory = self.getOutputValue(self.OUTPUT)

        mkdir(directory)

        fieldIndex = layer.fieldNameIndex(fieldName)
        uniqueValues = vector.uniqueValues(layer, fieldIndex)
        baseName = os.path.join(directory, '{0}_{1}'.format(layer.name(), fieldName))

        fields = layer.pendingFields()
        crs = layer.crs()
        geomType = layer.wkbType()

        total = 100.0 / len(uniqueValues)

        for current, i in enumerate(uniqueValues):
            fName = u'{0}_{1}.shp'.format(baseName, unicode(i).strip())

            writer = vector.VectorWriter(fName, None, fields, geomType, crs)
            for f in vector.features(layer):
                if f[fieldName] == i:
                    writer.addFeature(f)
            del writer

            progress.setPercentage(int(current * total))
Exemplo n.º 2
0
if allFieldsA:
    fieldListA = layerA.fields()
else:
    fieldListA = QgsFields()
    fieldListA.append(layerA.fields()[idxA])

if allFieldsB:
    fieldListB = layerB.fields()
else:
    fieldListB = QgsFields()
    fieldListB.append(layerB.fields()[idxB])

fieldListB = vector.testForUniqueness(fieldListA, fieldListB)
fieldListA.extend(fieldListB)

writer = vector.VectorWriter(Intersections, None, fieldListA, QGis.WKBPoint,
                             layerA.dataProvider().crs())

spatialIndex = vector.spatialindex(layerB)

outFeat = QgsFeature()
features = vector.features(layerA)
total = 100.0 / len(features)
hasIntersections = False

for current, inFeatA in enumerate(features):
    inGeom = inFeatA.geometry()
    hasIntersections = False
    lines = spatialIndex.intersects(inGeom.boundingBox())

    if len(lines) > 0:
        hasIntersections = True