Created
January 25, 2013 19:30
-
-
Save jef-n/4637120 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/python/plugins/fTools/tools/doIntersectLines.py b/python/plugins/fTools/tools/doIntersectLines.py | |
index 5df0975..03725cd 100644 | |
--- a/python/plugins/fTools/tools/doIntersectLines.py | |
+++ b/python/plugins/fTools/tools/doIntersectLines.py | |
@@ -111,69 +111,67 @@ class Dialog(QDialog, Ui_Dialog): | |
self.outShape.setText( QString( self.shapefileName ) ) | |
def compute(self, line1, line2, field1, field2, outPath, progressBar): | |
+ | |
layer1 = ftools_utils.getVectorLayerByName(line1) | |
- layer2 = ftools_utils.getVectorLayerByName(line2) | |
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") | |
+ | |
+ layer2 = ftools_utils.getVectorLayerByName(line2) | |
+ provider2 = layer2.dataProvider() | |
+ allAttrs = provider2.attributeIndexes() | |
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() | |
check = QFile(self.shapefileName) | |
if check.exists(): | |
if not QgsVectorFileWriter.deleteShapeFile(self.shapefileName): | |
return | |
+ | |
writer = QgsVectorFileWriter(self.shapefileName, self.encoding, 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 ) | |
+ | |
+ provider1.select([index1]) | |
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() | |
+ v1 = inFeat.attributeMap()[index1] | |
+ | |
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) | |
+ for i in lineList: | |
+ provider2.featureAtId( int( i ), inFeatB , True, [index2] ) | |
+ tmpGeom = QgsGeometry( inFeatB.geometry() ) | |
+ v2 = inFeatB.attributeMap()[index2] | |
+ | |
+ if inGeom.intersects(tmpGeom): | |
+ tempGeom = inGeom.intersection(tmpGeom) | |
+ if tempGeom.type() == QGis.Point: | |
+ tempList = [] | |
+ if tempGeom.isMultipart(): | |
+ tempList = tempGeom.asMultiPoint() | |
+ else: | |
+ tempList.append(tempGeom.asPoint()) | |
+ | |
+ for j in tempList: | |
+ outFeat.setGeometry(tempGeom.fromPoint(j)) | |
+ outFeat.addAttribute(0, v1) | |
+ outFeat.addAttribute(1, v2) | |
+ writer.addFeature(outFeat) | |
+ | |
start = start + add | |
progressBar.setValue(start) | |
+ | |
del writer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment