当前位置: 首页>>代码示例>>Python>>正文


Python VectorWriter.addFeature方法代码示例

本文整理汇总了Python中processing.tools.vector.VectorWriter.addFeature方法的典型用法代码示例。如果您正苦于以下问题:Python VectorWriter.addFeature方法的具体用法?Python VectorWriter.addFeature怎么用?Python VectorWriter.addFeature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在processing.tools.vector.VectorWriter的用法示例。


在下文中一共展示了VectorWriter.addFeature方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: VectorWriter

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]
##[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
开发者ID:GeoCat,项目名称:qgis-geoserver-plugin,代码行数:21,代码来源:vector_hook.py

示例2: QgsPoint

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]
                maxarea = area
        inGeom = tmpGeom
    atMap = inFeat.attributes()
    if QGis.QGIS_VERSION > '2.4':
        outGeom = inGeom.pointOnSurface()
    else:
        outGeom = inGeom.centroid()
    if not inGeom.contains(outGeom):
        # weight point outside the polygon
        # find intersection of horizontal line through the weight pont
        rect = inGeom.boundingBox()
        horiz = QgsGeometry.fromPolyline([QgsPoint(rect.xMinimum(), outGeom.asPoint()[1]), QgsPoint(rect.xMaximum(), outGeom.asPoint()[1])])
        line = horiz.intersection(inGeom)
        if line.isMultipart():
            # find longest intersection
            mline = line.asMultiPolyline()
            l = 0
            for i in range(len(mline)):
                d = sqrt((mline[i][0][0] - mline[i][1][0])**2 + (mline[i][0][1] - mline[i][1][1])**2)
                if d > l:
                    l = d
                    xMid = (mline[i][0][0] + mline[i][1][0]) / 2.0
                    yMid = (mline[i][0][1] + mline[i][1][1]) / 2.0
        else:
            xMid = (line.vertexAt(0).x() + line.vertexAt(1).x()) / 2.0
            yMid = (line.vertexAt(0).y() + line.vertexAt(1).y()) / 2.0
        outGeom = QgsGeometry.fromPoint(QgsPoint(xMid, yMid))
    outFeat.setAttributes(atMap)
    outFeat.setGeometry(outGeom)
    outputLayer.addFeature(outFeat)
开发者ID:spatialthoughts,项目名称:QGIS-Processing,代码行数:32,代码来源:realcentroid_algorithm.py

示例3: VectorWriter

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]
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]
					
	else:
		resg = [Polygon(g.exterior,
				[r for r in g.interiors if Polygon(r).area > Max_area])]

	resgeom = QgsGeometry().fromWkt(dumps(MultiPolygon(resg)))
	
	resfeat.setAttributes(feat.attributes())
	resfeat.setGeometry(resgeom)	
	writer.addFeature(resfeat)		

del writer
开发者ID:SIGISLV,项目名称:QGIS-Processing,代码行数:32,代码来源:Fill_holes.py

示例4: VectorWriter

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]
##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))
开发者ID:cayetanobv,项目名称:QGIS,代码行数:32,代码来源:centroids.py

示例5: VectorWriter

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]
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
开发者ID:nakijun,项目名称:qgis-scripts,代码行数:32,代码来源:Reproject+Vector+Layers.py

示例6:

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]
  else:
    polygon = geom.asPolygon()
    polygon_area = area.measurePolygon(polygon[0])

  # calculated area is in sq. metres
  if units_selection == 'sq_km':
    final_area = polygon_area / 1e6
  elif units_selection == 'sq_ft':
    final_area = area.convertMeasurement(
        polygon_area, QGis.Meters, QGis.Feet, True)[0]
  elif units_selection == 'sq_miles':
    final_area = area.convertMeasurement(
        polygon_area, QGis.Meters, QGis.Feet, True)[0] / (5280.0 * 5280.0)
  elif units_selection == 'sq_nm':
    final_area = area.convertMeasurement(
        polygon_area, QGis.Meters, QGis.NauticalMiles, True)[0]
  elif units_selection == 'sq_degrees':
    final_area = area.convertMeasurement(
        polygon_area, QGis.Meters, QGis.Degrees, True)[0]
  else:
    final_area = polygon_area

  attrs = feat.attributes()
  attrs.append(final_area)
  out_f.setGeometry(geom)
  out_f.setAttributes(attrs)
  writer.addFeature(out_f)

progress.setPercentage(100)
del writer
开发者ID:SIGISLV,项目名称:QGIS-Processing,代码行数:32,代码来源:ellipsoidal_area.py

示例7: createSample

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]

