本文整理汇总了Python中processing.tools.vector.VectorWriter类的典型用法代码示例。如果您正苦于以下问题:Python VectorWriter类的具体用法?Python VectorWriter怎么用?Python VectorWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VectorWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: writeClassification
def writeClassification(self):
#Create vector to write
provider = self.layer_datas.dataProvider()
#fields
fields = provider.fields()
fields=[i for i in fields]
fields.append(QgsField("class", QVariant.Int))
#Create shape writer
self.writer = VectorWriter(Output_classification, None, fields, provider.geometryType(), self.layer_datas.crs())
for i, feat in enumerate(self.layer_datas.getFeatures()):
#Add features write
fet = QgsFeature()
fet.setGeometry(feat.geometry())
attrs=feat.attributes()
attrs.append(int(self.classificationDatas[i]))
fet.setAttributes(attrs)
self.writer.addFeature(fet)
del(self.writer)
示例2: __init__
def __init__(self, donnees_d_entree):
QtCore.QObject.__init__(self)
self.pathshp = donnees_d_entree["pathshp"]
self.mesh = donnees_d_entree["mesh"]
self.x = donnees_d_entree["x"]
self.y = donnees_d_entree["y"]
self.ztri = donnees_d_entree["ztri"]
self.vlayer = ""
self.pasespace = donnees_d_entree["pasdespace"]
self.vitesse = "0"
self.paramvalueX = donnees_d_entree["paramvalueX"]
self.paramvalueY = donnees_d_entree["paramvalueY"]
self.traitementarriereplan = donnees_d_entree["traitementarriereplan"]
fields = donnees_d_entree["champs"]
if self.paramvalueX != None:
fields.append(QgsField("UV", QVariant.Double))
fields.append(QgsField("VV", QVariant.Double))
fields.append(QgsField("norme", QVariant.Double))
fields.append(QgsField("angle", QVariant.Double))
self.vitesse = "1"
if self.traitementarriereplan == 0 or self.traitementarriereplan == 2:
self.writerw1 = QgsVectorFileWriter(
self.pathshp,
None,
donnees_d_entree["champs"],
QGis.WKBPoint,
QgsCoordinateReferenceSystem(str(donnees_d_entree["crs"])),
"ESRI Shapefile",
)
if self.traitementarriereplan == 1 or self.traitementarriereplan == 2:
self.writerw2 = VectorWriter(
donnees_d_entree["fichierdesortie_point"],
None,
donnees_d_entree["champs"],
QGis.WKBMultiPoint,
QgsCoordinateReferenceSystem(str(donnees_d_entree["crs"])),
)
示例3: VectorWriter
##[Example scripts]=group
##input=vector
##output=output vector
from qgis.core import *
from processing.tools.vector import VectorWriter
vectorLayer = processing.getObject(input)
provider = vectorLayer.dataProvider()
writer = VectorWriter(output, None, provider.fields(),
provider.geometryType(), vectorLayer.crs())
features = processing.features(vectorLayer)
writer.addFeature(next(features.iter))
del writer
示例4: VectorWriter
##poly=vector
##output=output vector
from qgis.core import *
from qgis.core import *
from qgis.utils import *
from processing.tools.vector import VectorWriter
from math import sqrt
inputLayer = processing.getObject(poly)
features = processing.features(inputLayer)
fields = inputLayer.pendingFields().toList()
outputLayer = VectorWriter(output, None, fields, QGis.WKBPoint,
inputLayer.crs())
outFeat = QgsFeature()
for inFeat in features:
inGeom = inFeat.geometry()
if inGeom.isMultipart():
# find largest part in case of multipart
maxarea = 0
tmpGeom = QgsGeometry()
for part in inGeom.asGeometryCollection():
area = part.area()
if area > maxarea:
tmpGeom = part
maxarea = area
inGeom = tmpGeom
atMap = inFeat.attributes()
if QGis.QGIS_VERSION > '2.4':
outGeom = inGeom.pointOnSurface()
else:
outGeom = inGeom.centroid()
示例5: VectorWriter
##Results=output vector
from qgis.core import *
from PyQt4.QtCore import *
from processing.tools.vector import VectorWriter
from shapely.geometry import Polygon, MultiPolygon
from shapely.wkb import loads
from shapely.wkt import dumps
polyLayer = processing.getObject(Polygons)
polyPrder = polyLayer.dataProvider()
n = polyLayer.featureCount()
l = 0
writer = VectorWriter(Results, None, polyPrder.fields(),
QGis.WKBMultiPolygon, polyPrder.crs())
resgeom = QgsGeometry()
resfeat = QgsFeature()
for feat in processing.features(polyLayer):
progress.setPercentage(int(100*l/n))
l+=1
g = loads(feat.geometry().asWkb())
if g.geom_type == 'MultiPolygon':
resg = [Polygon(p.exterior,
[r for r in p.interiors if Polygon(r).area > Max_area]) for p in g]
示例6: VectorWriter
##Centroids=name
##Geometry=group
##INPUT_LAYER=vector
##OUTPUT_LAYER=output vector
from qgis.core import QgsWkbTypes, QgsGeometry
from processing.tools.vector import VectorWriter
from processing.tools import dataobjects
layer = dataobjects.getLayerFromString(INPUT_LAYER)
fields = layer.fields()
writer = VectorWriter(OUTPUT_LAYER, 'utf-8', fields, QgsWkbTypes.Point, layer.crs())
features = processing.features(layer)
count = len(features)
if count == 0:
raise GeoAlgorithmExecutionException('Input layer contains no features.')
total = 100.0 / len(features)
for count, f in enumerate(features):
outputFeature = f
if f.hasGeometry():
outputGeometry = f.geometry().centroid()
outputFeature.setGeometry(outputGeometry)
writer.addFeature(outputFeature)
feedback.setProgress(int(count * total))
示例7: Worker_pts
class Worker_pts(QtCore.QObject):
def __init__(self, donnees_d_entree):
QtCore.QObject.__init__(self)
self.pathshp = donnees_d_entree["pathshp"]
self.mesh = donnees_d_entree["mesh"]
self.x = donnees_d_entree["x"]
self.y = donnees_d_entree["y"]
self.ztri = donnees_d_entree["ztri"]
self.vlayer = ""
self.pasespace = donnees_d_entree["pasdespace"]
self.vitesse = "0"
self.paramvalueX = donnees_d_entree["paramvalueX"]
self.paramvalueY = donnees_d_entree["paramvalueY"]
self.traitementarriereplan = donnees_d_entree["traitementarriereplan"]
fields = donnees_d_entree["champs"]
if self.paramvalueX != None:
fields.append(QgsField("UV", QVariant.Double))
fields.append(QgsField("VV", QVariant.Double))
fields.append(QgsField("norme", QVariant.Double))
fields.append(QgsField("angle", QVariant.Double))
self.vitesse = "1"
if self.traitementarriereplan == 0 or self.traitementarriereplan == 2:
self.writerw1 = QgsVectorFileWriter(
self.pathshp,
None,
donnees_d_entree["champs"],
QGis.WKBPoint,
QgsCoordinateReferenceSystem(str(donnees_d_entree["crs"])),
"ESRI Shapefile",
)
if self.traitementarriereplan == 1 or self.traitementarriereplan == 2:
self.writerw2 = VectorWriter(
donnees_d_entree["fichierdesortie_point"],
None,
donnees_d_entree["champs"],
QGis.WKBMultiPoint,
QgsCoordinateReferenceSystem(str(donnees_d_entree["crs"])),
)
def run(self):
strtxt = (
str(ctime())
+ " - Thread - repertoire : "
+ os.path.dirname(self.pathshp)
+ " - fichier : "
+ os.path.basename(self.pathshp)
)
if self.traitementarriereplan == 0:
self.status.emit(strtxt)
else:
progress.setText(strtxt)
fet = QgsFeature()
try:
if True:
if self.paramvalueX == None:
boolvitesse = False
else:
boolvitesse = True
# ------------------------------------- TRaitement de tous les points
if self.pasespace == 0:
noeudcount = len(self.x)
strtxt = str(ctime()) + " - Thread - Traitement des vitesses - " + str(noeudcount) + " noeuds"
if self.traitementarriereplan == 0:
self.status.emit(strtxt)
else:
progress.setText(strtxt)
for k in range(len(self.x)):
if k % 5000 == 0:
strtxt = str(ctime()) + " - Thread - noeud n " + str(k) + "/" + str(noeudcount)
if self.traitementarriereplan == 0:
self.status.emit(strtxt)
else:
progress.setText(strtxt)
if self.traitementarriereplan == 0:
self.progress.emit(int(100.0 * k / noeudcount))
else:
progress.setPercentage(int(100.0 * k / noeudcount))
fet.setGeometry(QgsGeometry.fromPoint(QgsPoint(float(self.x[k]), float(self.y[k]))))
tabattr = []
for l in range(len(self.ztri)):
tabattr.append(float(self.ztri[l][k]))
if boolvitesse:
norme = (
(float(self.ztri[self.paramvalueX][k])) ** 2.0
+ (float(self.ztri[self.paramvalueY][k])) ** 2.0
) ** (0.5)
atanUVVV = math.atan2(
float(self.ztri[self.paramvalueY][k]), float(self.ztri[self.paramvalueX][k])
)
angle = atanUVVV / math.pi * 180.0
if angle < 0:
angle = angle + 360
# angle YML
# angle = atanUVVV*180.0/math.pi+min(atanUVVV,0)/atanUVVV*360.0
#.........这里部分代码省略.........
示例8: populateListFidNode
line = geom.asPolyline()
funcExist = existNodeCheckFid
populateListFidNode(fid, line, l_fid_node, funcExist )
# Remove Exists nodes
for id in reversed( xrange( len( l_fid_node ) ) ):
if l_fid_node[ id ]['exists']:
l_fid_node.pop( id )
# Remove nodes with same FID line
ids_remove = []
for id in xrange( len( l_fid_node )-1 ):
fid1, fid2 = l_fid_node[ id ]['fid'], l_fid_node[ id+1 ]['fid']
if fid1 == fid2:
ids_remove.append( id )
ids_remove.append( id+1 )
ids_remove.reverse()
for id in ids_remove:
l_fid_node.pop( id )
# Output
fields = [ QgsCore.QgsField("fid_line", QtCore.QVariant.Int ) ]
lyrSource = VectorWriter( Nascentes, None, fields, QgsCore.QGis.WKBPoint, lyrRiver.crs() )
for fn in l_fid_node:
feat = QgsCore.QgsFeature()
feat.setAttributes( [ fn['fid'] ])
feat.setGeometry( QgsCore.QgsGeometry.fromPoint( fn['node']) )
lyrSource.addFeature( feat )
del feat
del lyrSource
示例9: QgsFeature
fields.append(QgsField(createUniqueFieldName("MIN", fields), QVariant.Int))
fields.append(QgsField(createUniqueFieldName("MIN_P", fields), QVariant.Double))
outFeat = QgsFeature()
features = processing.features(polygon_layer)
n = len(features)
# get all unique raster values
values = []
for stats in frequency_analysis.itervalues():
freq = stats["freq"]
values = values + [v for (v, f) in freq.iteritems()]
values = sorted(list(set(values)))
print values
layer_writer = VectorWriter(Frequency_analysis_layer, None, fields, provider.geometryType(), polygon_layer.crs())
table_writer = TableWriter(Frequency_analysis_table, None, [id_field, "majority"] + ["value: %d" % v for v in values])
for i, feat in enumerate(features):
progress.setPercentage(int(100 * i / n))
fid = feat.id()
stats = frequency_analysis[fid]
count = stats["count"]
freq = stats["freq"]
if count == 0:
majority = 0
minority = 0
majority_p = 0
minority_p = 0
else:
示例10: len
selected_count = len(selected_layers)
for selected in selected_layers:
layer = processing.getObject(selected)
output_path = os.path.join(Output_Folder, layer.name() + '.shp')
projected += 1
progress.setPercentage(int(100 * projected / selected_count))
# check exist Ovewrite
if os.path.isfile(output_path) and Ovewrite == False:
print "Already exists: " + output_path
continue
trans.setSourceCrs(layer.crs())
# reprojecting layers
writer = VectorWriter(output_path, None, layer.dataProvider().fields(),
layer.dataProvider().geometryType(), dest_crs)
features = processing.features(layer)
for feature in features:
# transform geometry http://www.qgis.org/api/classQgsGeometry.html
geometry = feature.geometry()
geometry.transform(trans)
# create & insert feature
new_feature = QgsFeature()
new_feature.setGeometry(geometry)
new_feature.setAttributes(feature.attributes())
writer.addFeature(new_feature)
del writer
output = selected_count
示例11: VectorWriter
##[Example scripts]=group
##input=vector
##output=output vector
from qgis.core import *
from processing.tools.vector import VectorWriter
vectorLayer = processing.getObject(input)
provider = vectorLayer.dataProvider()
writer = VectorWriter(output, None, provider.fields(),
provider.geometryType(), vectorLayer.crs())
features = processing.features(vectorLayer)
writer.addFeature(features.iter.next())
del writer
示例12: QgsFields
* *
***************************************************************************/
"""
##[My Scripts]=group
##Vector Field Case Converter=name
##Vector_Layer=vector
##Upper_Case=boolean
##Output=output vector
from qgis.core import *
from processing.tools.vector import VectorWriter
vectorLayer = processing.getObject(Vector_Layer)
provider = vectorLayer.dataProvider()
# rebuild fields
new_fields = QgsFields()
for field in provider.fields():
field_name = field.name().upper() if Upper_Case else field.name().lower()
field.setName(field_name)
new_fields.append(field)
# write features
writer = VectorWriter(Output, None, new_fields, provider.geometryType(), vectorLayer.crs())
features = processing.features(vectorLayer)
for feature in features:
writer.addFeature(feature)
del writer
示例13: int
from PyQt4.QtCore import *
from processing.tools.vector import VectorWriter
from operator import itemgetter
To_keep = int(To_keep)
if To_keep < 1:
progress.setText("At least 1 part to keep")
To_keep = 1
polyLayer = processing.getObject(Polygons)
polyPrder = polyLayer.dataProvider()
n = polyLayer.featureCount()
l = 0
writer = VectorWriter(Results, None, polyPrder.fields(),
QGis.WKBMultiPolygon, polyPrder.crs())
for feat in processing.features(polyLayer):
progress.setPercentage(int(100*l/n))
l+=1
geom = feat.geometry()
if geom.isMultipart():
featres = feat
geoms = geom.asGeometryCollection()
geomlength = [(i, geoms[i].area()) for i in range(len(geoms))]
示例14: QgsFeature
p2 = self.id_to_centroid[key[1]][0].geometry().asPoint()
feat = QgsFeature()
feat.setGeometry(QgsGeometry.fromPolyline([p1,p2]))
feat.setAttributes([key[0],key[1],value])
lines.append(feat)
return lines
centroid_layer = processing.getObject(input_cell_centers)
trajectory_layer = processing.getObject(input_trajectories)
sg = SequenceGenerator(centroid_layer,trajectory_layer, weight_field if use_weight_field else None)
fields = [QgsField('FROM', QVariant.Int),
QgsField('TO', QVariant.Int),
QgsField('COUNT', QVariant.Int)]
geom_type = 2
writer = VectorWriter(flow_lines, None, fields, geom_type, centroid_layer.crs() )
for f in sg.create_flow_lines():
writer.addFeature(f)
del writer
fields = centroid_layer.fields()
fields.append( QgsField('COUNT',QVariant.Int))
fields.append( QgsField('COUNT_Q1',QVariant.Int))
fields.append( QgsField('COUNT_Q2',QVariant.Int))
fields.append( QgsField('COUNT_Q3',QVariant.Int))
fields.append( QgsField('COUNT_Q4',QVariant.Int))
writer = VectorWriter(cell_counts, None, fields, 1, centroid_layer.crs() )
for key, value in sg.id_to_centroid.iteritems():
(in_feature, n) = value
out_feature = QgsFeature()
out_feature.setGeometry(in_feature.geometry())
开发者ID:anitagraser,项目名称:QGIS-Processing-tools,代码行数:31,代码来源:compute_flows_between_cells_from_trajectories.py
示例15: GeoAlgorithmExecutionException
(field_name in additional_attributes_tile_bound) or \
(field_name in additional_attributes_poly_bound):
raise GeoAlgorithmExecutionException('Le champ {} existe deja, modifier le code du script ou la table'.format(field_name))
# ajout des attributs supplementaires
for attr in additional_attributes:
grid_fields.append(QgsField(attr, QVariant.Int))
for attr in additional_attributes_ord:
grid_fields.append(QgsField(attr, QVariant.String))
for attr in additional_attributes_tile_bound:
grid_fields.append(QgsField(attr, QVariant.Double))
for attr in additional_attributes_poly_bound:
grid_fields.append(QgsField(attr, QVariant.Double))
# preparation de la couche grille
vw_grid = VectorWriter(output, None, grid_fields, provider.geometryType(), layer.crs())
id_poly = 0
id_tile = 0
# pour tous les polygones
for feature in feats:
progress.setPercentage(int(100 * id_poly / nb_feats))
# get the feature bounding box
bounding_geom = feature.geometry().boundingBox()
min_x_poly = bounding_geom.xMinimum()
max_x_poly = bounding_geom.xMaximum()
min_y_poly = bounding_geom.yMinimum()
max_y_poly = bounding_geom.yMaximum()
buffer_geom = feature.geometry()