Skip to content

Commit

Permalink
Fixing several errors in generation of NxT distance matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrook committed Aug 11, 2014
1 parent e9dac8e commit c945eec
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions python/plugins/processing/algs/qgis/ftools/PointDistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))])

Expand All @@ -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()
Expand Down

0 comments on commit c945eec

Please sign in to comment.