#.........这里部分代码省略.........
        #Open layer sample 
        layer_sample = processing.getObject(Vector_samples)
        #Get index fields
        idx_field_class = layer_sample.fieldNameIndex(Classes_field)
        #iniciar variaveis auxiliares
        self.classes=[]
        self.training=[]
        #Get names fields sample
        layer_features = layer_sample.getFeatures()
        fields = layer_sample.pendingFields()
        #Get names fields sample
        fields_names = [str(i.name()) for i in fields]
        #Remover field class
        fields_names.remove(Classes_field)
        #Loop about features sample
        for feat in layer_features:
            #Get values attibutes
            attributes = feat.attributes()
            #Remove values classes e add in variable
            v_class = attributes.pop(idx_field_class)
            #Append value class
            self.classes.append(v_class)
            #Create dict from attr
            atr = dict(zip(fields_names, attributes))
            #Append in training
            self.training.append(atr)
            
    def createDatas(self):
        '''
        Input datas vector
        Create array from vector 
        Output datas (list(dict))
        '''
        
        #Open layer datas
        self.layer_datas = processing.getObject(Vector_datas)

        #iniciar variaveis auxiliares
        self.datas=[]
        #Get names fields sample
        features_datas = self.layer_datas.getFeatures()
        #Get fields vector datas
        fields = self.layer_datas.pendingFields()
        #Get names fields sample
        fields_names = [str(i.name()) for i in fields]
        #Loop features datas vector
        for feat in features_datas:
            #create datas from dict
            atr = dict(zip(fields_names, feat.attributes()))
            self.datas.append(atr)
  
    def classifierTree(self,Max_depth):
        '''
        Create model tree 
        Input training (list(dicy)), class (list) and datas (list(dict))
        Output list with classification of Datas
        '''
    
        #Create fit transform
        trans_train = vec.fit_transform(self.training).toarray()
        del(self.training)
        trans_datas = vec.fit_transform(self.datas).toarray()
        
        #Choose type classification
        clf = tree.DecisionTreeClassifier( max_depth = Max_depth)
        #Crate model classification tree
        modelTree = clf.fit(trans_train, self.classes)
        print 'max_n_classes, ', modelTree.tree_.max_n_classes
        print 'node_count: ', modelTree.tree_.node_count
        print 'min_density: ', modelTree.tree_.min_density
        print 'n_outputs: ', modelTree.tree_.n_outputs
        print 'n_features: ', modelTree.tree_.n_features
        print 'n__classes: ', modelTree.tree_.n_classes
        print 'n_samples: ', modelTree.tree_.n_samples
    
        del(trans_train)
        del(self.classes)
        #Apply model classification in Datas
        self.classificationDatas = modelTree.predict(trans_datas)
        
        with open("/home/ruiz/tree.dot", 'w') as f:
            f = tree.export_graphviz(modelTree, out_file=f)
    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)
开发者ID:RuizGeo,项目名称:classification_decision_tree,代码行数:104,代码来源:classification_by_decision_tree.py

示例8: freq_min_max

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]
    if count == 0:
        majority = 0
        minority = 0
        majority_p = 0
        minority_p = 0
    else:
        minority, majority = freq_min_max(freq)
        minority = int(minority)
        majority = int(majority)
        minority_p = float(freq[minority]) / count
        majority_p = float(freq[majority]) / count

    # write to layer
    outFeat.setGeometry(feat.geometry())
    attrs = feat.attributes() + [majority, majority_p, minority, minority_p]
    outFeat.setAttributes(attrs)
    layer_writer.addFeature(outFeat)

    # write to table
    row = [feat[id_field], majority]
    for v in values:
        if v in freq:
            row.append(float(freq[v]) / count)
        else:
            row.append(0)
    table_writer.addRecord(row)

progress.setPercentage(100)
del table_writer
del layer_writer
开发者ID:SIGISLV,项目名称:QGIS-Processing,代码行数:32,代码来源:FrequencyStats.py

示例9: range

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]
					  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))]
		
		geomlength.sort(key=itemgetter(1))
		
		if To_keep == 1:
			featres.setGeometry(geoms[geomlength[-1][0]])
		else: 
			geomres = [geoms[i].asPolygon() for i,a in geomlength[-1 * To_keep]]
			featres.setGeometry(QgsGeometry.fromMultiPolygon(geomres))
		
		writer.addFeature(featres)
		
	else:
		writer.addFeature(feat)

del writer
开发者ID:SIGISLV,项目名称:QGIS-Processing,代码行数:32,代码来源:Keep_n_biggest_parts.py

示例10: VectorWriter

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]
##[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
开发者ID:Ezio47,项目名称:qgis-geoserver-plugin,代码行数:21,代码来源:vector_hook.py

示例11: SequenceGenerator

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]
            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())
    attributes = in_feature.attributes()
    attributes.append(n[0])
开发者ID:anitagraser,项目名称:QGIS-Processing-tools,代码行数:33,代码来源:compute_flows_between_cells_from_trajectories.py

