Esempio n. 1
0
 def processAlgorithm(self, progress):
     inField = self.getParameterValue(PointsInPolygon.FIELD)
     polyLayer = QGisLayers.getObjectFromUri(
         self.getParameterValue(PointsInPolygon.POLYGONS))
     pointLayer = QGisLayers.getObjectFromUri(
         self.getParameterValue(PointsInPolygon.POINTS))
     polyProvider = polyLayer.dataProvider()
     pointProvider = pointLayer.dataProvider()
     if polyProvider.crs() <> pointProvider.crs():
         SextanteLog.addToLog(
             SextanteLog.LOG_WARNING,
             "CRS warning!Warning: Input layers have non-matching CRS.\nThis may cause unexpected results."
         )
     allAttrs = polyProvider.attributeIndexes()
     polyProvider.select(allAttrs)
     allAttrs = pointProvider.attributeIndexes()
     pointProvider.select(allAttrs)
     fieldList = ftools_utils.getFieldList(polyLayer)
     index = polyProvider.fieldNameIndex(unicode(inField))
     if index == -1:
         index = polyProvider.fieldCount()
         field = QgsField(unicode(inField), QVariant.Double, "real", 24, 15,
                          "point count field")
         fieldList[index] = field
     sRs = polyProvider.crs()
     writer = self.getOutputFromName(
         PointsInPolygon.OUTPUT).getVectorWriter(
             fieldList, polyProvider.geometryType(), sRs)
     inFeat = QgsFeature()
     inFeatB = QgsFeature()
     outFeat = QgsFeature()
     inGeom = QgsGeometry()
     start = 15.00
     add = 85.00 / polyProvider.featureCount()
     spatialIndex = ftools_utils.createIndex(pointProvider)
     while polyProvider.nextFeature(inFeat):
         inGeom = inFeat.geometry()
         atMap = inFeat.attributeMap()
         outFeat.setAttributeMap(atMap)
         outFeat.setGeometry(inGeom)
         pointList = []
         count = 0
         #(check, pointList) = pointLayer.featuresInRectangle(inGeom.boundingBox(), True, True)
         #pointLayer.select(inGeom.boundingBox(), False)
         #pointList = pointLayer.selectedFeatures()
         pointList = spatialIndex.intersects(inGeom.boundingBox())
         if len(pointList) > 0: check = 0
         else: check = 1
         if check == 0:
             for i in pointList:
                 pointProvider.featureAtId(int(i), inFeatB, True, allAttrs)
                 tmpGeom = QgsGeometry(inFeatB.geometry())
                 if inGeom.contains(tmpGeom):
                     count = count + 1
         outFeat.setAttributeMap(atMap)
         outFeat.addAttribute(index, QVariant(count))
         writer.addFeature(outFeat)
         start = start + add
         progress.setPercentage(start)
     del writer
Esempio n. 2
0
 def processAlgorithm(self, progress):
     inField = self.getParameterValue(SumLines.FIELD)
     lineLayer = QGisLayers.getObjectFromUri(self.getParameterValue(SumLines.LINES))
     polyLayer = QGisLayers.getObjectFromUri(self.getParameterValue(SumLines.POLYGONS))
     polyProvider = polyLayer.dataProvider()
     lineProvider = lineLayer.dataProvider()
     if polyProvider.crs() <> lineProvider.crs():
         SextanteLog.addToLog(SextanteLog.LOG_WARNING,
                              "CRS warning!Warning: Input layers have non-matching CRS.\nThis may cause unexpected results.")
     allAttrs = polyProvider.attributeIndexes()
     polyProvider.select(allAttrs)
     allAttrs = lineProvider.attributeIndexes()
     lineProvider.select(allAttrs)
     fieldList = ftools_utils.getFieldList(polyLayer)
     index = polyProvider.fieldNameIndex(unicode(inField))
     if index == -1:
         index = polyProvider.fieldCount()
         field = QgsField(unicode(inField), QVariant.Double, "real", 24, 15, self.tr("length field"))
         fieldList[index] = field
     sRs = polyProvider.crs()
     inFeat = QgsFeature()
     inFeatB = QgsFeature()
     outFeat = QgsFeature()
     inGeom = QgsGeometry()
     outGeom = QgsGeometry()
     distArea = QgsDistanceArea()
     lineProvider.rewind()
     start = 15.00
     add = 85.00 / polyProvider.featureCount()
     writer = self.getOutputFromName(SumLines.OUTPUT).getVectorWriter(fieldList, polyProvider.geometryType(), sRs)
     spatialIndex = ftools_utils.createIndex( lineProvider )
     while polyProvider.nextFeature(inFeat):
         inGeom = QgsGeometry(inFeat.geometry())
         atMap = inFeat.attributeMap()
         lineList = []
         length = 0
         #(check, lineList) = lineLayer.featuresInRectangle(inGeom.boundingBox(), True, False)
         #lineLayer.select(inGeom.boundingBox(), False)
         #lineList = lineLayer.selectedFeatures()
         lineList = spatialIndex.intersects(inGeom.boundingBox())
         if len(lineList) > 0: check = 0
         else: check = 1
         if check == 0:
             for i in lineList:
                 lineProvider.featureAtId( int( i ), inFeatB , True, allAttrs )
                 tmpGeom = QgsGeometry( inFeatB.geometry() )
                 if inGeom.intersects(tmpGeom):
                     outGeom = inGeom.intersection(tmpGeom)
                     length = length + distArea.measure(outGeom)
         outFeat.setGeometry(inGeom)
         outFeat.setAttributeMap(atMap)
         outFeat.addAttribute(index, QVariant(length))
         writer.addFeature(outFeat)
         start = start + add
         progress.setPercentage(start)
     del writer
Esempio n. 3
0
 def processAlgorithm(self, progress):
     inField = self.getParameterValue(PointsInPolygon.FIELD)
     polyLayer = QGisLayers.getObjectFromUri(self.getParameterValue(PointsInPolygon.POLYGONS))
     pointLayer = QGisLayers.getObjectFromUri(self.getParameterValue(PointsInPolygon.POINTS))
     polyProvider = polyLayer.dataProvider()
     pointProvider = pointLayer.dataProvider()
     if polyProvider.crs() <> pointProvider.crs():
         SextanteLog.addToLog(SextanteLog.LOG_WARNING,
                              "CRS warning!Warning: Input layers have non-matching CRS.\nThis may cause unexpected results.")
     allAttrs = polyProvider.attributeIndexes()
     polyProvider.select(allAttrs)
     allAttrs = pointProvider.attributeIndexes()
     pointProvider.select(allAttrs)
     fieldList = ftools_utils.getFieldList(polyLayer)
     index = polyProvider.fieldNameIndex(unicode(inField))
     if index == -1:
         index = polyProvider.fieldCount()
         field = QgsField(unicode(inField), QVariant.Double, "real", 24, 15, "point count field")
         fieldList[index] = field
     sRs = polyProvider.crs()
     writer = self.getOutputFromName(PointsInPolygon.OUTPUT).getVectorWriter(fieldList, polyProvider.geometryType(), sRs)
     inFeat = QgsFeature()
     inFeatB = QgsFeature()
     outFeat = QgsFeature()
     inGeom = QgsGeometry()
     start = 15.00
     add = 85.00 / polyProvider.featureCount()
     spatialIndex = ftools_utils.createIndex( pointProvider )
     while polyProvider.nextFeature(inFeat):
         inGeom = inFeat.geometry()
         atMap = inFeat.attributeMap()
         outFeat.setAttributeMap(atMap)
         outFeat.setGeometry(inGeom)
         pointList = []
         count = 0
         #(check, pointList) = pointLayer.featuresInRectangle(inGeom.boundingBox(), True, True)
         #pointLayer.select(inGeom.boundingBox(), False)
         #pointList = pointLayer.selectedFeatures()
         pointList = spatialIndex.intersects(inGeom.boundingBox())
         if len(pointList) > 0: check = 0
         else: check = 1
         if check == 0:
             for i in pointList:
                 pointProvider.featureAtId( int( i ), inFeatB , True, allAttrs )
                 tmpGeom = QgsGeometry( inFeatB.geometry() )
                 if inGeom.contains(tmpGeom):
                     count = count + 1
         outFeat.setAttributeMap(atMap)
         outFeat.addAttribute(index, QVariant(count))
         writer.addFeature(outFeat)
         start = start + add
         progress.setPercentage(start)
     del writer
Esempio n. 4
0
 def processAlgorithm(self, progress):
     method = self.getParameterValue(self.METHOD)
     selection = self.getParameterValue(self.USE_SELECTED)
     filename = self.getParameterValue(SelectByLocation.INPUT)
     inputLayer = QGisLayers.getObjectFromUri(filename)
     filename = self.getParameterValue(SelectByLocation.INTERSECT)
     selectLayer = QGisLayers.getObjectFromUri(filename)
     inputProvider = inputLayer.dataProvider()
     allAttrs = inputProvider.attributeIndexes()
     inputProvider.select(allAttrs, QgsRectangle())
     selectProvider = selectLayer.dataProvider()
     allAttrs = selectProvider.attributeIndexes()
     selectProvider.select(allAttrs, QgsRectangle())
     feat = QgsFeature()
     infeat = QgsFeature()
     geom = QgsGeometry()
     selectedSet = []
     index = ftools_utils.createIndex(inputProvider)
     if selection:
         features = selectLayer.selectedFeatures()
         featurescount = len(features)
         i = 0
         for feat in features:
             geom = QgsGeometry(feat.geometry())
             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())
             i += 1
             progress.setPercentage(i / featurescount * 100)
     else:
         featurescount = selectProvider.featureCount()
         while selectProvider.nextFeature(feat):
             geom = QgsGeometry(feat.geometry())
             intersects = index.intersects(geom.boundingBox())
             i = 0
             for iid in intersects:
                 inputProvider.featureAtId(int(iid), infeat, True)
                 tmpGeom = QgsGeometry(infeat.geometry())
                 if geom.intersects(tmpGeom):
                     selectedSet.append(infeat.id())
             i += 1
             progress.setPercentage(i / featurescount * 100)
     if method == 1:
         selectedSet = list(
             set(inputLayer.selectedFeaturesIds()).union(selectedSet))
     elif method == 2:
         selectedSet = list(
             set(inputLayer.selectedFeaturesIds()).difference(selectedSet))
     inputLayer.setSelectedFeatures(selectedSet)
     self.setOutputValue(self.OUTPUT, filename)
Esempio n. 5
0
 def processAlgorithm(self, progress):
     method = self.getParameterValue(self.METHOD)
     selection = self.getParameterValue(self.USE_SELECTED)
     filename = self.getParameterValue(SelectByLocation.INPUT)
     inputLayer = QGisLayers.getObjectFromUri(filename)
     filename = self.getParameterValue(SelectByLocation.INTERSECT)
     selectLayer = QGisLayers.getObjectFromUri(filename)
     inputProvider = inputLayer.dataProvider()
     allAttrs = inputProvider.attributeIndexes()
     inputProvider.select(allAttrs, QgsRectangle())
     selectProvider = selectLayer.dataProvider()
     allAttrs = selectProvider.attributeIndexes()
     selectProvider.select(allAttrs, QgsRectangle())
     feat = QgsFeature()
     infeat = QgsFeature()
     geom = QgsGeometry()
     selectedSet = []
     index = ftools_utils.createIndex(inputProvider)
     if selection:
         features = selectLayer.selectedFeatures()
         featurescount = len(features)
         i = 0
         for feat in features:
             geom = QgsGeometry(feat.geometry())
             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())
             i += 1
             progress.setPercentage(i/featurescount * 100)
     else:
         featurescount = selectProvider.featureCount()
         while selectProvider.nextFeature(feat):
             geom = QgsGeometry(feat.geometry())
             intersects = index.intersects(geom.boundingBox())
             i = 0
             for iid in intersects:
                 inputProvider.featureAtId(int(iid), infeat, True)
                 tmpGeom = QgsGeometry( infeat.geometry() )
                 if geom.intersects(tmpGeom):
                     selectedSet.append(infeat.id())
             i += 1
             progress.setPercentage(i/featurescount * 100)
     if method == 1:
         selectedSet = list(set(inputLayer.selectedFeaturesIds()).union(selectedSet))
     elif method == 2:
         selectedSet = list(set(inputLayer.selectedFeaturesIds()).difference(selectedSet))
     inputLayer.setSelectedFeatures(selectedSet)
     self.setOutputValue(self.OUTPUT, filename)
Esempio n. 6
0
 def processAlgorithm(self, progress):
     output = self.getOutputValue(NearestNeighbourAnalysis.OUTPUT)
     vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(NearestNeighbourAnalysis.POINTS))
     vprovider = vlayer.dataProvider()
     allAttrs = vprovider.attributeIndexes()
     vprovider.select( allAttrs )
     feat = QgsFeature()
     neighbour = QgsFeature()
     sumDist = 0.00
     distance = QgsDistanceArea()
     A = vlayer.extent()
     A = float( A.width() * A.height() )
     index = ftools_utils.createIndex( vprovider )
     vprovider.rewind()
     nFeat = vprovider.featureCount()
     nElement = 0
     while vprovider.nextFeature( feat ):
       neighbourID = index.nearestNeighbor( feat.geometry().asPoint(), 2 )[ 1 ]
       vprovider.featureAtId( neighbourID, neighbour, True, [] )
       nearDist = distance.measureLine( neighbour.geometry().asPoint(), feat.geometry().asPoint() )
       sumDist += nearDist
       nElement += 1
       progress.setPercentage(int(nElement/nFeat * 100))
     nVal = vprovider.featureCount()
     do = float( sumDist) / nVal
     de = float( 0.5 / math.sqrt( nVal / A ) )
     d = float( do / de )
     SE = float( 0.26136 / math.sqrt( ( nVal * nVal ) / A ) )
     zscore = float( ( do - de ) / SE )
     lstStats = []
     lstStats.append("Observed mean distance:" + unicode( do ) )
     lstStats.append("Expected mean distance:" + unicode( de ) )
     lstStats.append("Nearest neighbour index:" + unicode( d ) )
     lstStats.append("N:" + unicode( nVal ) )
     lstStats.append("Z-Score:"  + unicode( zscore ) )
     self.createHTML(output, lstStats)
Esempio n. 7
0
    def processAlgorithm(self, progress):
        settings = QSettings()
        systemEncoding = settings.value("/UI/encoding", "System").toString()
        output = self.getOutputValue(Clip.OUTPUT)
        useSelection = self.getParameterValue(Clip.USE_SELECTED)
        useSelection2 = self.getParameterValue(Clip.USE_SELECTED2)
        vlayerA = QGisLayers.getObjectFromUri(
            self.getParameterValue(Clip.INPUT))
        vlayerB = QGisLayers.getObjectFromUri(
            self.getParameterValue(Clip.INPUT2))
        GEOS_EXCEPT = True
        FEATURE_EXCEPT = True
        vproviderA = vlayerA.dataProvider()
        allAttrsA = vproviderA.attributeIndexes()
        vproviderA.select(allAttrsA)
        vproviderB = vlayerB.dataProvider()
        allAttrsB = vproviderB.attributeIndexes()
        vproviderB.select(allAttrsB)
        # check for crs compatibility
        crsA = vproviderA.crs()
        crsB = vproviderB.crs()
        if not crsA.isValid() or not crsB.isValid():
            SextanteLog.addToLog(
                SextanteLog.LOG_WARNING,
                "Intersection. Invalid CRS. Results might be unexpected")
        else:
            if not crsA != crsB:
                SextanteLog.addToLog(
                    SextanteLog.LOG_WARNING,
                    "Intersection. Non-matching CRSs. Results might be unexpected"
                )
        fields = vproviderA.fields()
        writer = QgsVectorFileWriter(output, systemEncoding, fields,
                                     vproviderA.geometryType(),
                                     vproviderA.crs())

        inFeatA = QgsFeature()
        inFeatB = QgsFeature()
        outFeat = QgsFeature()
        index = ftools_utils.createIndex(vproviderB)
        vproviderA.rewind()
        nElement = 0
        # there is selection in input layer
        if useSelection:
            nFeat = vlayerA.selectedFeatureCount()
            selectionA = vlayerA.selectedFeatures()
            # we have selection in overlay layer
            if useSelection2:
                selectionB = vlayerB.selectedFeaturesIds()
                for inFeatA in selectionA:
                    nElement += 1
                    progress.setPercentage(int(nElement / nFeat * 100))
                    geom = QgsGeometry(inFeatA.geometry())
                    int_geom = QgsGeometry(geom)
                    atMap = inFeatA.attributeMap()
                    intersects = index.intersects(geom.boundingBox())
                    found = False
                    first = True
                    for id in intersects:
                        if id in selectionB:
                            vproviderB.featureAtId(int(id), inFeatB, True,
                                                   allAttrsB)
                            tmpGeom = QgsGeometry(inFeatB.geometry())
                            if tmpGeom.intersects(geom):
                                found = True
                                if first:
                                    outFeat.setGeometry(QgsGeometry(tmpGeom))
                                    first = False
                                else:
                                    try:
                                        cur_geom = QgsGeometry(
                                            outFeat.geometry())
                                        new_geom = QgsGeometry(
                                            cur_geom.combine(tmpGeom))
                                        outFeat.setGeometry(
                                            QgsGeometry(new_geom))
                                    except:
                                        GEOS_EXCEPT = False
                                        break
                    if found:
                        try:
                            cur_geom = QgsGeometry(outFeat.geometry())
                            new_geom = QgsGeometry(geom.intersection(cur_geom))
                            if new_geom.wkbType() == 7:
                                int_com = QgsGeometry(geom.combine(cur_geom))
                                int_sym = QgsGeometry(
                                    geom.symDifference(cur_geom))
                                new_geom = QgsGeometry(
                                    int_com.difference(int_sym))
                            try:
                                outFeat.setGeometry(new_geom)
                                outFeat.setAttributeMap(atMap)
                                writer.addFeature(outFeat)
                            except:
                                FEAT_EXCEPT = False
                                continue
                        except:
                            GEOS_EXCEPT = False
                            continue
            # we have no selection in overlay layer
            else:
                for inFeatA in selectionA:
                    nElement += 1
                    progress.setPercentage(int(nElement / nFeat * 100))
                    geom = QgsGeometry(inFeatA.geometry())
                    atMap = inFeatA.attributeMap()
                    intersects = index.intersects(geom.boundingBox())
                    found = False
                    first = True
                    for id in intersects:
                        vproviderB.featureAtId(int(id), inFeatB, True,
                                               allAttrsB)
                        tmpGeom = QgsGeometry(inFeatB.geometry())
                        if tmpGeom.intersects(geom):
                            found = True
                            if first:
                                outFeat.setGeometry(QgsGeometry(tmpGeom))
                                first = False
                            else:
                                try:
                                    cur_geom = QgsGeometry(outFeat.geometry())
                                    new_geom = QgsGeometry(
                                        cur_geom.combine(tmpGeom))
                                    outFeat.setGeometry(QgsGeometry(new_geom))
                                except:
                                    GEOS_EXCEPT = False
                                    break
                    if found:
                        try:
                            cur_geom = QgsGeometry(outFeat.geometry())
                            new_geom = QgsGeometry(geom.intersection(cur_geom))
                            if new_geom.wkbType() == 7:
                                int_com = QgsGeometry(geom.combine(cur_geom))
                                int_sym = QgsGeometry(
                                    geom.symDifference(cur_geom))
                                new_geom = QgsGeometry(
                                    int_com.difference(int_sym))
                            try:
                                outFeat.setGeometry(new_geom)
                                outFeat.setAttributeMap(atMap)
                                writer.addFeature(outFeat)
                            except:
                                FEAT_EXCEPT = False
                                continue
                        except:
                            GEOS_EXCEPT = False
                            continue
        # there is no selection in input layer
        else:
            nFeat = vproviderA.featureCount()
            # we have selection in overlay layer
            if useSelection2:
                selectionB = vlayerB.selectedFeaturesIds()
                while vproviderA.nextFeature(inFeatA):
                    nElement += 1
                    progress.setPercentage(int(nElement / nFeat * 100))
                    geom = QgsGeometry(inFeatA.geometry())
                    atMap = inFeatA.attributeMap()
                    intersects = index.intersects(geom.boundingBox())
                    found = False
                    first = True
                    for id in intersects:
                        if id in selectionB:
                            vproviderB.featureAtId(int(id), inFeatB, True,
                                                   allAttrsB)
                            tmpGeom = QgsGeometry(inFeatB.geometry())
                            if tmpGeom.intersects(geom):
                                found = True
                                if first:
                                    outFeat.setGeometry(QgsGeometry(tmpGeom))
                                    first = False
                                else:
                                    try:
                                        cur_geom = QgsGeometry(
                                            outFeat.geometry())
                                        new_geom = QgsGeometry(
                                            cur_geom.combine(tmpGeom))
                                        outFeat.setGeometry(
                                            QgsGeometry(new_geom))
                                    except:
                                        GEOS_EXCEPT = False
                                        break
                    if found:
                        try:
                            cur_geom = QgsGeometry(outFeat.geometry())
                            new_geom = QgsGeometry(geom.intersection(cur_geom))
                            if new_geom.wkbType() == 7:
                                int_com = QgsGeometry(geom.combine(cur_geom))
                                int_sym = QgsGeometry(
                                    geom.symDifference(cur_geom))
                                new_geom = QgsGeometry(
                                    int_com.difference(int_sym))
                            try:
                                outFeat.setGeometry(new_geom)
                                outFeat.setAttributeMap(atMap)
                                writer.addFeature(outFeat)
                            except:
                                FEAT_EXCEPT = False
                                continue
                        except:
                            GEOS_EXCEPT = False
                            continue
            # we have no selection in overlay layer
            else:
                while vproviderA.nextFeature(inFeatA):
                    nElement += 1
                    progress.setPercentage(int(nElement / nFeat * 100))
                    geom = QgsGeometry(inFeatA.geometry())
                    atMap = inFeatA.attributeMap()
                    intersects = index.intersects(geom.boundingBox())
                    first = True
                    found = False
                    if len(intersects) > 0:
                        for id in intersects:
                            vproviderB.featureAtId(int(id), inFeatB, True,
                                                   allAttrsB)
                            tmpGeom = QgsGeometry(inFeatB.geometry())
                            if tmpGeom.intersects(geom):
                                found = True
                                if first:
                                    outFeat.setGeometry(QgsGeometry(tmpGeom))
                                    first = False
                                else:
                                    try:
                                        cur_geom = QgsGeometry(
                                            outFeat.geometry())
                                        new_geom = QgsGeometry(
                                            cur_geom.combine(tmpGeom))
                                        outFeat.setGeometry(
                                            QgsGeometry(new_geom))
                                    except:
                                        GEOS_EXCEPT = False
                                        break
                        if found:
                            try:
                                cur_geom = QgsGeometry(outFeat.geometry())
                                new_geom = QgsGeometry(
                                    geom.intersection(cur_geom))
                                if new_geom.wkbType() == 7:
                                    int_com = QgsGeometry(
                                        geom.combine(cur_geom))
                                    int_sym = QgsGeometry(
                                        geom.symDifference(cur_geom))
                                    new_geom = QgsGeometry(
                                        int_com.difference(int_sym))
                                try:
                                    outFeat.setGeometry(new_geom)
                                    outFeat.setAttributeMap(atMap)
                                    writer.addFeature(outFeat)
                                except:
                                    FEAT_EXCEPT = False
                                    continue
                            except:
                                GEOS_EXCEPT = False
                                continue
        del writer
        if not GEOS_EXCEPT:
            SextanteLog.addToLog(SextanteLog.LOG_WARNING,
                                 "Geometry exception while computing clip")
        if not FEATURE_EXCEPT:
            SextanteLog.addToLog(SextanteLog.LOG_WARNING,
                                 "Feature exception while computing clip")
Esempio n. 8
0
 def processAlgorithm(self, progress):
     useSelection = self.getParameterValue(Intersection.USE_SELECTED)
     useSelection2 = self.getParameterValue(Intersection.USE_SELECTED2)
     vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(Intersection.INPUT))
     vlayerB = QGisLayers.getObjectFromUri(self.getParameterValue(Intersection.INPUT2))
     GEOS_EXCEPT = True
     FEATURE_EXCEPT = True
     vproviderA = vlayerA.dataProvider()
     allAttrsA = vproviderA.attributeIndexes()
     vproviderA.select( allAttrsA )
     vproviderB = vlayerB.dataProvider()
     allAttrsB = vproviderB.attributeIndexes()
     vproviderB.select( allAttrsB )
     # check for crs compatibility
     crsA = vproviderA.crs()
     crsB = vproviderB.crs()
     if not crsA.isValid() or not crsB.isValid():
         SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Intersection. Invalid CRS. Results might be unexpected")
     else:
         if not crsA != crsB:
             SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Intersection. Non-matching CRSs. Results might be unexpected")
     fields = ftools_utils.combineVectorFields(vlayerA, vlayerB)
     longNames = ftools_utils.checkFieldNameLength( fields )
     if not longNames.isEmpty():
         raise GeoAlgorithmExecutionException("Following field names are longer than 10 characters:\n" +  longNames.join('\n') )
     writer = self.getOutputFromName(Intersection.OUTPUT).getVectorWriter(fields, vproviderA.geometryType(), vproviderA.crs() )
     inFeatA = QgsFeature()
     inFeatB = QgsFeature()
     outFeat = QgsFeature()
     index = ftools_utils.createIndex( vproviderB )
     nElement = 0
     # there is selection in input layer
     if useSelection:
       nFeat = vlayerA.selectedFeatureCount()
       selectionA = vlayerA.selectedFeatures()
       # we have selection in overlay layer
       if useSelection2:
         selectionB = vlayerB.selectedFeaturesIds()
         for inFeatA in selectionA:
           nElement += 1
           progress.setPercentage(int(nElement/nFeat * 100))
           geom = QgsGeometry( inFeatA.geometry() )
           atMapA = inFeatA.attributeMap()
           intersects = index.intersects( geom.boundingBox() )
           for id in intersects:
             if id in selectionB:
               vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
               tmpGeom = QgsGeometry( inFeatB.geometry() )
               try:
                 if geom.intersects( tmpGeom ):
                   atMapB = inFeatB.attributeMap()
                   int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
                   if int_geom.wkbType() == 7:
                     int_com = geom.combine( tmpGeom )
                     int_sym = geom.symDifference( tmpGeom )
                     int_geom = QgsGeometry( int_com.difference( int_sym ) )
                   try:
                     outFeat.setGeometry( int_geom )
                     outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
                     writer.addFeature( outFeat )
                   except:
                     FEATURE_EXCEPT = False
                     continue
               except:
                 GEOS_EXCEPT = False
                 break
       # we don't have selection in overlay layer
       else:
         for inFeatA in selectionA:
           nElement += 1
           progress.setPercentage(int(nElement/nFeat * 100))
           geom = QgsGeometry( inFeatA.geometry() )
           atMapA = inFeatA.attributeMap()
           intersects = index.intersects( geom.boundingBox() )
           for id in intersects:
             vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
             tmpGeom = QgsGeometry( inFeatB.geometry() )
             try:
               if geom.intersects( tmpGeom ):
                 atMapB = inFeatB.attributeMap()
                 int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
                 if int_geom.wkbType() == 7:
                   int_com = geom.combine( tmpGeom )
                   int_sym = geom.symDifference( tmpGeom )
                   int_geom = QgsGeometry( int_com.difference( int_sym ) )
                 try:
                   outFeat.setGeometry( int_geom )
                   outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
                   writer.addFeature( outFeat )
                 except:
                   EATURE_EXCEPT = False
                   continue
             except:
               GEOS_EXCEPT = False
               break
     # there is no selection in input layer
     else:
       nFeat = vproviderA.featureCount()
       vproviderA.rewind()
       # we have selection in overlay layer
       if useSelection2:
         selectionB = vlayerB.selectedFeaturesIds()
         while vproviderA.nextFeature( inFeatA ):
           nElement += 1
           progress.setPercentage(int(nElement/nFeat * 100))
           geom = QgsGeometry( inFeatA.geometry() )
           atMapA = inFeatA.attributeMap()
           intersects = index.intersects( geom.boundingBox() )
           for id in intersects:
             if id in selectionB:
               vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
               tmpGeom = QgsGeometry( inFeatB.geometry() )
               try:
                 if geom.intersects( tmpGeom ):
                   atMapB = inFeatB.attributeMap()
                   int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
                   if int_geom.wkbType() == 7:
                     int_com = geom.combine( tmpGeom )
                     int_sym = geom.symDifference( tmpGeom )
                     int_geom = QgsGeometry( int_com.difference( int_sym ) )
                   try:
                     outFeat.setGeometry( int_geom )
                     outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
                     writer.addFeature( outFeat )
                   except:
                     FEATURE_EXCEPT = False
                     continue
               except:
                 GEOS_EXCEPT = False
                 break
       # we have no selection in overlay layer
       else:
         while vproviderA.nextFeature( inFeatA ):
           nElement += 1
           progress.setPercentage(int(nElement/nFeat * 100))
           geom = QgsGeometry( inFeatA.geometry() )
           atMapA = inFeatA.attributeMap()
           intersects = index.intersects( geom.boundingBox() )
           for id in intersects:
             vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
             tmpGeom = QgsGeometry( inFeatB.geometry() )
             try:
               if geom.intersects( tmpGeom ):
                 atMapB = inFeatB.attributeMap()
                 int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
                 if int_geom.wkbType() == 7:
                   int_com = geom.combine( tmpGeom )
                   int_sym = geom.symDifference( tmpGeom )
                   int_geom = QgsGeometry( int_com.difference( int_sym ) )
                 try:
                   outFeat.setGeometry( int_geom )
                   outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
                   writer.addFeature( outFeat )
                 except:
                   FEATURE_EXCEPT = False
                   continue
             except:
               GEOS_EXCEPT = False
               break
     del writer
     if not GEOS_EXCEPT:
         SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Geometry exception while computing intersection")
     if not FEATURE_EXCEPT:
         SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Feature exception while computing interesection")
Esempio n. 9
0
 def processAlgorithm(self, progress):
     layer1 = QGisLayers.getObjectFromUri(self.getParameterValue(LinesIntersection.INPUT1))
     layer2 = QGisLayers.getObjectFromUri(self.getParameterValue(LinesIntersection.INPUT2))
     field1 = self.getParameterValue(LinesIntersection.FIELD1)
     field2 = self.getParameterValue(LinesIntersection.FIELD2)
     provider1 = layer1.dataProvider()
     provider2 = layer2.dataProvider()
     allAttrs = provider1.attributeIndexes()
     provider1.select(allAttrs)
     allAttrs = provider2.attributeIndexes()
     provider2.select(allAttrs)
     fieldList = ftools_utils.getFieldList(layer1)
     index1 = provider1.fieldNameIndex(field1)
     field1 = fieldList[index1]
     field1.setName(unicode(field1.name()) + "_1")
     fieldList = ftools_utils.getFieldList(layer2)
     index2 = provider2.fieldNameIndex(field2)
     field2 = fieldList[index2]
     field2.setName(unicode(field2.name()) + "_2")
     fieldList = {0:field1, 1:field2}
     sRs = provider1.crs()
     writer = self.getOutputFromName(LinesIntersection.OUTPUT).getVectorWriter(fieldList, QGis.WKBPoint, sRs)
     #writer = QgsVectorFileWriter(outPath, "UTF-8", fieldList, QGis.WKBPoint, sRs)
     inFeat = QgsFeature()
     inFeatB = QgsFeature()
     outFeat = QgsFeature()
     inGeom = QgsGeometry()
     tempGeom = QgsGeometry()
     start = 15.00
     add = 85.00 / layer1.featureCount()
     index = ftools_utils.createIndex( provider2 )
     while provider1.nextFeature(inFeat):
         inGeom = inFeat.geometry()
         lineList = []
         #(check, lineList) = layer2.featuresInRectangle(inGeom.boundingBox(), True, True)
         # Below is a work-around for featuresInRectangle
         # Which appears to have been removed for QGIS version 1.0
         #layer2.select(inGeom.boundingBox(), False)
         #lineList = layer2.selectedFeatures()
         lineList = index.intersects( inGeom.boundingBox() )
         if len(lineList) > 0: check = 0
         else: check = 1
         if check == 0:
             for i in lineList:
                 provider2.featureAtId( int( i ), inFeatB , True, allAttrs )
                 tmpGeom = QgsGeometry( inFeatB.geometry() )
                 #tempGeom = i.geometry()
                 tempList = []
                 atMap1 = inFeat.attributeMap()
                 atMap2 = inFeatB.attributeMap()
                 if inGeom.intersects(tmpGeom):
                     tempGeom = inGeom.intersection(tmpGeom)
                     if tempGeom.type() == QGis.Point:
                         if tempGeom.isMultipart():
                             tempList = tempGeom.asMultiPoint()
                         else:
                             tempList.append(tempGeom.asPoint())
                         for j in tempList:
                             outFeat.setGeometry(tempGeom.fromPoint(j))
                             outFeat.addAttribute(0, atMap1[index1])
                             outFeat.addAttribute(1, atMap2[index2])
                             writer.addFeature(outFeat)
         start = start + add
         progress.setPercentage(start)
     del writer
