本文整理汇总了Python中sextante.core.QGisLayers.QGisLayers类的典型用法代码示例。如果您正苦于以下问题:Python QGisLayers类的具体用法?Python QGisLayers怎么用?Python QGisLayers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QGisLayers类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: processAlgorithm
def processAlgorithm(self, progress):
fieldtype = self.getParameterValue(self.FIELD_TYPE)
fieldname = self.getParameterValue(self.FIELD_NAME)
output = self.getOutputFromName(self.OUTPUT_LAYER)
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
fields[len(fields)] = QgsField(fieldname, self.TYPES[fieldtype])
writer = output.getVectorWriter(fields, vprovider.geometryType(), vprovider.crs() )
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = vprovider.featureCount()
nElement = 0
features = QGisLayers.features(vlayer)
for inFeat in features:
progress.setPercentage(int((100 * nElement)/nFeat))
nElement += 1
inGeom = inFeat.geometry()
outFeat.setGeometry( inGeom )
atMap = inFeat.attributeMap()
outFeat.setAttributeMap( atMap )
outFeat.addAttribute( len(vprovider.fields()), QVariant() )
writer.addFeature( outFeat )
del writer
开发者ID:Nald,项目名称:Quantum-GIS,代码行数:26,代码来源:AddTableField.py
示例2: processAlgorithm
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.LAYERNAME))
attribute = self.getParameterValue(self.ATTRIBUTE)
idx = layer.fieldNameIndex(attribute)
fields = layer.pendingFields()
fields[idx] = QgsField(fields[idx].name(), QVariant.Double)
output = self.getOutputFromName(self.SAVENAME)
out = output.getVectorWriter(fields, layer.wkbType(), layer.crs())
i = 0
features = QGisLayers.features(layer)
featurecount = len(features)
for feature in features:
i+=1
progress.setPercentage(float(i) / featurecount * 100)
attributes = feature.attributes()
try:
v = unicode(attributes[idx].toString())
if '%' in v:
v = v.replace('%', "")
attributes[idx] = float(attributes[idx]) / float(100)
else:
attributes[idx] = float(attributes[idx])
except:
attributes[idx] = QVariant()
feature.setAttributes(attributes)
out.addFeature(feature)
del out
开发者ID:PepSalehi,项目名称:Quantum-GIS,代码行数:30,代码来源:MMQGISXAlgorithms.py
示例3: processAlgorithm
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
interval = self.getParameterValue(self.INTERVAL)
isPolygon = layer.geometryType() == QGis.Polygon
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
layer.wkbType(), layer.crs())
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
current = 0
for f in features:
featGeometry = QgsGeometry(f.geometry())
attrMap = f.attributes()
newGeometry = self.densifyGeometry(featGeometry, interval, isPolygon)
feature = QgsFeature()
feature.setGeometry(newGeometry)
feature.setAttributes(attrMap)
writer.addFeature(feature)
current += 1
progress.setPercentage(int(current * total))
del writer
开发者ID:sawajid,项目名称:Quantum-GIS,代码行数:26,代码来源:DensifyGeometriesInterval.py
示例4: processAlgorithm
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(QVariant())
outFeat.setAttributes(atMap)
writer.addFeature( outFeat )
del writer
开发者ID:Hardysong,项目名称:Quantum-GIS,代码行数:28,代码来源:AddTableField.py
示例5: exportVectorLayer
def exportVectorLayer(self, orgFilename):
#only export to an intermediate shp if the layer is not file-based.
#We assume that almost all file formats will be supported by ogr
#We also export if there is a selection
if not os.path.exists(orgFilename):
layer = QGisLayers.getObjectFromUri(orgFilename, False)
if layer:
filename = LayerExporter.exportVectorLayer(layer)
else:
layer = QGisLayers.getObjectFromUri(orgFilename, False)
if layer:
useSelection = SextanteConfig.getSetting(SextanteConfig.USE_SELECTED)
if useSelection and layer.selectedFeatureCount() != 0:
filename = LayerExporter.exportVectorLayer(layer)
else:
filename = orgFilename
else:
filename = orgFilename
destFilename = self.getTempFilename()
self.exportedLayers[orgFilename]= destFilename
command = "v.in.ogr"
command += " min_area=-1"
command +=" dsn=\"" + os.path.dirname(filename) + "\""
command +=" layer=" + os.path.basename(filename)[:-4]
command +=" output=" + destFilename;
command +=" --overwrite -o"
return command
开发者ID:mokerjoke,项目名称:Quantum-GIS,代码行数:27,代码来源:GrassAlgorithm.py
示例6: getSafeExportedLayers
def getSafeExportedLayers(self):
'''Returns not the value entered by the user, but a string with semicolon-separated filenames
which contains the data of the selected layers, but saved in a standard format (currently
shapefiles for vector layers and GeoTiff for raster) so that they can be opened by most
external applications.
If there is a selection and SEXTANTE is configured to use just the selection, if exports
the layer even if it is already in a suitable format.
Works only if the layer represented by the parameter value is currently loaded in QGIS.
Otherwise, it will not perform any export and return the current value string.
If the current value represents a layer in a suitable format, it does no export at all
and returns that value.
Currently, it works just for vector layer. In the case of raster layers, it returns the
parameter value.
The layers are exported just the first time the method is called. The method can be called
several times and it will always return the same string, performing the export only the first time.'''
if self.exported:
return self.exported
self.exported = self.value
layers = self.value.split(";")
if layers == None or len(layers) == 0:
return self.value
if self.datatype == ParameterMultipleInput.TYPE_RASTER:
for layerfile in layers:
layer = QGisLayers.getObjectFromUri(layerfile, False)
if layer:
filename = LayerExporter.exportRasterLayer(layer)
self.exported = self.exported.replace(layerfile, filename)
return self.exported
else:
for layerfile in layers:
layer = QGisLayers.getObjectFromUri(layerfile, False)
if layer:
filename = LayerExporter.exportVectorLayer(layer)
self.exported = self.exported.replace(layerfile, filename)
return self.exported
开发者ID:Nald,项目名称:Quantum-GIS,代码行数:35,代码来源:ParameterMultipleInput.py
示例7: 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
开发者ID:sawajid,项目名称:Quantum-GIS,代码行数:60,代码来源:PointsInPolygonUnique.py
示例8: processAlgorithm
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
provider = layer.dataProvider()
geomType = self.multiToSingleGeom(provider.geometryType())
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(layer.pendingFields(),
geomType, layer.crs())
outFeat = QgsFeature()
inGeom = QgsGeometry()
current = 0
features = QGisLayers.features(layer)
total = 100.0 / float(len(features))
for inFeat in features:
inGeom = inFeat.geometry()
atMap = inFeat.attributes()
features = self.extractAsSingle(inGeom)
outFeat.setAttributes(atMap)
for f in features:
outFeat.setGeometry(f)
writer.addFeature(outFeat)
current += 1
progress.setPercentage(int(current * total))
del writer
开发者ID:geonux,项目名称:Quantum-GIS,代码行数:31,代码来源:MultipartToSingleparts.py
示例9: getMinCoveringExtent
def getMinCoveringExtent(self):
first = True
found = False
for param in self.params:
if param.value:
if isinstance(param, (ParameterRaster, ParameterVector)):
if isinstance(param.value, (QgsRasterLayer, QgsVectorLayer)):
layer = param.value
else:
layer = QGisLayers.getObjectFromUri(param.value)
if layer:
found = True
self.addToRegion(layer, first)
first = False
elif isinstance(param, ParameterMultipleInput):
layers = param.value.split(";")
for layername in layers:
layer = QGisLayers.getObjectFromUri(layername, first)
if layer:
found = True
self.addToRegion(layer, first)
first = False
if found:
return str(self.xmin) + "," + str(self.xmax) + "," + str(self.ymin) + "," + str(self.ymax)
else:
return None
开发者ID:Hardysong,项目名称:Quantum-GIS,代码行数:26,代码来源:ExtentSelectionPanel.py
示例10: processAlgorithm
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.getOutputValue(self.OUTPUT_LAYER)
# input layers vales are always a string with its location.
# That string can be converted into a QGIS object (a QgsVectorLayer in
# this case) using the Sextante.getObjectFromUri() method.
vectorLayer = QGisLayers.getObjectFromUri(inputFilename)
# And now we can process
# First we create the output layer. The output value entered by the user
# is a string containing a filename, so we can use it directly
settings = QSettings()
systemEncoding = settings.value( "/UI/encoding", "System" )
provider = vectorLayer.dataProvider()
writer = QgsVectorFileWriter(output,
systemEncoding,
provider.fields(),
provider.geometryType(),
provider.crs()
)
# Now we take the features from input layer and add them to the output.
# Method features() returns an iterator, considiring the selection that
# might exisist in layer and SEXTANTE configuration that indicates
# should algorithm use only selected features or all of them
features = QGisLayers.features(vectorLayer)
for f in features:
writer.addFeature(f)
开发者ID:ajdunlap,项目名称:Quantum-GIS,代码行数:34,代码来源:ExampleAlgorithm.py
示例11: 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
开发者ID:rgsena,项目名称:Quantum-GIS,代码行数:60,代码来源:PointsInPolygonWeighted.py
示例12: processAlgorithm
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 Sextante.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 SextanteVectorWriter, 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
开发者ID:Adam-Brown,项目名称:Quantum-GIS,代码行数:30,代码来源:SaveSelectedFeatures.py
示例13: 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
开发者ID:pka,项目名称:qgisenterprise-sextante-plugin,代码行数:60,代码来源:PointsInPolygon.py
示例14: processAlgorithm
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(), vprovider.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].toString()
if clazz not in classes:
classes[clazz] = len(classes.keys())
atMap.append(QVariant(classes[clazz]))
outFeat.setAttributes(atMap)
writer.addFeature( outFeat )
del writer
开发者ID:sawajid,项目名称:Quantum-GIS,代码行数:28,代码来源:EquivalentNumField.py
示例15: processAlgorithm
def processAlgorithm(self, progress):
layer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT_LAYER))
valuesFieldName = self.getParameterValue(self.VALUES_FIELD_NAME)
categoriesFieldName = self.getParameterValue(self.CATEGORIES_FIELD_NAME)
output = self.getOutputFromName(self.OUTPUT)
valuesField = layer.fieldNameIndex(valuesFieldName)
categoriesField = layer.fieldNameIndex(categoriesFieldName)
features = QGisLayers.features(layer)
nFeat = len(features)
values = {}
for feat in features:
attrs = feat.attributes()
value = float(attrs[valuesField].toDouble()[0])
cat = unicode(attrs[categoriesField].toString())
if cat not in values:
values[cat] = []
values[cat].append(value)
fields = [QgsField("category", QVariant.String), QgsField("mean", QVariant.Double), QgsField("variance", QVariant.Double)]
writer = output.getTableWriter(fields)
for cat, value in values.items():
n, min_max, mean, var, skew, kurt = stats.describe(value)
record = [cat, mean, math.sqrt(var)]
writer.addRecord(record)
开发者ID:badcock4412,项目名称:Quantum-GIS,代码行数:26,代码来源:StatisticsByCategories.py
示例16: processAlgorithm
def processAlgorithm(self, progress):
vlayer = QGisLayers.getObjectFromUri(self.getParameterValue(self.INPUT))
output = self.getOutputFromName(self.OUTPUT)
vprovider = vlayer.dataProvider()
allAttrs = vprovider.attributeIndexes()
vprovider.select( allAttrs )
fields = vprovider.fields()
writer = output.getVectorWriter(fields, QGis.WKBLineString, vprovider.crs() )
inFeat = QgsFeature()
outFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = vprovider.featureCount()
nElement = 0
features = QGisLayers.features(layer)
for feature in features:
nElement += 1
progress.setPercentage((nElement*100)/nFeat)
inGeom = feature.geometry()
atMap = feature.attributeMap()
segments = self.extractAsSingleSegments( inGeom )
outFeat.setAttributeMap( atMap )
for segment in segments:
outFeat.setGeometry(segment)
writer.addFeature(outFeat)
del writer
开发者ID:Nald,项目名称:Quantum-GIS,代码行数:25,代码来源:Explode.py
示例17: processAlgorithm
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))
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].toString())
y = float(attrs[yfieldindex].toString())
except:
continue
pt = QgsPoint(x, y)
outFeat.setGeometry(QgsGeometry.fromPoint(pt))
outFeat.setAttributes(attrs)
writer.addFeature(outFeat)
del writer
开发者ID:badcock4412,项目名称:Quantum-GIS,代码行数:29,代码来源:PointsLayerFromTable.py
示例18: handleAlgorithmResults
def handleAlgorithmResults(alg, progress, showResults = True):
wrongLayers = []
htmlResults = False;
progress.setText("Loading resulting layers")
i = 0
for out in alg.outputs:
progress.setPercentage(100 * i / float(len(alg.outputs)))
if out.hidden or not out.open:
continue
if isinstance(out, (OutputRaster, OutputVector, OutputTable)):
try:
if out.value.startswith("memory:"):
layer = out.memoryLayer
QgsMapLayerRegistry.instance().addMapLayers([layer])
else:
if SextanteConfig.getSetting(SextanteConfig.USE_FILENAME_AS_LAYER_NAME):
name = os.path.basename(out.value)
else:
name = out.description
QGisLayers.load(out.value, name, alg.crs, RenderingStyles.getStyle(alg.commandLineName(),out.name))
except Exception, e:
wrongLayers.append(out)
#QMessageBox.critical(None, "Error", str(e))
elif isinstance(out, OutputHTML):
SextanteResults.addResult(out.description, out.value)
htmlResults = True
开发者ID:jesusjl,项目名称:Quantum-GIS,代码行数:26,代码来源:SextantePostprocessing.py
示例19: convertUnsupportedFormats
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)))
开发者ID:Hardysong,项目名称:Quantum-GIS,代码行数:31,代码来源:GeoAlgorithm.py
示例20: 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)
开发者ID:Hardysong,项目名称:Quantum-GIS,代码行数:35,代码来源:SelectByLocation.py
注:本文中的sextante.core.QGisLayers.QGisLayers类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论