@@ -113,7 +113,7 @@ def linearMatrix(self, inLayer, inField, targetLayer, targetField,
113
113
index = vector .spatialindex (targetLayer )
114
114
115
115
inIdx = inLayer .fieldNameIndex (inField )
116
- outIdx = targetLayer .fieldNameIndex (inField )
116
+ outIdx = targetLayer .fieldNameIndex (targetField )
117
117
118
118
outFeat = QgsFeature ()
119
119
inGeom = QgsGeometry ()
@@ -125,7 +125,7 @@ def linearMatrix(self, inLayer, inField, targetLayer, targetField,
125
125
total = 100.0 / float (len (features ))
126
126
for inFeat in features :
127
127
inGeom = inFeat .geometry ()
128
- inID = inFeat .attributes ()[inIdx ]
128
+ inID = unicode ( inFeat .attributes ()[inIdx ])
129
129
featList = index .nearestNeighbor (inGeom .asPoint (), nPoints )
130
130
distList = []
131
131
vari = 0.0
@@ -137,17 +137,16 @@ def linearMatrix(self, inLayer, inField, targetLayer, targetField,
137
137
dist = distArea .measureLine (inGeom .asPoint (),
138
138
outGeom .asPoint ())
139
139
if matType == 0 :
140
- self .writer .addRecord ([unicode (inID ), unicode (outID ),
141
- unicode (dist )])
140
+ self .writer .addRecord ([inID ,unicode (outID ),unicode (dist )])
142
141
else :
143
142
distList .append (float (dist ))
144
143
145
- if matType == 2 :
144
+ if matType != 0 :
146
145
mean = sum (distList ) / len (distList )
147
146
for i in distList :
148
147
vari += (i - mean ) * (i - mean )
149
148
vari = math .sqrt (vari / len (distList ))
150
- self .writer .addRecord ([unicode ( inID ) , unicode (mean ),
149
+ self .writer .addRecord ([inID , unicode (mean ),
151
150
unicode (vari ), unicode (min (distList )),
152
151
unicode (max (distList ))])
153
152
@@ -173,18 +172,16 @@ def regularMatrix(self, inLayer, inField, targetLayer, targetField,
173
172
174
173
for inFeat in features :
175
174
inGeom = inFeat .geometry ()
176
- inID = inFeat .attributes ()[inIdx ]
175
+ inID = unicode (inFeat .attributes ()[inIdx ])
176
+ featList = index .nearestNeighbor (inGeom .asPoint (), nPoints )
177
177
if first :
178
- featList = index .nearestNeighbor (inGeom .asPoint (), nPoints )
179
178
first = False
180
179
data = ['ID' ]
181
- for i in featList :
182
- request = QgsFeatureRequest ().setFilterFid (i )
183
- outFeat = targetLayer .getFeatures (request ).next ()
184
- data .append (unicode (outFeat .attributes [outIdx ]))
180
+ for i in range (len (featList )):
181
+ data .append ('DIST_{0}' .format (i + 1 ))
185
182
self .writer .addRecord (data )
186
183
187
- data = [unicode ( inID ) ]
184
+ data = [inID ]
188
185
for i in featList :
189
186
request = QgsFeatureRequest ().setFilterFid (i )
190
187
outFeat = targetLayer .getFeatures (request ).next ()
0 commit comments