本文整理汇总了Python中processing.core.QGisLayers.QGisLayers.features方法的典型用法代码示例。如果您正苦于以下问题:Python QGisLayers.features方法的具体用法?Python QGisLayers.features怎么用?Python QGisLayers.features使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类processing.core.QGisLayers.QGisLayers
的用法示例。
在下文中一共展示了QGisLayers.features方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convertUnsupportedFormats
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def convertUnsupportedFormats(self, progress):
i = 0
progress.setText("Converting outputs")
for out in self.outputs:
if isinstance(out, OutputVector):
if out.compatible is not None:
layer = QGisLayers.getObjectFromUri(out.compatible)
if layer is None: # for the case of memory layer, if the getCompatible method has been called
continue
provider = layer.dataProvider()
writer = out.getVectorWriter( provider.fields(), provider.geometryType(), layer.crs())
features = QGisLayers.features(layer)
for feature in features:
writer.addFeature(feature)
elif isinstance(out, OutputRaster):
if out.compatible is not None:
layer = QGisLayers.getObjectFromUri(out.compatible)
provider = layer.dataProvider()
writer = QgsRasterFileWriter(out.value)
format = self.getFormatShortNameFromFilename(out.value)
writer.setOutputFormat(format);
writer.writeRaster(layer.pipe(), layer.width(), layer.height(), layer.extent(), layer.crs())
elif isinstance(out, OutputTable):
if out.compatible is not None:
layer = QGisLayers.getObjectFromUri(out.compatible)
provider = layer.dataProvider()
writer = out.getTableWriter(provider.fields())
features = QGisLayers.features(layer)
for feature in features:
writer.addRecord(feature)
progress.setPercentage(100 * i / float(len(self.outputs)))
示例2: processAlgorithm
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def processAlgorithm(self, progress):
hublayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.HUBNAME))
spokelayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.SPOKENAME))
hubattr = self.getParameterValue(self.HUBATTRIBUTE)
spokeattr = self.getParameterValue(self.SPOKEATTRIBUTE)
if hublayer == spokelayer:
raise GeoAlgorithmExecutionException ("Same layer given for both hubs and spokes")
hubindex = hublayer.dataProvider().fieldNameIndex(hubattr)
spokeindex = spokelayer.dataProvider().fieldNameIndex(spokeattr)
outfields = spokelayer.pendingFields()
output = self.getOutputFromName(self.SAVENAME)
out = output.getVectorWriter(outfields, QGis.WKBLineString, spokelayer.crs())
# Scan spoke points
linecount = 0
spokepoints = QGisLayers.features(spokelayer)
i = 0
for spokepoint in spokepoints:
i += 1
spokex = spokepoint.geometry().boundingBox().center().x()
spokey = spokepoint.geometry().boundingBox().center().y()
spokeid = unicode(spokepoint.attributes()[spokeindex])
progress.setPercentage(float(i) / len(spokepoints) * 100)
# Scan hub points to find first matching hub
hubpoints = QGisLayers.features(hublayer)
for hubpoint in hubpoints:
hubid = unicode(hubpoint.attributes()[hubindex])
if hubid == spokeid:
hubx = hubpoint.geometry().boundingBox().center().x()
huby = hubpoint.geometry().boundingBox().center().y()
# Write line to the output file
outfeature = QgsFeature()
outfeature.setAttributes(spokepoint.attributes())
polyline = []
polyline.append(QgsPoint(spokex, spokey))
polyline.append(QgsPoint(hubx, huby))
geometry = QgsGeometry()
outfeature.setGeometry(geometry.fromPolyline(polyline))
out.addFeature(outfeature)
linecount = linecount + 1
break
del out
if linecount <= 0:
raise GeoAlgorithmExecutionException("No spoke/hub matches found to create lines")
示例3: processAlgorithm
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
output = self.getOutputValue(self.OUTPUT)
fieldName = self.getParameterValue(self.FIELD)
geomType = self.singleToMultiGeom(layer.dataProvider().geometryType())
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields().toList(),
geomType, layer.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:
multi_feature= []
first = True
features = QGisLayers.features(layer)
for inFeat in features:
atMap = inFeat.attributes()
idVar = atMap[index]
if unicode(idVar).strip() == unicode(i).strip():
if first:
attrs = atMap
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")
示例4: processAlgorithm
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def processAlgorithm(self, progress):
input = self.getParameterValue(self.INPUT_LAYER)
input2 = self.getParameterValue(self.INPUT_LAYER_2)
output = self.getOutputFromName(self.OUTPUT_LAYER)
field = self.getParameterValue(self.TABLE_FIELD)
field2 = self.getParameterValue(self.TABLE_FIELD_2)
# Layer 1
layer = QGisLayers.getObjectFromUri(input)
provider = layer.dataProvider()
joinField1Index = layer.fieldNameIndex(field)
# Layer 2
layer2 = QGisLayers.getObjectFromUri(input2)
provider2 = layer2.dataProvider()
joinField2Index = layer2.fieldNameIndex(field2)
# Output
outFields = []
outFields.extend(provider.fields())
outFields.extend(provider2.fields())
writer = output.getVectorWriter(outFields, provider.geometryType(), layer.crs())
inFeat = QgsFeature()
inFeat2 = QgsFeature()
outFeat = QgsFeature()
# Create output vector layer with additional attribute
features = QGisLayers.features(layer);
for inFeat in features:
inGeom = inFeat.geometry()
attrs = inFeat.attributes()
joinValue1 = attrs[joinField1Index]
features2 = QGisLayers.features(layer2);
for inFeat2 in features2:
## Maybe it should cache this entries...
attrs2 = inFeat2.attributes()
joinValue2 = attrs2[joinField2Index]
if joinValue1 == joinValue2:
# create the new feature
outFeat.setGeometry(inGeom)
attrs.extend(attrs2)
break;
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
del writer
示例5: processAlgorithm
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def processAlgorithm(self, progress):
source = self.getParameterValue(self.INPUT)
vlayer = QGisLayers.getObjectFromUri(source)
output = self.getOutputFromName(self.OUTPUT)
vprovider = vlayer.dataProvider()
fields = vprovider.fields()
writer = output.getVectorWriter(fields, QGis.WKBPoint, self.crs)
xfieldindex = vlayer.fieldNameIndex(self.getParameterValue(self.XFIELD))
yfieldindex = vlayer.fieldNameIndex(self.getParameterValue(self.YFIELD))
crsId = self.getParameterValue(self.TARGET_CRS)
targetCrs = QgsCoordinateReferenceSystem(crsId)
self.crs = targetCrs
outFeat = QgsFeature()
nElement = 0
features = QGisLayers.features(vlayer)
nFeat = len(features)
for feature in features:
nElement += 1
progress.setPercentage((nElement*100)/nFeat)
attrs = feature.attributes()
try:
x = float(attrs[xfieldindex])
y = float(attrs[yfieldindex])
except:
continue
pt = QgsPoint(x, y)
outFeat.setGeometry(QgsGeometry.fromPoint(pt))
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
del writer
示例6: spatialindex
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def spatialindex(layer):
'''Creates a spatial index for the passed vector layer'''
idx = QgsSpatialIndex()
features = QGisLayers.features(layer)
for ft in features:
idx.insertFeature(ft)
return idx
示例7: processAlgorithm
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields().toList(),
QGis.WKBPolygon, layer.crs())
outFeat = QgsFeature()
current = 0
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
for f in features:
outGeomList = []
if f.geometry().isMultipart():
outGeomList = f.geometry().asMultiPolyline()
else:
outGeomList.append(f.geometry().asPolyline())
polyGeom = self.removeBadLines(outGeomList)
if len(polyGeom) <> 0:
outFeat.setGeometry(QgsGeometry.fromPolygon(polyGeom))
attrs = f.attributes()
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
current += 1
progress.setPercentage(int(current * total))
del writer
示例8: processAlgorithm
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def processAlgorithm(self, progress):
'''Here is where the processing itself takes place'''
#the first thing to do is retrieve the values of the parameters
#entered by the user
inputFilename = self.getParameterValue(self.INPUT_LAYER)
output = self.getOutputFromName(self.OUTPUT_LAYER)
#input layers values are always a string with its location.
#That string can be converted into a QGIS object (a QgsVectorLayer in this case))
#using the Processing.getObject() method
vectorLayer = QGisLayers.getObjectFromUri(inputFilename)
#And now we can process
#First we create the output layer.
#To do so, we call the getVectorWriter method in the Output object.
#That will give as a ProcessingVectorWriter, that we can later use to add features.
provider = vectorLayer.dataProvider()
writer = output.getVectorWriter( provider.fields(), provider.geometryType(), vectorLayer.crs() )
#Now we take the selected features and add them to the output layer
features = QGisLayers.features(vectorLayer)
total = len(features)
i = 0
for feat in features:
writer.addFeature(feat)
progress.setPercentage(100 * i / float(total))
i += 1
del writer
示例9: getUniqueValues
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def getUniqueValues(layer, fieldIndex):
values = []
features = QGisLayers.features(layer)
for feat in features:
if feat.attributes()[fieldIndex] not in values:
values.append(feat.attributes()[fieldIndex])
return values
示例10: processAlgorithm
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
tolerance =self.getParameterValue(self.TOLERANCE)
pointsBefore = 0
pointsAfter = 0
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields().toList(),
layer.wkbType(), layer.crs())
current = 0
selection = QGisLayers.features(layer)
total = 100.0 / float(len(selection))
for f in selection:
featGeometry = QgsGeometry(f.geometry())
attrs = f.attributes()
pointsBefore += self.geomVertexCount(featGeometry)
newGeometry = featGeometry.simplify(tolerance)
pointsAfter += self.geomVertexCount(newGeometry)
feature = QgsFeature()
feature.setGeometry(newGeometry)
feature.setAttributes(attrs)
writer.addFeature(feature)
current += 1
progress.setPercentage(int(current * total))
del writer
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, "Simplify: Input geometries have been simplified from"
+ str(pointsBefore) + " to " + str(pointsAfter) + " points.")
示例11: processAlgorithm
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def processAlgorithm(self, progress):
fieldname = self.getParameterValue(self.FIELD)
output = self.getOutputFromName(self.OUTPUT)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
vprovider = vlayer.dataProvider()
fieldindex = vlayer.fieldNameIndex(fieldname)
fields = vprovider.fields()
fields.append(QgsField("NUM_FIELD", QVariant.Int))
writer = output.getVectorWriter(fields, vprovider.geometryType(), vlayer.crs() )
outFeat = QgsFeature()
inGeom = QgsGeometry()
nElement = 0
classes = {}
features = QGisLayers.features(vlayer)
nFeat = len(features)
for feature in features:
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
inGeom = feature.geometry()
outFeat.setGeometry( inGeom )
atMap = feature.attributes()
clazz = atMap[fieldindex]
if clazz not in classes:
classes[clazz] = len(classes.keys())
atMap.append(classes[clazz])
outFeat.setAttributes(atMap)
writer.addFeature( outFeat )
del writer
示例12: processAlgorithm
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def processAlgorithm(self, progress):
fieldType = self.getParameterValue(self.FIELD_TYPE)
fieldName = self.getParameterValue(self.FIELD_NAME)
fieldLength = self.getParameterValue(self.FIELD_LENGTH)
fieldPrecision = self.getParameterValue(self.FIELD_PRECISION)
output = self.getOutputFromName(self.OUTPUT_LAYER)
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))
provider = layer.dataProvider()
fields = provider.fields()
fields.append(QgsField(fieldName, self.TYPES[fieldType], "", fieldLength, fieldPrecision))
writer = output.getVectorWriter(fields, provider.geometryType(), layer.crs())
outFeat = QgsFeature()
inGeom = QgsGeometry()
nElement = 0
features = QGisLayers.features(layer)
nFeat = len(features)
for inFeat in features:
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
inGeom = inFeat.geometry()
outFeat.setGeometry( inGeom )
atMap = inFeat.attributes()
atMap.append(None)
outFeat.setAttributes(atMap)
writer.addFeature( outFeat )
del writer
示例13: featureExtent
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def featureExtent(self, layer, writer, progress):
current = 0
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
feat = QgsFeature()
for f in features:
rect = f.geometry().boundingBox()
minx = rect.xMinimum()
miny = rect.yMinimum()
maxx = rect.xMaximum()
maxy = rect.yMaximum()
height = rect.height()
width = rect.width()
cntx = minx + (width / 2.0)
cnty = miny + (height / 2.0)
area = width * height
perim = (2 * width) + (2 * height)
rect = [
QgsPoint(minx, miny),
QgsPoint(minx, maxy),
QgsPoint(maxx, maxy),
QgsPoint(maxx, miny),
QgsPoint(minx, miny),
]
geometry = QgsGeometry().fromPolygon([rect])
feat.setGeometry(geometry)
attrs = [minx, miny, maxx, maxy, cntx, cnty, area, perim, height, width]
feat.setAttributes(attrs)
writer.addFeature(feat)
current += 1
progress.setPercentage(int(current * total))
示例14: processAlgorithm
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
geomType = self.multiToSingleGeom(layer.dataProvider().geometryType())
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields().toList(),
geomType, layer.crs())
outFeat = QgsFeature()
inGeom = QgsGeometry()
current = 0
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
for f in features:
inGeom = f.geometry()
attrs = f.attributes()
geometries = self.extractAsSingle(inGeom)
outFeat.setAttributes(attrs)
for g in geometries:
outFeat.setGeometry(g)
writer.addFeature(outFeat)
current += 1
progress.setPercentage(int(current * total))
del writer
示例15: processAlgorithm
# 需要导入模块: from processing.core.QGisLayers import QGisLayers [as 别名]
# 或者: from processing.core.QGisLayers.QGisLayers import features [as 别名]
def processAlgorithm(self, progress):
inLayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))
inField = self.getParameterValue(self.INPUT_FIELD)
targetLayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.TARGET_LAYER))
targetField = self.getParameterValue(self.TARGET_FIELD)
matType = self.getParameterValue(self.MATRIX_TYPE)
nPoints = self.getParameterValue(self.NEAREST_POINTS)
outputFile = self.getOutputValue(self.DISTANCE_MATRIX)
if nPoints < 1:
nPoints = len(QGisLayers.features(targetLayer))
# prepare CSV file writer
csvFile = open(outputFile, "wb")
self.writer = UnicodeWriter(csvFile)
if matType == 0: # Linear distance matrix
self.linearMatrix(inLayer, inField, targetLayer, targetField, matType, nPoints, progress)
elif matType == 1: # Standard distance matrix
self.regularMatrix(inLayer, inField, targetLayer, targetField, nPoints, progress)
elif matType == 2: # Summary distance matrix
self.linearMatrix(inLayer, inField, targetLayer, targetField, matType, nPoints, progress)
csvFile.close()
del self.writer