Esempio n. 10
0
 def processAlgorithm(self, progress):
     useSelection = self.getParameterValue(Difference.USE_SELECTED)
     useSelection2 = self.getParameterValue(Difference.USE_SELECTED2)
     vlayerA = QGisLayers.getObjectFromUri(
         self.getParameterValue(Difference.INPUT))
     vlayerB = QGisLayers.getObjectFromUri(
         self.getParameterValue(Difference.INPUT2))
     GEOS_EXCEPT = True
     FEATURE_EXCEPT = True
     vproviderA = vlayerA.dataProvider()
     allAttrsA = vproviderA.attributeIndexes()
     vproviderA.select(allAttrsA)
     vproviderB = vlayerB.dataProvider()
     allAttrsB = vproviderB.attributeIndexes()
     vproviderB.select(allAttrsB)
     fields = vproviderA.fields()
     # check for crs compatibility
     crsA = vproviderA.crs()
     crsB = vproviderB.crs()
     if not crsA.isValid() or not crsB.isValid():
         SextanteLog.addToLog(
             SextanteLog.LOG_WARNING,
             "Difference. Invalid CRS. Results might be unexpected")
     else:
         if not crsA != crsB:
             SextanteLog.addToLog(
                 SextanteLog.LOG_WARNING,
                 "Difference. Non-matching CRSs. Results might be unexpected"
             )
     writer = self.getOutputFromName(Difference.OUTPUT).getVectorWriter(
         fields, vproviderA.geometryType(), vproviderA.crs())
     inFeatA = QgsFeature()
     inFeatB = QgsFeature()
     outFeat = QgsFeature()
     index = ftools_utils.createIndex(vproviderB)
     nElement = 0
     # there is selection in input layer
     if useSelection:
         nFeat = vlayerA.selectedFeatureCount()
         selectionA = vlayerA.selectedFeatures()
         # we have selection in overlay layer
         if useSelection2:
             selectionB = vlayerB.selectedFeaturesIds()
             for inFeatA in selectionA:
                 nElement += 1
                 progress.setPercentage(int(nElement / nFeat * 100))
                 add = True
                 geom = QgsGeometry(inFeatA.geometry())
                 diff_geom = QgsGeometry(geom)
                 atMap = inFeatA.attributeMap()
                 intersects = index.intersects(geom.boundingBox())
                 for id in intersects:
                     # is intersect feature in selection
                     if id in selectionB:
                         vproviderB.featureAtId(int(id), inFeatB, True,
                                                allAttrsB)
                         tmpGeom = QgsGeometry(inFeatB.geometry())
                         try:
                             if diff_geom.intersects(tmpGeom):
                                 diff_geom = QgsGeometry(
                                     diff_geom.difference(tmpGeom))
                         except:
                             GEOS_EXCEPT = False
                             add = False
                             break
                 if add:
                     try:
                         outFeat.setGeometry(diff_geom)
                         outFeat.setAttributeMap(atMap)
                         writer.addFeature(outFeat)
                     except:
                         FEATURE_EXCEPT = False
                         continue
         # we have no selection in overlay layer
         else:
             for inFeatA in selectionA:
                 nElement += 1
                 progress.setPercentage(int(nElement / nFeat * 100))
                 add = True
                 geom = QgsGeometry(inFeatA.geometry())
                 diff_geom = QgsGeometry(geom)
                 atMap = inFeatA.attributeMap()
                 intersects = index.intersects(geom.boundingBox())
                 for id in intersects:
                     vproviderB.featureAtId(int(id), inFeatB, True,
                                            allAttrsB)
                     tmpGeom = QgsGeometry(inFeatB.geometry())
                     try:
                         if diff_geom.intersects(tmpGeom):
                             diff_geom = QgsGeometry(
                                 diff_geom.difference(tmpGeom))
                     except:
                         GEOS_EXCEPT = False
                         add = False
                         break
                 if add:
                     try:
                         outFeat.setGeometry(diff_geom)
                         outFeat.setAttributeMap(atMap)
                         writer.addFeature(outFeat)
                     except:
                         FEATURE_EXCEPT = False
                         continue
     # there is no selection in input layer
     else:
         nFeat = vproviderA.featureCount()
         vproviderA.rewind()
         # we have selection in overlay layer
         if useSelection2:
             selectionB = vlayerB.selectedFeaturesIds()
             while vproviderA.nextFeature(inFeatA):
                 nElement += 1
                 add = True
                 progress.setPercentage(int(nElement / nFeat * 100))
                 geom = QgsGeometry(inFeatA.geometry())
                 diff_geom = QgsGeometry(geom)
                 atMap = inFeatA.attributeMap()
                 intersects = index.intersects(geom.boundingBox())
                 for id in intersects:
                     # now check if id in selection
                     if id in selectionB:
                         vproviderB.featureAtId(int(id), inFeatB, True,
                                                allAttrsB)
                         tmpGeom = QgsGeometry(inFeatB.geometry())
                         try:
                             if diff_geom.intersects(tmpGeom):
                                 diff_geom = QgsGeometry(
                                     diff_geom.difference(tmpGeom))
                         except:
                             GEOS_EXCEPT = False
                             add = False
                             break
                 if add:
                     try:
                         outFeat.setGeometry(diff_geom)
                         outFeat.setAttributeMap(atMap)
                         writer.addFeature(outFeat)
                     except:
                         FEATURE_EXCEPT = False
                         continue
         # we have no selection in overlay layer
         else:
             while vproviderA.nextFeature(inFeatA):
                 nElement += 1
                 add = True
                 progress.setPercentage(int(nElement / nFeat * 100))
                 geom = QgsGeometry(inFeatA.geometry())
                 diff_geom = QgsGeometry(geom)
                 atMap = inFeatA.attributeMap()
                 intersects = index.intersects(geom.boundingBox())
                 for id in intersects:
                     vproviderB.featureAtId(int(id), inFeatB, True,
                                            allAttrsB)
                     tmpGeom = QgsGeometry(inFeatB.geometry())
                     try:
                         if diff_geom.intersects(tmpGeom):
                             diff_geom = QgsGeometry(
                                 diff_geom.difference(tmpGeom))
                     except:
                         GEOS_EXCEPT = False
                         add = False
                         break
                 if add:
                     try:
                         outFeat.setGeometry(diff_geom)
                         outFeat.setAttributeMap(atMap)
                         writer.addFeature(outFeat)
                     except:
                         FEATURE_EXCEPT = False
                         continue
     del writer
     if not GEOS_EXCEPT:
         SextanteLog.addToLog(
             SextanteLog.LOG_WARNING,
             "Geometry exception while computing difference")
     if not FEATURE_EXCEPT:
         SextanteLog.addToLog(
             SextanteLog.LOG_WARNING,
             "Feature exception while computing difference")
Esempio n. 11
0
 def processAlgorithm(self, progress):
     useSelection = self.getParameterValue(Intersection.USE_SELECTED)
     useSelection2 = self.getParameterValue(Intersection.USE_SELECTED2)
     vlayerA = QGisLayers.getObjectFromUri(
         self.getParameterValue(Intersection.INPUT))
     vlayerB = QGisLayers.getObjectFromUri(
         self.getParameterValue(Intersection.INPUT2))
     GEOS_EXCEPT = True
     FEATURE_EXCEPT = True
     vproviderA = vlayerA.dataProvider()
     allAttrsA = vproviderA.attributeIndexes()
     vproviderA.select(allAttrsA)
     vproviderB = vlayerB.dataProvider()
     allAttrsB = vproviderB.attributeIndexes()
     vproviderB.select(allAttrsB)
     # check for crs compatibility
     crsA = vproviderA.crs()
     crsB = vproviderB.crs()
     if not crsA.isValid() or not crsB.isValid():
         SextanteLog.addToLog(
             SextanteLog.LOG_WARNING,
             "Intersection. Invalid CRS. Results might be unexpected")
     else:
         if not crsA != crsB:
             SextanteLog.addToLog(
                 SextanteLog.LOG_WARNING,
                 "Intersection. Non-matching CRSs. Results might be unexpected"
             )
     fields = ftools_utils.combineVectorFields(vlayerA, vlayerB)
     longNames = ftools_utils.checkFieldNameLength(fields)
     if not longNames.isEmpty():
         raise GeoAlgorithmExecutionException(
             "Following field names are longer than 10 characters:\n" +
             longNames.join('\n'))
     writer = self.getOutputFromName(Intersection.OUTPUT).getVectorWriter(
         fields, vproviderA.geometryType(), vproviderA.crs())
     inFeatA = QgsFeature()
     inFeatB = QgsFeature()
     outFeat = QgsFeature()
     index = ftools_utils.createIndex(vproviderB)
     nElement = 0
     # there is selection in input layer
     if useSelection:
         nFeat = vlayerA.selectedFeatureCount()
         selectionA = vlayerA.selectedFeatures()
         # we have selection in overlay layer
         if useSelection2:
             selectionB = vlayerB.selectedFeaturesIds()
             for inFeatA in selectionA:
                 nElement += 1
                 progress.setPercentage(int(nElement / nFeat * 100))
                 geom = QgsGeometry(inFeatA.geometry())
                 atMapA = inFeatA.attributeMap()
                 intersects = index.intersects(geom.boundingBox())
                 for id in intersects:
                     if id in selectionB:
                         vproviderB.featureAtId(int(id), inFeatB, True,
                                                allAttrsB)
                         tmpGeom = QgsGeometry(inFeatB.geometry())
                         try:
                             if geom.intersects(tmpGeom):
                                 atMapB = inFeatB.attributeMap()
                                 int_geom = QgsGeometry(
                                     geom.intersection(tmpGeom))
                                 if int_geom.wkbType() == 7:
                                     int_com = geom.combine(tmpGeom)
                                     int_sym = geom.symDifference(tmpGeom)
                                     int_geom = QgsGeometry(
                                         int_com.difference(int_sym))
                                 try:
                                     outFeat.setGeometry(int_geom)
                                     outFeat.setAttributeMap(
                                         ftools_utils.
                                         combineVectorAttributes(
                                             atMapA, atMapB))
                                     writer.addFeature(outFeat)
                                 except:
                                     FEATURE_EXCEPT = False
                                     continue
                         except:
                             GEOS_EXCEPT = False
                             break
         # we don't have selection in overlay layer
         else:
             for inFeatA in selectionA:
                 nElement += 1
                 progress.setPercentage(int(nElement / nFeat * 100))
                 geom = QgsGeometry(inFeatA.geometry())
                 atMapA = inFeatA.attributeMap()
                 intersects = index.intersects(geom.boundingBox())
                 for id in intersects:
                     vproviderB.featureAtId(int(id), inFeatB, True,
                                            allAttrsB)
                     tmpGeom = QgsGeometry(inFeatB.geometry())
                     try:
                         if geom.intersects(tmpGeom):
                             atMapB = inFeatB.attributeMap()
                             int_geom = QgsGeometry(
                                 geom.intersection(tmpGeom))
                             if int_geom.wkbType() == 7:
                                 int_com = geom.combine(tmpGeom)
                                 int_sym = geom.symDifference(tmpGeom)
                                 int_geom = QgsGeometry(
                                     int_com.difference(int_sym))
                             try:
                                 outFeat.setGeometry(int_geom)
                                 outFeat.setAttributeMap(
                                     ftools_utils.combineVectorAttributes(
                                         atMapA, atMapB))
                                 writer.addFeature(outFeat)
                             except:
                                 EATURE_EXCEPT = False
                                 continue
                     except:
                         GEOS_EXCEPT = False
                         break
     # there is no selection in input layer
     else:
         nFeat = vproviderA.featureCount()
         vproviderA.rewind()
         # we have selection in overlay layer
         if useSelection2:
             selectionB = vlayerB.selectedFeaturesIds()
             while vproviderA.nextFeature(inFeatA):
                 nElement += 1
                 progress.setPercentage(int(nElement / nFeat * 100))
                 geom = QgsGeometry(inFeatA.geometry())
                 atMapA = inFeatA.attributeMap()
                 intersects = index.intersects(geom.boundingBox())
                 for id in intersects:
                     if id in selectionB:
                         vproviderB.featureAtId(int(id), inFeatB, True,
                                                allAttrsB)
                         tmpGeom = QgsGeometry(inFeatB.geometry())
                         try:
                             if geom.intersects(tmpGeom):
                                 atMapB = inFeatB.attributeMap()
                                 int_geom = QgsGeometry(
                                     geom.intersection(tmpGeom))
                                 if int_geom.wkbType() == 7:
                                     int_com = geom.combine(tmpGeom)
                                     int_sym = geom.symDifference(tmpGeom)
                                     int_geom = QgsGeometry(
                                         int_com.difference(int_sym))
                                 try:
                                     outFeat.setGeometry(int_geom)
                                     outFeat.setAttributeMap(
                                         ftools_utils.
                                         combineVectorAttributes(
                                             atMapA, atMapB))
                                     writer.addFeature(outFeat)
                                 except:
                                     FEATURE_EXCEPT = False
                                     continue
                         except:
                             GEOS_EXCEPT = False
                             break
         # we have no selection in overlay layer
         else:
             while vproviderA.nextFeature(inFeatA):
                 nElement += 1
                 progress.setPercentage(int(nElement / nFeat * 100))
                 geom = QgsGeometry(inFeatA.geometry())
                 atMapA = inFeatA.attributeMap()
                 intersects = index.intersects(geom.boundingBox())
                 for id in intersects:
                     vproviderB.featureAtId(int(id), inFeatB, True,
                                            allAttrsB)
                     tmpGeom = QgsGeometry(inFeatB.geometry())
                     try:
                         if geom.intersects(tmpGeom):
                             atMapB = inFeatB.attributeMap()
                             int_geom = QgsGeometry(
                                 geom.intersection(tmpGeom))
                             if int_geom.wkbType() == 7:
                                 int_com = geom.combine(tmpGeom)
                                 int_sym = geom.symDifference(tmpGeom)
                                 int_geom = QgsGeometry(
                                     int_com.difference(int_sym))
                             try:
                                 outFeat.setGeometry(int_geom)
                                 outFeat.setAttributeMap(
                                     ftools_utils.combineVectorAttributes(
                                         atMapA, atMapB))
                                 writer.addFeature(outFeat)
                             except:
                                 FEATURE_EXCEPT = False
                                 continue
                     except:
                         GEOS_EXCEPT = False
                         break
     del writer
     if not GEOS_EXCEPT:
         SextanteLog.addToLog(
             SextanteLog.LOG_WARNING,
             "Geometry exception while computing intersection")
     if not FEATURE_EXCEPT:
         SextanteLog.addToLog(
             SextanteLog.LOG_WARNING,
             "Feature exception while computing interesection")
