本文整理汇总了Python中sextante.algs.ftools.FToolsUtils类的典型用法代码示例。如果您正苦于以下问题:Python FToolsUtils类的具体用法?Python FToolsUtils怎么用?Python FToolsUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FToolsUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: processAlgorithm
def processAlgorithm(self, progress):
polyLayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.POLYGONS))
pointLayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.POINTS))
fieldName = self.getParameterValue(self.FIELD)
fieldIdx = pointLayer.fieldNameIndex(self.getParameterValue(self.WEIGHT))
polyProvider = polyLayer.dataProvider()
idxCount, fieldList = utils.findOrCreateField(polyLayer, polyLayer.pendingFields(), fieldName)
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
fieldList.toList(), polyProvider.geometryType(), polyProvider.crs()
)
spatialIndex = utils.createSpatialIndex(pointLayer)
ftPoint = QgsFeature()
outFeat = QgsFeature()
geom = QgsGeometry()
current = 0
hasIntersections = False
features = QGisLayers.features(polyLayer)
total = 100.0 / float(len(features))
for ftPoly in features:
geom = ftPoly.geometry()
attrs = ftPoly.attributes()
count = 0
hasIntersections = False
points = spatialIndex.intersects(geom.boundingBox())
if len(points) > 0:
hasIntersections = True
if hasIntersections:
progress.setText(str(len(points)))
for i in points:
request = QgsFeatureRequest().setFilterFid(i)
ftPoint = pointLayer.getFeatures(request).next()
tmpGeom = QgsGeometry(ftPoint.geometry())
if geom.contains(tmpGeom):
weight = str(ftPoint.attributes()[fieldIdx])
try:
count += float(weight)
except:
pass # ignore fields with non-numeric values
outFeat.setGeometry(geom)
if idxCount == len(attrs):
attrs.append(count)
else:
attrs[idxCount] = count
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
current += 1
progress.setPercentage(int(current * total))
del writer
示例2: processAlgorithm
def processAlgorithm(self, progress):
polyLayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.POLYGONS))
pointLayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.POINTS))
fieldName = self.getParameterValue(self.FIELD)
classFieldName = self.getParameterValue(self.CLASSFIELD)
polyProvider = polyLayer.dataProvider()
pointProvider = pointLayer.dataProvider()
if polyProvider.crs() != pointProvider.crs():
SextanteLog.addToLog(SextanteLog.LOG_WARNING,
"CRS warning: Input layers have non-matching CRS. This may cause unexpected results.")
classFieldIndex = pointProvider.fieldNameIndex(classFieldName)
idxCount, fieldList = utils.findOrCreateField(polyLayer, polyLayer.pendingFields(), fieldName)
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList,
polyProvider.geometryType(), polyProvider.crs())
spatialIndex = utils.createSpatialIndex(pointLayer)
ftPoint = QgsFeature()
outFeat = QgsFeature()
geom = QgsGeometry()
current = 0
hasIntersections = False
features = QGisLayers.features(polyLayer)
total = 100.0 / float(len(features))
for ftPoly in features:
geom = ftPoly.geometry()
atMap = ftPoly.attributes()
classes = []
hasIntersections = False
points = spatialIndex.intersects(geom.boundingBox())
if len(points) > 0:
hasIntersections = True
if hasIntersections:
for i in points:
pointLayer.featureAtId(int(i), ftPoint, True, True)
tmpGeom = QgsGeometry(ftPoint.geometry())
if geom.contains(tmpGeom):
clazz = ftPoint.attributes()[classFieldIndex].toString()
if not clazz in classes:
classes.append(clazz)
outFeat.setGeometry(geom)
if idxCount == len(atMap):
atMap.append(QVariant(len(classes)))
else:
atMap[idxCount] = QVariant(len(classes))
outFeat.setAttributes(atMap)
writer.addFeature(outFeat)
current += 1
progress.setPercentage(current / total)
del writer
示例3: processAlgorithm
def processAlgorithm(self, progress):
polyLayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.POLYGONS))
pointLayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.POINTS))
fieldName = self.getParameterValue(self.FIELD)
polyProvider = polyLayer.dataProvider()
pointProvider = pointLayer.dataProvider()
if polyProvider.crs() != pointProvider.crs():
SextanteLog.addToLog(SextanteLog.LOG_WARNING,
"CRS warning: Input layers have non-matching CRS. This may cause unexpected results.")
idxCount, fieldList = utils.findOrCreateField(polyLayer, polyLayer.pendingFields(), fieldName)
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList,
polyProvider.geometryType(), polyProvider.crs())
spatialIndex = utils.createSpatialIndex(pointLayer)
pointProvider.rewind()
pointProvider.select()
allAttrs = polyLayer.pendingAllAttributesList()
polyLayer.select(allAttrs)
ftPoly = QgsFeature()
ftPoint = QgsFeature()
outFeat = QgsFeature()
geom = QgsGeometry()
current = 0
hasIntersections = False
features = QGisLayers.features(polyLayer)
total = 100.0 / float(len(features))
for ftPoly in features:
geom = ftPoly.geometry()
atMap = ftPoly.attributeMap()
count = 0
hasIntersections = False
points = spatialIndex.intersects(geom.boundingBox())
if len(points) > 0:
hasIntersections = True
if hasIntersections:
for i in points:
pointLayer.featureAtId(int(i), ftPoint, True, False)
tmpGeom = QgsGeometry(ftPoint.geometry())
if geom.contains(tmpGeom):
count += 1
outFeat.setGeometry(geom)
outFeat.setAttributeMap(atMap)
outFeat.addAttribute(idxCount, QVariant(count))
writer.addFeature(outFeat)
current += 1
progress.setPercentage(int(current * total))
del writer
示例4: processAlgorithm
def processAlgorithm(self, progress):
polyLayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.POLYGONS))
pointLayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.POINTS))
fieldName = self.getParameterValue(self.FIELD)
classFieldName = self.getParameterValue(self.CLASSFIELD)
polyProvider = polyLayer.dataProvider()
classFieldIndex = pointLayer.fieldNameIndex(classFieldName)
idxCount, fieldList = utils.findOrCreateField(polyLayer, polyLayer.pendingFields(), fieldName)
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList.toList(),
polyProvider.geometryType(), polyProvider.crs())
spatialIndex = utils.createSpatialIndex(pointLayer)
ftPoint = QgsFeature()
outFeat = QgsFeature()
geom = QgsGeometry()
current = 0
hasIntersections = False
features = QGisLayers.features(polyLayer)
total = 100.0 / float(len(features))
for ftPoly in features:
geom = ftPoly.geometry()
attrs = ftPoly.attributes()
classes = []
hasIntersections = False
points = spatialIndex.intersects(geom.boundingBox())
if len(points) > 0:
hasIntersections = True
if hasIntersections:
for i in points:
request = QgsFeatureRequest().setFilterFid(i)
ftPoint = pointLayer.getFeatures(request).next()
tmpGeom = QgsGeometry(ftPoint.geometry())
if geom.contains(tmpGeom):
clazz = ftPoint.attributes()[classFieldIndex]
if not clazz in classes:
classes.append(clazz)
outFeat.setGeometry(geom)
if idxCount == len(attrs):
attrs.append(len(classes))
else:
attrs[idxCount] = len(classes)
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
current += 1
progress.setPercentage(current / total)
del writer
示例5: processAlgorithm
def processAlgorithm(self, progress):
filename = self.getParameterValue(self.INPUT)
inputLayer = QGisLayers.getObjectFromUri(filename)
method = self.getParameterValue(self.METHOD)
filename = self.getParameterValue(self.INTERSECT)
selectLayer = QGisLayers.getObjectFromUri(filename)
oldSelection = set(inputLayer.selectedFeaturesIds())
index = spatialIndex = utils.createSpatialIndex(inputLayer)
feat = QgsFeature()
geom = QgsGeometry()
selectedSet = []
current = 0
features = QGisLayers.features(selectLayer)
total = 100.0 / float(len(features))
for f in features:
geom = QgsGeometry(f.geometry())
intersects = index.intersects(geom.boundingBox())
for i in intersects:
request = QgsFeatureRequest().setFilterFid(i)
feat = inputLayer.getFeatures(request).next()
tmpGeom = QgsGeometry(feat.geometry())
if geom.intersects(tmpGeom):
selectedSet.append(feat.id())
current += 1
progress.setPercentage(int(current * total))
if method == 1:
selectedSet = list(oldSelection.union(selectedSet))
elif method == 2:
selectedSet = list(oldSelection.difference(selectedSet))
inputLayer.setSelectedFeatures(selectedSet)
self.setOutputValue(self.OUTPUT, filename)
示例6: processAlgorithm
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))
fieldName = self.getParameterValue(self.FIELD_NAME)
outputFile = self.getOutputValue(self.OUTPUT)
values = utils.getUniqueValues(layer, layer.fieldNameIndex(fieldName))
self.createHTML(outputFile, values)
self.setOutputValue(self.TOTAL_VALUES, len(values))
self.setOutputValue(self.UNIQUE_VALUES, ";".join([unicode(v) for v in values]))
示例7: processAlgorithm
def processAlgorithm(self, progress):
layerA = QGisLayers.getObjectFromUri(self.getParameterValue(Difference.INPUT))
layerB = QGisLayers.getObjectFromUri(self.getParameterValue(Difference.OVERLAY))
GEOS_EXCEPT = True
FEATURE_EXCEPT = True
writer = self.getOutputFromName(Difference.OUTPUT).getVectorWriter(layerA.pendingFields(),
layerA.dataProvider().geometryType(), layerA.dataProvider().crs())
inFeatA = QgsFeature()
inFeatB = QgsFeature()
outFeat = QgsFeature()
index = utils.createSpatialIndex(layerB)
selectionA = QGisLayers.features(layerA)
current = 0
total = 100.0 / float(len(selectionA))
for inFeatA in selectionA:
add = True
geom = QgsGeometry(inFeatA.geometry())
diff_geom = QgsGeometry(geom)
attrs = inFeatA.attributes()
intersections = index.intersects(geom.boundingBox())
for i in intersections:
request = QgsFeatureRequest().setFilterFid(i)
inFeatB = layerB.getFeatures(request).next()
tmpGeom = QgsGeometry(inFeatB.geometry())
try:
if diff_geom.intersects(tmpGeom):
diff_geom = QgsGeometry(diff_geom.difference(tmpGeom))
except:
GEOS_EXCEPT = False
add = False
break
if add:
try:
outFeat.setGeometry(diff_geom)
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
except:
FEATURE_EXCEPT = False
continue
current += 1
progress.setPercentage(int(current * total))
del writer
if not GEOS_EXCEPT:
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Geometry exception while computing difference")
if not FEATURE_EXCEPT:
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Feature exception while computing difference")
示例8: processAlgorithm
def processAlgorithm(self, progress):
vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(Intersection.INPUT))
vlayerB = QGisLayers.getObjectFromUri(self.getParameterValue(Intersection.INPUT2))
vproviderA = vlayerA.dataProvider()
fields = utils.combineVectorFields(vlayerA, vlayerB)
writer = self.getOutputFromName(Intersection.OUTPUT).getVectorWriter(fields, vproviderA.geometryType(), vproviderA.crs() )
inFeatA = QgsFeature()
inFeatB = QgsFeature()
outFeat = QgsFeature()
index = utils.createSpatialIndex(vlayerB)
nElement = 0
selectionA = QGisLayers.features(vlayerA)
nFeat = len(selectionA)
for inFeatA in selectionA:
nElement += 1
progress.setPercentage(nElement/float(nFeat) * 100)
geom = QgsGeometry( inFeatA.geometry() )
atMapA = inFeatA.attributes()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
vlayerB.featureAtId( int( id ), inFeatB , True)
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if geom.intersects( tmpGeom ):
atMapB = inFeatB.attributes()
int_geom = QgsGeometry( geom.intersection( tmpGeom ) )
if int_geom.wkbType() == 7:
int_com = geom.combine( tmpGeom )
int_sym = geom.symDifference( tmpGeom )
int_geom = QgsGeometry( int_com.difference( int_sym ) )
try:
outFeat.setGeometry( int_geom )
attrs = []
attrs.extend(atMapA)
attrs.extend(atMapB)
outFeat.setAttributes(attrs)
writer.addFeature( outFeat )
except:
raise GeoAlgorithmExecutionException("Feature exception while computing intersection")
except:
raise GeoAlgorithmExecutionException("Geometry exception while computing intersection")
del writer
示例9: processAlgorithm
def processAlgorithm(self, progress):
vlayerA = QGisLayers.getObjectFromUri(self.getParameterValue(Difference.INPUT))
vlayerB = QGisLayers.getObjectFromUri(self.getParameterValue(Difference.INPUT2))
GEOS_EXCEPT = True
FEATURE_EXCEPT = True
vproviderA = vlayerA.dataProvider()
vproviderB = vlayerB.dataProvider()
fields = vproviderA.fields()
# check for crs compatibility
crsA = vproviderA.crs()
crsB = vproviderB.crs()
if not crsA.isValid() or not crsB.isValid():
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Difference. Invalid CRS. Results might be unexpected")
else:
if crsA != crsB:
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Difference. Non-matching CRSs. Results might be unexpected")
writer = self.getOutputFromName(Difference.OUTPUT).getVectorWriter(fields, vproviderA.geometryType(), vproviderA.crs() )
inFeatA = QgsFeature()
inFeatB = QgsFeature()
outFeat = QgsFeature()
index = utils.createSpatialIndex(vlayerB)
nElement = 0
selectionA = QGisLayers.features(vlayerA)
nFeat = len(selectionA)
for inFeatA in selectionA:
nElement += 1
progress.setPercentage(nElement/float(nFeat) * 100)
add = True
geom = QgsGeometry( inFeatA.geometry() )
diff_geom = QgsGeometry( geom )
atMap = inFeatA.attributes()
intersects = index.intersects( geom.boundingBox() )
for id in intersects:
vlayerB.featureAtId( int( id ), inFeatB , True)
tmpGeom = QgsGeometry( inFeatB.geometry() )
try:
if diff_geom.intersects( tmpGeom ):
diff_geom = QgsGeometry( diff_geom.difference( tmpGeom ) )
except:
GEOS_EXCEPT = False
add = False
break
if add:
try:
outFeat.setGeometry( diff_geom )
outFeat.setAttributes( atMap )
writer.addFeature( outFeat )
except:
FEATURE_EXCEPT = False
continue
del writer
if not GEOS_EXCEPT:
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Geometry exception while computing difference")
if not FEATURE_EXCEPT:
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Feature exception while computing difference")
示例10: processAlgorithm
def processAlgorithm(self, progress):
filename = self.getParameterValue(self.INPUT)
inputLayer = QGisLayers.getObjectFromUri(filename)
method = self.getParameterValue(self.METHOD)
selection = self.getParameterValue(self.USE_SELECTED)
filename = self.getParameterValue(self.INTERSECT)
selectLayer = QGisLayers.getObjectFromUri(filename)
inputProvider = inputLayer.dataProvider()
selectProvider = selectLayer.dataProvider()
index = utils.createSpatialIndex(inputLayer)
inputProvider.select()
selectProvider.select()
feat = QgsFeature()
infeat = QgsFeature()
geom = QgsGeometry()
selectedSet = []
if selection:
features = selectLayer.selectedFeatures()
total = 100.0 / float(len(features))
current = 0
for feat in features:
geom = QgsGeometry(feat.geometry())
intersects = index.intersects(geom.boundingBox())
for i in intersects:
inputProvider.featureAtId(i, infeat, True)
tmpGeom = QgsGeometry(infeat.geometry())
if geom.intersects(tmpGeom):
selectedSet.append(infeat.id())
current += 1
progress.setPercentage(int(current * total))
else:
total = 100.0 / float(selectProvider.featureCount())
current = 0
while selectProvider.nextFeature(feat):
geom = QgsGeometry(feat.geometry())
intersects = index.intersects(geom.boundingBox())
for i in intersects:
inputProvider.featureAtId(i, infeat, True)
tmpGeom = QgsGeometry(infeat.geometry())
if geom.intersects(tmpGeom):
selectedSet.append(infeat.id())
current += 1
progress.setPercentage(int(current * total))
if method == 1:
selectedSet = list(set(inputLayer.selectedFeaturesIds()).union(selectedSet))
elif method == 2:
selectedSet = list(set(inputLayer.selectedFeaturesIds()).difference(selectedSet))
inputLayer.setSelectedFeatures(selectedSet)
self.setOutputValue(self.OUTPUT, filename)
示例11: processAlgorithm
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
output = self.getOutputValue(self.OUTPUT)
fieldName = self.getParameterValue(self.FIELD)
provider = layer.dataProvider()
allAttrs = layer.pendingAllAttributesList()
layer.select(allAttrs)
geomType = self.singleToMultiGeom(provider.geometryType())
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
geomType, provider.crs())
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
outGeom = QgsGeometry()
index = layer.fieldNameIndex(fieldName)
unique = utils.getUniqueValues(layer, index)
current = 0
features = QGisLayers.features(layer)
total = 100.0 / float(len(features) * len(unique))
if not len(unique) == layer.featureCount():
for i in unique:
#provider.rewind()
multi_feature= []
first = True
layer.select(allAttrs)
features = QGisLayers.features(layer)
for inFeat in features:
atMap = inFeat.attributes()
idVar = atMap[index]
if idVar.toString().trimmed() == i.toString().trimmed():
if first:
attrs = atMap
print attrs
first = False
inGeom = QgsGeometry(inFeat.geometry())
vType = inGeom.type()
feature_list = self.extractAsMulti(inGeom)
multi_feature.extend(feature_list)
current += 1
progress.setPercentage(int(current * total))
outFeat.setAttributes(attrs)
outGeom = QgsGeometry(self.convertGeometry(multi_feature, vType))
outFeat.setGeometry(outGeom)
writer.addFeature(outFeat)
del writer
else:
raise GeoAlgorithmExecutionException("Invalid unique ID field")
示例12: processAlgorithm
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.POINTS))
weightField = self.getParameterValue(self.WEIGHT)
uniqueField = self.getParameterValue(self.UID)
weightIndex = layer.fieldNameIndex(weightField)
uniqueIndex = layer.fieldNameIndex(uniqueField)
fieldList = [QgsField("MEAN_X", QVariant.Double, "", 24, 15),
QgsField("MEAN_Y", QVariant.Double, "", 24, 15),
QgsField("UID", QVariant.String, "", 255)
]
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(fieldList,
QGis.WKBPoint, layer.crs())
current = 0
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
means = {}
for feat in features:
current += 1
progress.setPercentage(current * total)
clazz = str(feat.attributes()[uniqueIndex]).strip()
if weightIndex == -1:
weight = 1.00
else:
try:
weight = float(feat.attributes()[weightIndex])
except:
weight = 1.00
if clazz not in means:
means[clazz] = (0,0,0)
cx,cy, totalweight = means[clazz]
geom = QgsGeometry(feat.geometry())
geom = utils.extractPoints(geom)
for i in geom:
cx += i.x() * weight
cy += i.y() * weight
totalweight += weight
means[clazz] = (cx, cy, totalweight)
for clazz, values in means.iteritems():
outFeat = QgsFeature()
cx = values[0] / values[2]
cy = values[1] / values[2]
meanPoint = QgsPoint(cx, cy)
outFeat.setGeometry(QgsGeometry.fromPoint(meanPoint))
outFeat.setAttributes([cx, cy, clazz])
writer.addFeature(outFeat)
del writer
示例13: processAlgorithm
def processAlgorithm(self, progress):
filename = self.getParameterValue(self.INPUT)
layer = QGisLayers.getObjectFromUri(filename)
field = self.getParameterValue(self.FIELD)
method = self.getParameterValue(self.METHOD)
layer.removeSelection()
index = layer.fieldNameIndex(field)
unique = utils.getUniqueValues(layer, index)
featureCount = layer.featureCount()
value = int(self.getParameterValue(self.NUMBER))
if method == 0:
if value > featureCount:
raise GeoAlgorithmExecutionException("Selected number is greater that feature count. Choose lesser value and try again.")
else:
if value > 100:
raise GeoAlgorithmExecutionException("Persentage can't be greater than 100. Set corrent value and try again.")
value = value / 100.0
selran = []
inFeat = QgsFeature()
current = 0
total = 100.0 / float(featureCount * len(unique))
features = QGisLayers.features(layer)
if not len(unique) == featureCount:
for i in unique:
FIDs= []
for inFeat in features:
attrs = inFeat.attributes()
if attrs[index] == QVariant(i):
FIDs.append(inFeat.id())
current += 1
progress.setPercentage(int(current * total))
if method == 1:
selValue = int(round(value * len(FIDs), 0))
else:
selValue = value
if selValue >= len(FIDs):
selFeat = FIDs
else:
selFeat = random.sample(FIDs, selValue)
selran.extend(selFeat)
layer.setSelectedFeatures(selran)
else:
layer.setSelectedFeatures(range(0, featureCount))
self.setOutputValue(self.OUTPUT, filename)
示例14: processAlgorithm
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.POINTS))
output = self.getOutputValue(self.OUTPUT)
provider = layer.dataProvider()
spatialIndex = utils.createSpatialIndex(provider)
provider.rewind()
provider.select()
feat = QgsFeature()
neighbour = QgsFeature()
distance = QgsDistanceArea()
sumDist = 0.00
A = layer.extent()
A = float(A.width() * A.height())
current = 0
total = 100.0 / float(provider.featureCount())
while provider.nextFeature( feat ):
neighbourID = spatialIndex.nearestNeighbor(feat.geometry().asPoint(), 2)[1]
provider.featureAtId(neighbourID, neighbour, True)
sumDist += distance.measureLine(neighbour.geometry().asPoint(), feat.geometry().asPoint())
current += 1
progress.setPercentage(int(current * total))
count = provider.featureCount()
do = float(sumDist) / count
de = float(0.5 / math.sqrt(count / A))
d = float(do / de)
SE = float(0.26136 / math.sqrt(( count ** 2) / A))
zscore = float((do - de) / SE)
data = []
data.append("Observed mean distance: " + unicode(do))
data.append("Expected mean distance: " + unicode(de))
data.append("Nearest neighbour index: " + unicode(d))
data.append("Number of points: " + unicode(count))
data.append("Z-Score: " + unicode(zscore))
self.createHTML(output, data)
self.setOutputValue(self.OBSERVED_MD, float( data[ 0 ].split( ": " )[ 1 ] ) )
self.setOutputValue(self.EXPECTED_MD, float( data[ 1 ].split( ": " )[ 1 ] ) )
self.setOutputValue(self.NN_INDEX, float( data[ 2 ].split( ": " )[ 1 ] ) )
self.setOutputValue(self.POINT_COUNT, float( data[ 3 ].split( ": " )[ 1 ] ) )
self.setOutputValue(self.Z_SCORE, float( data[ 4 ].split( ": " )[ 1 ] ) )
示例15: linearMatrix
def linearMatrix(self, inLayer, inField, targetLayer, targetField, matType, nPoints, progress):
if matType == 0:
self.writer.writerow(["InputID", "TargetID", "Distance"])
else:
self.writer.writerow(["InputID", "MEAN", "STDDEV", "MIN", "MAX"])
index = utils.createSpatialIndex(targetLayer);
inIdx = inLayer.fieldNameIndex(inField)
inLayer.select([inIdx])
outIdx = targetLayer.fieldNameIndex(inField)
outFeat = QgsFeature()
inGeom = QgsGeometry()
outGeom = QgsGeometry()
distArea = QgsDistanceArea()
features = QGisLayers.features(inLayer)
current = 0
total = 100.0 / float(len(features))
for inFeat in features:
inGeom = inFeat.geometry()
inID = inFeat.attributes()[inIdx].toString()
featList = index.nearestNeighbor(inGeom.asPoint(), nPoints)
distList = []
vari = 0.0
for i in featList:
request = QgsFeatureRequest().setFilterFid(i)
outFeat = targetLayer.getFeatures(request).next()
outID = outFeat.attributes()[outIdx].toString()
outGeom = outFeat.geometry()
dist = distArea.measureLine(inGeom.asPoint(), outGeom.asPoint())
if matType == 0:
self.writer.writerow([unicode(inID), unicode(outID), unicode(dist)])
else:
distList.append(float(dist))
if matType == 2:
mean = sum(distList) / len(distList)
for i in distList:
vari += (i - mean) * (i - mean)
vari = math.sqrt(vari / len(distList))
self.writer.writerow([unicode(inID), unicode(mean), unicode(vari), unicode(min(distList)), unicode(max(distList))])
current += 1
progress.setPercentage(int(current * total))