Skip to content
Permalink
Browse files
cleanup doIntersectLines.py and fix #7021
  • Loading branch information
jef-n committed Jan 25, 2013
1 parent 7ad3048 commit 298f0c000e041795390ae4759ae01572f9d677e5
Showing with 33 additions and 35 deletions.
  1. +33 −35 python/plugins/fTools/tools/doIntersectLines.py
@@ -111,69 +111,67 @@ def outFile(self):
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

0 comments on commit 298f0c0

Please sign in to comment.