Esempio n. 12
0
    def processAlgorithm(self, progress):
        settings = QSettings()
        systemEncoding = settings.value( "/UI/encoding", "System" ).toString()
        output = self.getOutputValue(Clip.OUTPUT)
        useSelection = self.getParameterValue(Clip.USE_SELECTED)
        useSelection2 = self.getParameterValue(Clip.USE_SELECTED2)
        vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(Clip.INPUT))
        vlayerB = QGisLayers.getObjectFromUri(self.getParameterValue(Clip.INPUT2))
        GEOS_EXCEPT = True
        FEATURE_EXCEPT = True
        vproviderA = vlayerA.dataProvider()
        allAttrsA = vproviderA.attributeIndexes()
        vproviderA.select( allAttrsA )
        vproviderB = vlayerB.dataProvider()
        allAttrsB = vproviderB.attributeIndexes()
        vproviderB.select( allAttrsB )
        # check for crs compatibility
        crsA = vproviderA.crs()
        crsB = vproviderB.crs()
        if not crsA.isValid() or not crsB.isValid():
            SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Intersection. Invalid CRS. Results might be unexpected")
        else:
            if not crsA != crsB:
                SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Intersection. Non-matching CRSs. Results might be unexpected")
        fields = vproviderA.fields()
        writer = QgsVectorFileWriter( output, systemEncoding,fields, vproviderA.geometryType(), vproviderA.crs() )

        inFeatA = QgsFeature()
        inFeatB = QgsFeature()
        outFeat = QgsFeature()
        index = ftools_utils.createIndex( vproviderB )
        vproviderA.rewind()
        nElement = 0
        # there is selection in input layer
        if useSelection:
          nFeat = vlayerA.selectedFeatureCount()
          selectionA = vlayerA.selectedFeatures()
          # we have selection in overlay layer
          if useSelection2:
            selectionB = vlayerB.selectedFeaturesIds()
            for inFeatA in selectionA:
              nElement += 1
              progress.setPercentage(int(nElement/nFeat * 100))
              geom = QgsGeometry( inFeatA.geometry() )
              int_geom = QgsGeometry( geom )
              atMap = inFeatA.attributeMap()
              intersects = index.intersects( geom.boundingBox() )
              found = False
              first = True
              for id in intersects:
                if id in selectionB:
                  vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
                  tmpGeom = QgsGeometry( inFeatB.geometry() )
                  if tmpGeom.intersects( geom ):
                    found = True
                    if first:
                      outFeat.setGeometry( QgsGeometry( tmpGeom ) )
                      first = False
                    else:
                      try:
                        cur_geom = QgsGeometry( outFeat.geometry() )
                        new_geom = QgsGeometry( cur_geom.combine( tmpGeom ) )
                        outFeat.setGeometry( QgsGeometry( new_geom ) )
                      except:
                        GEOS_EXCEPT = False
                        break
              if found:
                try:
                  cur_geom = QgsGeometry( outFeat.geometry() )
                  new_geom = QgsGeometry( geom.intersection( cur_geom ) )
                  if new_geom.wkbType() == 7:
                    int_com = QgsGeometry( geom.combine( cur_geom ) )
                    int_sym = QgsGeometry( geom.symDifference( cur_geom ) )
                    new_geom = QgsGeometry( int_com.difference( int_sym ) )
                  try:
                    outFeat.setGeometry( new_geom )
                    outFeat.setAttributeMap( atMap )
                    writer.addFeature( outFeat )
                  except:
                    FEAT_EXCEPT = False
                    continue
                except:
                  GEOS_EXCEPT = False
                  continue
          # we have no selection in overlay layer
          else:
            for inFeatA in selectionA:
              nElement += 1
              progress.setPercentage(int(nElement/nFeat * 100))
              geom = QgsGeometry( inFeatA.geometry() )
              atMap = inFeatA.attributeMap()
              intersects = index.intersects( geom.boundingBox() )
              found = False
              first = True
              for id in intersects:
                vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
                tmpGeom = QgsGeometry( inFeatB.geometry() )
                if tmpGeom.intersects( geom ):
                  found = True
                  if first:
                    outFeat.setGeometry( QgsGeometry( tmpGeom ) )
                    first = False
                  else:
                    try:
                      cur_geom = QgsGeometry( outFeat.geometry() )
                      new_geom = QgsGeometry( cur_geom.combine( tmpGeom ) )
                      outFeat.setGeometry( QgsGeometry( new_geom ) )
                    except:
                      GEOS_EXCEPT = False
                      break
              if found:
                try:
                  cur_geom = QgsGeometry( outFeat.geometry() )
                  new_geom = QgsGeometry( geom.intersection( cur_geom ) )
                  if new_geom.wkbType() == 7:
                    int_com = QgsGeometry( geom.combine( cur_geom ) )
                    int_sym = QgsGeometry( geom.symDifference( cur_geom ) )
                    new_geom = QgsGeometry( int_com.difference( int_sym ) )
                  try:
                    outFeat.setGeometry( new_geom )
                    outFeat.setAttributeMap( atMap )
                    writer.addFeature( outFeat )
                  except:
                    FEAT_EXCEPT = False
                    continue
                except:
                  GEOS_EXCEPT = False
                  continue
        # there is no selection in input layer
        else:
          nFeat = vproviderA.featureCount()
          # we have selection in overlay layer
          if useSelection2:
            selectionB = vlayerB.selectedFeaturesIds()
            while vproviderA.nextFeature( inFeatA ):
              nElement += 1
              progress.setPercentage(int(nElement/nFeat * 100))
              geom = QgsGeometry( inFeatA.geometry() )
              atMap = inFeatA.attributeMap()
              intersects = index.intersects( geom.boundingBox() )
              found = False
              first = True
              for id in intersects:
                if id in selectionB:
                  vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
                  tmpGeom = QgsGeometry( inFeatB.geometry() )
                  if tmpGeom.intersects( geom ):
                    found = True
                    if first:
                      outFeat.setGeometry( QgsGeometry( tmpGeom ) )
                      first = False
                    else:
                      try:
                        cur_geom = QgsGeometry( outFeat.geometry() )
                        new_geom = QgsGeometry( cur_geom.combine( tmpGeom ) )
                        outFeat.setGeometry( QgsGeometry( new_geom ) )
                      except:
                        GEOS_EXCEPT = False
                        break
              if found:
                try:
                  cur_geom = QgsGeometry( outFeat.geometry() )
                  new_geom = QgsGeometry( geom.intersection( cur_geom ) )
                  if new_geom.wkbType() == 7:
                    int_com = QgsGeometry( geom.combine( cur_geom ) )
                    int_sym = QgsGeometry( geom.symDifference( cur_geom ) )
                    new_geom = QgsGeometry( int_com.difference( int_sym ) )
                  try:
                    outFeat.setGeometry( new_geom )
                    outFeat.setAttributeMap( atMap )
                    writer.addFeature( outFeat )
                  except:
                    FEAT_EXCEPT = False
                    continue
                except:
                  GEOS_EXCEPT = False
                  continue
          # we have no selection in overlay layer
          else:
            while vproviderA.nextFeature( inFeatA ):
              nElement += 1
              progress.setPercentage(int(nElement/nFeat * 100))
              geom = QgsGeometry( inFeatA.geometry() )
              atMap = inFeatA.attributeMap()
              intersects = index.intersects( geom.boundingBox() )
              first = True
              found = False
              if len( intersects ) > 0:
                for id in intersects:
                  vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
                  tmpGeom = QgsGeometry( inFeatB.geometry() )
                  if tmpGeom.intersects( geom ):
                    found = True
                    if first:
                      outFeat.setGeometry( QgsGeometry( tmpGeom ) )
                      first = False
                    else:
                      try:
                        cur_geom = QgsGeometry( outFeat.geometry() )
                        new_geom = QgsGeometry( cur_geom.combine( tmpGeom ) )
                        outFeat.setGeometry( QgsGeometry( new_geom ) )
                      except:
                        GEOS_EXCEPT = False
                        break
                if found:
                  try:
                    cur_geom = QgsGeometry( outFeat.geometry() )
                    new_geom = QgsGeometry( geom.intersection( cur_geom ) )
                    if new_geom.wkbType() == 7:
                      int_com = QgsGeometry( geom.combine( cur_geom ) )
                      int_sym = QgsGeometry( geom.symDifference( cur_geom ) )
                      new_geom = QgsGeometry( int_com.difference( int_sym ) )
                    try:
                      outFeat.setGeometry( new_geom )
                      outFeat.setAttributeMap( atMap )
                      writer.addFeature( outFeat )
                    except:
                      FEAT_EXCEPT = False
                      continue
                  except:
                    GEOS_EXCEPT = False
                    continue
        del writer
        if not GEOS_EXCEPT:
            SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Geometry exception while computing clip")
        if not FEATURE_EXCEPT:
            SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Feature exception while computing clip")
Esempio n. 13
0
 def processAlgorithm(self, progress):
     inField = self.getParameterValue(SumLines.FIELD)
     lineLayer = QGisLayers.getObjectFromUri(
         self.getParameterValue(SumLines.LINES))
     polyLayer = QGisLayers.getObjectFromUri(
         self.getParameterValue(SumLines.POLYGONS))
     polyProvider = polyLayer.dataProvider()
     lineProvider = lineLayer.dataProvider()
     if polyProvider.crs() <> lineProvider.crs():
         SextanteLog.addToLog(
             SextanteLog.LOG_WARNING,
             "CRS warning!Warning: Input layers have non-matching CRS.\nThis may cause unexpected results."
         )
     allAttrs = polyProvider.attributeIndexes()
     polyProvider.select(allAttrs)
     allAttrs = lineProvider.attributeIndexes()
     lineProvider.select(allAttrs)
     fieldList = ftools_utils.getFieldList(polyLayer)
     index = polyProvider.fieldNameIndex(unicode(inField))
     if index == -1:
         index = polyProvider.fieldCount()
         field = QgsField(unicode(inField), QVariant.Double, "real", 24, 15,
                          self.tr("length field"))
         fieldList[index] = field
     sRs = polyProvider.crs()
     inFeat = QgsFeature()
     inFeatB = QgsFeature()
     outFeat = QgsFeature()
     inGeom = QgsGeometry()
     outGeom = QgsGeometry()
     distArea = QgsDistanceArea()
     lineProvider.rewind()
     start = 15.00
     add = 85.00 / polyProvider.featureCount()
     writer = self.getOutputFromName(SumLines.OUTPUT).getVectorWriter(
         fieldList, polyProvider.geometryType(), sRs)
     spatialIndex = ftools_utils.createIndex(lineProvider)
     while polyProvider.nextFeature(inFeat):
         inGeom = QgsGeometry(inFeat.geometry())
         atMap = inFeat.attributeMap()
         lineList = []
         length = 0
         #(check, lineList) = lineLayer.featuresInRectangle(inGeom.boundingBox(), True, False)
         #lineLayer.select(inGeom.boundingBox(), False)
         #lineList = lineLayer.selectedFeatures()
         lineList = spatialIndex.intersects(inGeom.boundingBox())
         if len(lineList) > 0: check = 0
         else: check = 1
         if check == 0:
             for i in lineList:
                 lineProvider.featureAtId(int(i), inFeatB, True, allAttrs)
                 tmpGeom = QgsGeometry(inFeatB.geometry())
                 if inGeom.intersects(tmpGeom):
                     outGeom = inGeom.intersection(tmpGeom)
                     length = length + distArea.measure(outGeom)
         outFeat.setGeometry(inGeom)
         outFeat.setAttributeMap(atMap)
         outFeat.addAttribute(index, QVariant(length))
         writer.addFeature(outFeat)
         start = start + add
         progress.setPercentage(start)
     del writer
Esempio n. 14
0
 def processAlgorithm(self, progress):
     useSelection = self.getParameterValue(Difference.USE_SELECTED)
     useSelection2 = self.getParameterValue(Difference.USE_SELECTED2)
     vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(Difference.INPUT))
     vlayerB = QGisLayers.getObjectFromUri(self.getParameterValue(Difference.INPUT2))
     GEOS_EXCEPT = True
     FEATURE_EXCEPT = True
     vproviderA = vlayerA.dataProvider()
     allAttrsA = vproviderA.attributeIndexes()
     vproviderA.select( allAttrsA )
     vproviderB = vlayerB.dataProvider()
     allAttrsB = vproviderB.attributeIndexes()
     vproviderB.select( allAttrsB )
     fields = vproviderA.fields()
     # check for crs compatibility
     crsA = vproviderA.crs()
     crsB = vproviderB.crs()
     if not crsA.isValid() or not crsB.isValid():
         SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Difference. Invalid CRS. Results might be unexpected")
     else:
         if not crsA != crsB:
             SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Difference. Non-matching CRSs. Results might be unexpected")
     writer = self.getOutputFromName(Difference.OUTPUT).getVectorWriter(fields, vproviderA.geometryType(), vproviderA.crs() )
     inFeatA = QgsFeature()
     inFeatB = QgsFeature()
     outFeat = QgsFeature()
     index = ftools_utils.createIndex( vproviderB )
     nElement = 0
     # there is selection in input layer
     if useSelection:
       nFeat = vlayerA.selectedFeatureCount()
       selectionA = vlayerA.selectedFeatures()
       # we have selection in overlay layer
       if useSelection2:
         selectionB = vlayerB.selectedFeaturesIds()
         for inFeatA in selectionA:
           nElement += 1
           progress.setPercentage(int(nElement/nFeat * 100))
           add = True
           geom = QgsGeometry( inFeatA.geometry() )
           diff_geom = QgsGeometry( geom )
           atMap = inFeatA.attributeMap()
           intersects = index.intersects( geom.boundingBox() )
           for id in intersects:
             # is intersect feature in selection
             if id in selectionB:
               vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
               tmpGeom = QgsGeometry( inFeatB.geometry() )
               try:
                 if diff_geom.intersects( tmpGeom ):
                   diff_geom = QgsGeometry( diff_geom.difference( tmpGeom ) )
               except:
                 GEOS_EXCEPT = False
                 add = False
                 break
           if add:
             try:
               outFeat.setGeometry( diff_geom )
               outFeat.setAttributeMap( atMap )
               writer.addFeature( outFeat )
             except:
               FEATURE_EXCEPT = False
               continue
       # we have no selection in overlay layer
       else:
         for inFeatA in selectionA:
           nElement += 1
           progress.setPercentage(int(nElement/nFeat * 100))
           add = True
           geom = QgsGeometry( inFeatA.geometry() )
           diff_geom = QgsGeometry( geom )
           atMap = inFeatA.attributeMap()
           intersects = index.intersects( geom.boundingBox() )
           for id in intersects:
             vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
             tmpGeom = QgsGeometry( inFeatB.geometry() )
             try:
               if diff_geom.intersects( tmpGeom ):
                 diff_geom = QgsGeometry( diff_geom.difference( tmpGeom ) )
             except:
               GEOS_EXCEPT = False
               add = False
               break
           if add:
             try:
               outFeat.setGeometry( diff_geom )
               outFeat.setAttributeMap( atMap )
               writer.addFeature( outFeat )
             except:
               FEATURE_EXCEPT = False
               continue
     # there is no selection in input layer
     else:
       nFeat = vproviderA.featureCount()
       vproviderA.rewind()
       # we have selection in overlay layer
       if useSelection2:
         selectionB = vlayerB.selectedFeaturesIds()
         while vproviderA.nextFeature( inFeatA ):
           nElement += 1
           add = True
           progress.setPercentage(int(nElement/nFeat * 100))
           geom = QgsGeometry( inFeatA.geometry() )
           diff_geom = QgsGeometry( geom )
           atMap = inFeatA.attributeMap()
           intersects = index.intersects( geom.boundingBox() )
           for id in intersects:
             # now check if id in selection
             if id in selectionB:
               vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
               tmpGeom = QgsGeometry( inFeatB.geometry() )
               try:
                 if diff_geom.intersects( tmpGeom ):
                   diff_geom = QgsGeometry( diff_geom.difference( tmpGeom ) )
               except:
                 GEOS_EXCEPT = False
                 add = False
                 break
           if add:
             try:
               outFeat.setGeometry( diff_geom )
               outFeat.setAttributeMap( atMap )
               writer.addFeature( outFeat )
             except:
               FEATURE_EXCEPT = False
               continue
       # we have no selection in overlay layer
       else:
         while vproviderA.nextFeature( inFeatA ):
           nElement += 1
           add = True
           progress.setPercentage(int(nElement/nFeat * 100))
           geom = QgsGeometry( inFeatA.geometry() )
           diff_geom = QgsGeometry( geom )
           atMap = inFeatA.attributeMap()
           intersects = index.intersects( geom.boundingBox() )
           for id in intersects:
             vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
             tmpGeom = QgsGeometry( inFeatB.geometry() )
             try:
               if diff_geom.intersects( tmpGeom ):
                 diff_geom = QgsGeometry( diff_geom.difference( tmpGeom ) )
             except:
               GEOS_EXCEPT = False
               add = False
               break
           if add:
             try:
               outFeat.setGeometry( diff_geom )
               outFeat.setAttributeMap( atMap )
               writer.addFeature( outFeat )
             except:
               FEATURE_EXCEPT = False
               continue
     del writer
     if not GEOS_EXCEPT:
         SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Geometry exception while computing difference")
     if not FEATURE_EXCEPT:
         SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Feature exception while computing difference")
