Skip to content
Permalink
Browse files

Fixing several errors in generation of NxT distance matrix

  • Loading branch information
ccrook committed Aug 11, 2014
1 parent e9dac8e commit c945eec5560555cffa7a2f2881074f701f098569
Showing with 9 additions and 12 deletions.
  1. +9 −12 python/plugins/processing/algs/qgis/ftools/PointDistance.py
@@ -125,7 +125,7 @@ def linearMatrix(self, inLayer, inField, targetLayer, targetField,
total = 100.0 / float(len(features))
for inFeat in features:
inGeom = inFeat.geometry()
inID = inFeat.attributes()[inIdx]
inID = unicode(inFeat.attributes()[inIdx])
featList = index.nearestNeighbor(inGeom.asPoint(), nPoints)
distList = []
vari = 0.0
@@ -137,17 +137,16 @@ def linearMatrix(self, inLayer, inField, targetLayer, targetField,
dist = distArea.measureLine(inGeom.asPoint(),
outGeom.asPoint())
if matType == 0:
self.writer.addRecord([unicode(inID), unicode(outID),
unicode(dist)])
self.writer.addRecord([inID,unicode(outID),unicode(dist)])
else:
distList.append(float(dist))

if matType == 2:
if matType != 0:
mean = sum(distList) / len(distList)
for i in distList:
vari += (i - mean) * (i - mean)
vari = math.sqrt(vari / len(distList))
self.writer.addRecord([unicode(inID), unicode(mean),
self.writer.addRecord([inID, unicode(mean),
unicode(vari), unicode(min(distList)),
unicode(max(distList))])

@@ -173,18 +172,16 @@ def regularMatrix(self, inLayer, inField, targetLayer, targetField,

for inFeat in features:
inGeom = inFeat.geometry()
inID = inFeat.attributes()[inIdx]
inID = unicode(inFeat.attributes()[inIdx])
featList = index.nearestNeighbor(inGeom.asPoint(), nPoints)
if first:
featList = index.nearestNeighbor(inGeom.asPoint(), nPoints)
first = False
data = ['ID']
for i in featList:
request = QgsFeatureRequest().setFilterFid(i)
outFeat = targetLayer.getFeatures(request).next()
data.append(unicode(outFeat.attributes[outIdx]))
for i in range(len(featList)):
data.append('DIST_{0}'.format(i+1))
self.writer.addRecord(data)

data = [unicode(inID)]
data = [inID]
for i in featList:
request = QgsFeatureRequest().setFilterFid(i)
outFeat = targetLayer.getFeatures(request).next()

0 comments on commit c945eec

Please sign in to comment.
You can’t perform that action at this time.