How to replace VectorWriter with QgsVectorFileWriter?

المشرف العام

Administrator
طاقم الإدارة
Within QGIS 2.8.1 I found within the Processing Toolbox a script called "Points on crossing lines" which should exactly as it is named. Unfortunately it needs processing.core.VectorWriter which I guess has disappeared in this latest installment of QGIS. I tried to replace the writer with QgsVectorWriter but get the following error message:

"Algorithm [Unnamed algorithm] starting...Index lines...Find crossing points...arguments did not match any overloaded call:QgsVectorFileWriter(QString,QString, QgsFields, QGis.WkbType,QgsCoordinateReferenceSystem, QString driverName="ESRI Shapefile",QStringList datasourceOptions=QStringList(), QStringListlayerOptions=QStringList(), QString newFilename=None,QgsVectorFileWriter.SymbologyExportsymbologyExport=QgsVectorFileWriter.NoSymbology): argument 3 has unexpectedtype 'list' QgsVectorFileWriter(QgsVectorFileWriter): argument 1 hasunexpected type 'unicode' See log for more details" Can you point me at what I am doing wrong?

##Lines=vector##Results=output vectorfrom qgis.core import *from PyQt4.QtCore import *cutLayer = processing.getObject(Lines)cutPrder = cutLayer.dataProvider()n = cutLayer.featureCount()l = 0# build spatial index of linesindex = QgsSpatialIndex()geom_ix = {}progress.setText("Index lines...")for feat in processing.features(cutLayer):progress.setPercentage(int(100*l/n))l+=1index.insertFeature(feat)geom_ix[feat.id()] = feat.geometry().asWkb()# find points on crossing linesprogress.setText("Find crossing points...")l = 0i = 0ptindex = QgsSpatialIndex()pt_ix = {}secgeom = QgsGeometry()featgeom = QgsGeometry()resfeat = QgsFeature()for feat in processing.features(cutLayer):progress.setPercentage(int(100*l/n))l+=1near = index.intersects(feat.geometry().boundingBox())for f in [x for x in near if x != feat.id()]: # exclude self featgeom = feat.geometry() secgeom.fromWkb(geom_ix[f]) if featgeom.crosses(secgeom): crosspts = feat.geometry().intersection(secgeom).asGeometryCollection() for pt in crosspts: i += 1 # index point resfeat.setGeometry(pt) resfeat.setFeatureId(i) ptindex.insertFeature(resfeat) pt_ix = pt.asPoint()feat = QgsFeature()fields = [QgsField("nodeid", QVariant.Int)]writer = QgsVectorFileWriter(Results,None, fields, QGis.WKBPoint, 27700)progress.setText("test")# only save unique pointsprogress.setText("Save unique points...")n = len(pt_ix)featgeom = QgsGeometry()while len(pt_ix) != 0:progress.setPercentage(int(100*(n-len(pt_ix))/n))i = pt_ix.keys()[0]# write pointattrs = feat.setGeometry(featgeom.fromPoint(pt_ix))feat.setAttributes(attrs)writer.addFeature(feat)# delete close pointsnear = ptindex.intersects(buffRect(pt_ix, buff))for pt in near: feat.setFeatureId(pt) feat.setGeometry(featgeom.fromPoint(pt_ix[pt])) deleted = ptindex.deleteFeature(feat) del pt_ix[pt]del writer

أكثر...
 
أعلى