Esempio n. 15
0
    def processAlgorithm(self, progress):
        vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(Union.INPUT))
        vlayerB = QGisLayers.getObjectFromUri(self.getParameterValue(Union.INPUT2))
        GEOS_EXCEPT = True
        FEATURE_EXCEPT = True
        vproviderA = vlayerA.dataProvider()
        allAttrsA = vproviderA.attributeIndexes()
        vproviderA.select( allAttrsA )
        vproviderB = vlayerB.dataProvider()
        allAttrsB = vproviderB.attributeIndexes()
        vproviderB.select( allAttrsB )

        # check for crs compatibility
        crsA = vproviderA.crs()
        crsB = vproviderB.crs()
        if not crsA.isValid() or not crsB.isValid():
            SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Union. Invalid CRS. Results might be unexpected")
        else:
            if not crsA != crsB:
                SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Union. Non-matching CRSs. Results might be unexpected")
        fields = ftools_utils.combineVectorFields(vlayerA, vlayerB )
        longNames = ftools_utils.checkFieldNameLength( fields )
        if not longNames.isEmpty():
            raise GeoAlgorithmExecutionException("Following field names are longer than 10 characters:\n" +  longNames.join('\n') )
        writer = self.getOutputFromName(Union.OUTPUT).getVectorWriter(fields, vproviderA.geometryType(), vproviderA.crs() )
        inFeatA = QgsFeature()
        inFeatB = QgsFeature()
        outFeat = QgsFeature()
        indexA = ftools_utils.createIndex( vproviderB )
        indexB = ftools_utils.createIndex( vproviderA )
        nFeat = vproviderA.featureCount() * vproviderB.featureCount()
        vproviderA.rewind()
        count = 0
        nElement = 0

        while vproviderA.nextFeature( inFeatA ):
          progress.setPercentage(int(nElement/nFeat * 100))
          nElement += 1
          found = False
          geom = QgsGeometry( inFeatA.geometry() )
          diff_geom = QgsGeometry( geom )
          atMapA = inFeatA.attributeMap()
          intersects = indexA.intersects( geom.boundingBox() )
          if len( intersects ) < 1:
            try:
              outFeat.setGeometry( geom )
              outFeat.setAttributeMap( atMapA )
              writer.addFeature( outFeat )
            except:
              # this really shouldn't happen, as we
              # haven't edited the input geom at all
              FEATURE_EXCEPT = False
          else:
            for id in intersects:
              count += 1
              vproviderB.featureAtId( int( id ), inFeatB , True, allAttrsB )
              atMapB = inFeatB.attributeMap()
              tmpGeom = QgsGeometry( inFeatB.geometry() )
              try:
                if geom.intersects( tmpGeom ):
                  found = True
                  int_geom = geom.intersection( tmpGeom )

                  if int_geom is None:
                    # There was a problem creating the intersection
                    GEOS_EXCEPT = False
                    int_geom = QgsGeometry()
                  else:
                    int_geom = QgsGeometry(int_geom)

                  if diff_geom.intersects( tmpGeom ):
                    diff_geom = diff_geom.difference( tmpGeom )
                    if diff_geom is None:
                      # It's possible there was an error here?
                      diff_geom = QgsGeometry()
                    else:
                      diff_geom = QgsGeometry(diff_geom)

                  if int_geom.wkbType() == 0:
                    # intersection produced different geomety types
                    temp_list = int_geom.asGeometryCollection()
                    for i in temp_list:
                      if i.type() == geom.type():
                          int_geom = QgsGeometry( i )
                  try:
                    outFeat.setGeometry( int_geom )
                    outFeat.setAttributeMap( ftools_utils.combineVectorAttributes( atMapA, atMapB ) )
                    writer.addFeature( outFeat )
                  except Exception, err:
                    FEATURE_EXCEPT = False
                else:
                  # this only happends if the bounding box
                  # intersects, but the geometry doesn't
                  try:
                    outFeat.setGeometry( geom )
                    outFeat.setAttributeMap( atMapA )
                    writer.addFeature( outFeat )
                  except:
                    # also shoudn't ever happen
                    FEATURE_EXCEPT = False
              except Exception, err:
                GEOS_EXCEPT = False
                found = False
Esempio n. 16
0
 def processAlgorithm(self, progress):
     layer1 = QGisLayers.getObjectFromUri(
         self.getParameterValue(LinesIntersection.INPUT1))
     layer2 = QGisLayers.getObjectFromUri(
         self.getParameterValue(LinesIntersection.INPUT2))
     field1 = self.getParameterValue(LinesIntersection.FIELD1)
     field2 = self.getParameterValue(LinesIntersection.FIELD2)
     provider1 = layer1.dataProvider()
     provider2 = layer2.dataProvider()
     allAttrs = provider1.attributeIndexes()
     provider1.select(allAttrs)
     allAttrs = provider2.attributeIndexes()
     provider2.select(allAttrs)
     fieldList = ftools_utils.getFieldList(layer1)
     index1 = provider1.fieldNameIndex(field1)
     field1 = fieldList[index1]
     field1.setName(unicode(field1.name()) + "_1")
     fieldList = ftools_utils.getFieldList(layer2)
     index2 = provider2.fieldNameIndex(field2)
     field2 = fieldList[index2]
     field2.setName(unicode(field2.name()) + "_2")
     fieldList = {0: field1, 1: field2}
     sRs = provider1.crs()
     writer = self.getOutputFromName(
         LinesIntersection.OUTPUT).getVectorWriter(fieldList, QGis.WKBPoint,
                                                   sRs)
     #writer = QgsVectorFileWriter(outPath, "UTF-8", fieldList, QGis.WKBPoint, sRs)
     inFeat = QgsFeature()
     inFeatB = QgsFeature()
     outFeat = QgsFeature()
     inGeom = QgsGeometry()
     tempGeom = QgsGeometry()
     start = 15.00
     add = 85.00 / layer1.featureCount()
     index = ftools_utils.createIndex(provider2)
     while provider1.nextFeature(inFeat):
         inGeom = inFeat.geometry()
         lineList = []
         #(check, lineList) = layer2.featuresInRectangle(inGeom.boundingBox(), True, True)
         # Below is a work-around for featuresInRectangle
         # Which appears to have been removed for QGIS version 1.0
         #layer2.select(inGeom.boundingBox(), False)
         #lineList = layer2.selectedFeatures()
         lineList = index.intersects(inGeom.boundingBox())
         if len(lineList) > 0: check = 0
         else: check = 1
         if check == 0:
             for i in lineList:
                 provider2.featureAtId(int(i), inFeatB, True, allAttrs)
                 tmpGeom = QgsGeometry(inFeatB.geometry())
                 #tempGeom = i.geometry()
                 tempList = []
                 atMap1 = inFeat.attributeMap()
                 atMap2 = inFeatB.attributeMap()
                 if inGeom.intersects(tmpGeom):
                     tempGeom = inGeom.intersection(tmpGeom)
                     if tempGeom.type() == QGis.Point:
                         if tempGeom.isMultipart():
                             tempList = tempGeom.asMultiPoint()
                         else:
                             tempList.append(tempGeom.asPoint())
                         for j in tempList:
                             outFeat.setGeometry(tempGeom.fromPoint(j))
                             outFeat.addAttribute(0, atMap1[index1])
                             outFeat.addAttribute(1, atMap2[index2])
                             writer.addFeature(outFeat)
         start = start + add
         progress.setPercentage(start)
     del writer