示例12: or

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]
            # l'intersection se fait avec le polygone bufferise
            if not no_blank or (no_blank and rectangle.intersects(buffer_geom)):
                id_tile += 1
                id_poly_tile += 1
                new_feat = QgsFeature()
                new_feat.setGeometry(rectangle)
                # attributs standards
                attribute_values = feature.attributes()[:]                                              
                # attributs supplementaires
                attribute_values.extend([id_poly, id_tile, id_poly_tile, row_poly_tile, col_poly_tile]) 
                # attribut supplementaire pour tri
                if ord_field:
                    attribute_values.append('{}#{:04d}'.format(feature[ord_field], id_poly_tile))     
                # attributs supplementaires coord dalle
                if tile_bound:
                    attribute_values.extend([min_x_tile, max_x_tile, min_y_tile, max_y_tile])           
                # attributs supplementaires coord enveloppe
                if poly_bound:
                    attribute_values.extend([min_x_poly, max_x_poly, min_y_poly, max_y_poly])           

                # ajoute les geometries et valeurs des enregistrements
                new_feat.setAttributes(attribute_values)
                vw_grid.addFeature(new_feat)
del vw_grid

# pour memoire :
#QMessageBox.information(None, 'DEBUGn: ' , 'texte') # pas recommande !
#progress.setInfo('texte')
#progress.setText('texte')
#raise GeoAlgorithmExecutionException('texte')
开发者ID:sigvar,项目名称:grille,代码行数:32,代码来源:couche_de_couverture.py

示例13: VectorWriter

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]
    cell_feature.setAttributes(ret)
    centroid_features[idx_side] = cell_feature

#. write features
cell_writer = VectorWriter(Output_layer, None, cell_fields, QGis.WKBPolygon, input_layer.crs())
for idx_side in xrange(DEFAULT_SEGS):
    cell_feature = centroid_features[idx_side]
    value = cell_feature.attributes()[3]
    linear_trans_value = (value - minVal) / (maxVal - minVal);
    adjusted_radius = linear_trans_value * radius
    if adjusted_radius > 0:
        from_deg = (idx_side * step_angle) - half_step
        to_deg = ((idx_side + 1) * step_angle) - half_step
        cell = create_cell(center_point, from_deg, to_deg, adjusted_radius)
        cell_feature.setGeometry(cell)
        cell_writer.addFeature(cell_feature)

del cell_writer

#. write anchor      
cell_fields = QgsFields()
cell_fields.append(QgsField("distance", QVariant.Double))
cell_fields.append(QgsField("direction", QVariant.String))
anchor_writer = VectorWriter(Output_Anchor, None, cell_fields, QGis.WKBLineString, input_layer.crs())

radius_step = radius / 5
center =  QgsGeometry.fromPoint(center_point)
for idx_side in xrange(5):
    buffer_radius = radius_step * (idx_side + 1)
    anchor_feature = QgsFeature(cell_fields)
    anchor_feature.setGeometry(center.buffer(buffer_radius, 32))
开发者ID:dassouki,项目名称:qgis-scripts,代码行数:33,代码来源:Create+WindRose+Maps.py

示例14: QgsFields

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]
 *                                                                         *
 ***************************************************************************/
"""
##[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
开发者ID:dassouki,项目名称:qgis-scripts,代码行数:32,代码来源:Vector+Fields+Case+Converter.py

示例15: Grid

# 需要导入模块: from processing.tools.vector import VectorWriter [as 别名]
# 或者: from processing.tools.vector.VectorWriter import addFeature [as 别名]
grid = Grid(bbox,max_radius)
print("Inserting {} points ...".format(len(points)))
grid.insert_points(points)
print("Redistributing {} points ...".format(len(points)))
grid.redistribute_points(points)

fields = [QgsField('GROUP', QVariant.Int)]
geom_type = 1 # point 
writer_pts = VectorWriter(grouped_points, None, fields, geom_type, l.crs() )
writer_centroids = VectorWriter(group_centroids, None, fields, geom_type, l.crs() )

print("Writing {} groups ...".format(len(grid.resulting_groups)))

for id,g in enumerate(grid.resulting_groups):
    fet2 = QgsFeature()
    fet2.setGeometry(QgsGeometry.fromPoint(g.centroid))
    fet2.setAttributes([id])
    writer_centroids.addFeature(fet2)
    for pt in g.points:
        fet = QgsFeature()
        fet.setGeometry(QgsGeometry.fromPoint(pt))
        fet.setAttributes([id])
        writer_pts.addFeature(fet)
    
    
    
del writer_pts
del writer_centroids


开发者ID:anitagraser,项目名称:QGIS-Processing-tools,代码行数:30,代码来源:group_points_in_space.py


注:本文中的processing.tools.vector.VectorWriter.addFeature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。