fTools: option to select create new shape or update existing layer when

exporting geometry column
This commit is contained in:
Alexander Bruy 2012-02-02 10:15:59 +02:00
parent 8fda99366b
commit 42617a0721
2 changed files with 204 additions and 77 deletions

View File

@ -48,6 +48,9 @@ class GeometryDialog( QDialog, Ui_Dialog ):
QObject.connect( self.toolOut, SIGNAL( "clicked()" ), self.outFile ) QObject.connect( self.toolOut, SIGNAL( "clicked()" ), self.outFile )
if self.myFunction == 1: if self.myFunction == 1:
QObject.connect( self.inShape, SIGNAL( "currentIndexChanged( QString )" ), self.update ) QObject.connect( self.inShape, SIGNAL( "currentIndexChanged( QString )" ), self.update )
elif self.myFunction == 5:
QObject.connect( self.chkWriteShapefile, SIGNAL( "stateChanged( int )" ), self.updateGui )
self.updateGui()
self.manageGui() self.manageGui()
self.success = False self.success = False
self.cancel_close = self.buttonBox_2.button( QDialogButtonBox.Close ) self.cancel_close = self.buttonBox_2.button( QDialogButtonBox.Close )
@ -67,7 +70,7 @@ class GeometryDialog( QDialog, Ui_Dialog ):
if self.inShape.currentText() == "": if self.inShape.currentText() == "":
QMessageBox.information( self, self.tr( "Geometry" ), QMessageBox.information( self, self.tr( "Geometry" ),
self.tr( "Please specify input vector layer" ) ) self.tr( "Please specify input vector layer" ) )
elif self.outShape.text() == "": elif self.outShape.text() == "" and self.myFunction != 5:
QMessageBox.information( self, self.tr( "Geometry" ), QMessageBox.information( self, self.tr( "Geometry" ),
self.tr( "Please specify output shapefile" ) ) self.tr( "Please specify output shapefile" ) )
elif self.lineEdit.isVisible() and self.lineEdit.value() < 0.00: elif self.lineEdit.isVisible() and self.lineEdit.value() < 0.00:
@ -80,7 +83,7 @@ class GeometryDialog( QDialog, Ui_Dialog ):
self.outShape.clear() self.outShape.clear()
self.geometry( self.inShape.currentText(), self.lineEdit.value(), self.cmbField.currentText() ) self.geometry( self.inShape.currentText(), self.lineEdit.value(), self.cmbField.currentText() )
def outFile(self): def outFile( self ):
self.outShape.clear() self.outShape.clear()
(self.shapefileName, self.encoding) = ftools_utils.saveDialog( self ) (self.shapefileName, self.encoding) = ftools_utils.saveDialog( self )
if self.shapefileName is None or self.encoding is None: if self.shapefileName is None or self.encoding is None:
@ -93,31 +96,33 @@ class GeometryDialog( QDialog, Ui_Dialog ):
self.lblCalcType.setVisible( False ) self.lblCalcType.setVisible( False )
self.cmbCalcType.setVisible( False ) self.cmbCalcType.setVisible( False )
self.chkWriteShapefile.setVisible( False )
if self.myFunction == 1: # Singleparts to multipart if self.myFunction == 1: # Singleparts to multipart
self.setWindowTitle( self.tr( "Singleparts to multipart" ) ) self.setWindowTitle( self.tr( "Singleparts to multipart" ) )
self.lineEdit.setVisible( False ) self.lineEdit.setVisible( False )
self.label.setVisible( False ) self.label.setVisible( False )
self.label_2.setText( self.tr( "Output shapefile" ) ) self.lblOutputShapefile.setText( self.tr( "Output shapefile" ) )
self.cmbField.setVisible( True ) self.cmbField.setVisible( True )
self.lblField.setVisible( True ) self.lblField.setVisible( True )
elif self.myFunction == 2: # Multipart to singleparts elif self.myFunction == 2: # Multipart to singleparts
self.setWindowTitle( self.tr( "Multipart to singleparts" ) ) self.setWindowTitle( self.tr( "Multipart to singleparts" ) )
self.lineEdit.setVisible( False ) self.lineEdit.setVisible( False )
self.label.setVisible( False ) self.label.setVisible( False )
self.label_2.setText( self.tr( "Output shapefile" ) ) self.lblOutputShapefile.setText( self.tr( "Output shapefile" ) )
elif self.myFunction == 3: # Extract nodes elif self.myFunction == 3: # Extract nodes
self.setWindowTitle( self.tr( "Extract nodes" ) ) self.setWindowTitle( self.tr( "Extract nodes" ) )
self.lineEdit.setVisible( False ) self.lineEdit.setVisible( False )
self.label.setVisible( False ) self.label.setVisible( False )
elif self.myFunction == 4: # Polygons to lines elif self.myFunction == 4: # Polygons to lines
self.setWindowTitle( self.tr( "Polygons to lines" ) ) self.setWindowTitle( self.tr( "Polygons to lines" ) )
self.label_2.setText( self.tr( "Output shapefile" ) ) self.lblOutputShapefile.setText( self.tr( "Output shapefile" ) )
self.label_3.setText( self.tr( "Input polygon vector layer" ) ) self.label_3.setText( self.tr( "Input polygon vector layer" ) )
self.label.setVisible( False ) self.label.setVisible( False )
self.lineEdit.setVisible( False ) self.lineEdit.setVisible( False )
elif self.myFunction == 5: # Export/Add geometry columns elif self.myFunction == 5: # Export/Add geometry columns
self.setWindowTitle( self.tr( "Export/Add geometry columns" ) ) self.setWindowTitle( self.tr( "Export/Add geometry columns" ) )
self.label_2.setText( self.tr( "Output shapefile" ) ) self.lblOutputShapefile.setText( self.tr( "Output shapefile" ) )
self.label_3.setText( self.tr( "Input vector layer" ) ) self.label_3.setText( self.tr( "Input vector layer" ) )
self.label.setVisible( False ) self.label.setVisible( False )
self.lineEdit.setVisible( False ) self.lineEdit.setVisible( False )
@ -127,9 +132,13 @@ class GeometryDialog( QDialog, Ui_Dialog ):
self.cmbCalcType.addItem( self.tr( "Layer CRS" ) ) self.cmbCalcType.addItem( self.tr( "Layer CRS" ) )
self.cmbCalcType.addItem( self.tr( "Project CRS" ) ) self.cmbCalcType.addItem( self.tr( "Project CRS" ) )
self.cmbCalcType.addItem( self.tr( "Ellipsoid" ) ) self.cmbCalcType.addItem( self.tr( "Ellipsoid" ) )
self.chkWriteShapefile.setVisible( True )
self.chkWriteShapefile.setChecked( False )
self.lblOutputShapefile.setVisible( False )
elif self.myFunction == 7: # Polygon centroids elif self.myFunction == 7: # Polygon centroids
self.setWindowTitle( self.tr( "Polygon centroids" ) ) self.setWindowTitle( self.tr( "Polygon centroids" ) )
self.label_2.setText( self.tr( "Output point shapefile" ) ) self.lblOutputShapefile.setText( self.tr( "Output point shapefile" ) )
self.label_3.setText( self.tr( "Input polygon vector layer" ) ) self.label_3.setText( self.tr( "Input polygon vector layer" ) )
self.label.setVisible( False ) self.label.setVisible( False )
self.lineEdit.setVisible( False ) self.lineEdit.setVisible( False )
@ -149,7 +158,7 @@ class GeometryDialog( QDialog, Ui_Dialog ):
self.lineEdit.setValue( 0 ) self.lineEdit.setValue( 0 )
elif self.myFunction == 11: #Lines to polygons elif self.myFunction == 11: #Lines to polygons
self.setWindowTitle( self.tr( "Lines to polygons" ) ) self.setWindowTitle( self.tr( "Lines to polygons" ) )
self.label_2.setText( self.tr( "Output shapefile" ) ) self.lblOutputShapefile.setText( self.tr( "Output shapefile" ) )
self.label_3.setText( self.tr( "Input line vector layer" ) ) self.label_3.setText( self.tr( "Input line vector layer" ) )
self.label.setVisible( False ) self.label.setVisible( False )
self.lineEdit.setVisible( False ) self.lineEdit.setVisible( False )
@ -158,10 +167,18 @@ class GeometryDialog( QDialog, Ui_Dialog ):
self.label_3.setText( self.tr( "Input layer" ) ) self.label_3.setText( self.tr( "Input layer" ) )
self.label.setVisible( False ) self.label.setVisible( False )
self.lineEdit.setVisible( False ) self.lineEdit.setVisible( False )
self.label_2.setText( self.tr( "Output polygon shapefile" ) ) self.lblOutputShapefile.setText( self.tr( "Output polygon shapefile" ) )
self.resize( 381, 100 ) self.resize( 381, 100 )
self.populateLayers() self.populateLayers()
def updateGui( self ):
if self.chkWriteShapefile.isChecked():
self.lineEdit.setEnabled( True )
self.toolOut.setEnabled( True )
else:
self.lineEdit.setEnabled( False )
self.toolOut.setEnabled( False )
def populateLayers( self ): def populateLayers( self ):
self.inShape.clear() self.inShape.clear()
if self.myFunction == 3 or self.myFunction == 6: if self.myFunction == 3 or self.myFunction == 6:
@ -196,15 +213,23 @@ class GeometryDialog( QDialog, Ui_Dialog ):
else: else:
vlayer = ftools_utils.getVectorLayerByName( myLayer ) vlayer = ftools_utils.getVectorLayerByName( myLayer )
error = False error = False
check = QFile( self.shapefileName )
if check.exists(): if ( self.myFunction == 5 and self.chkWriteShapefile.isChecked() ) or self.myFunction != 5:
if not QgsVectorFileWriter.deleteShapeFile( self.shapefileName ): check = QFile( self.shapefileName )
QMessageBox.warning( self, self.tr( "Geometry"), if check.exists():
self.tr( "Unable to delete existing shapefile." ) ) if not QgsVectorFileWriter.deleteShapeFile( self.shapefileName ):
return QMessageBox.warning( self, self.tr( "Geometry"),
self.tr( "Unable to delete existing shapefile." ) )
return
if self.myFunction == 5 and not self.chkWriteShapefile.isChecked():
self.shapefileName = None
self.encoding = None
self.buttonOk.setEnabled( False ) self.buttonOk.setEnabled( False )
self.testThread = geometryThread( self.iface.mainWindow(), self, self.myFunction, vlayer, myParam, self.testThread = geometryThread( self.iface.mainWindow(), self, self.myFunction,
myField, self.shapefileName, self.encoding, self.cmbCalcType.currentIndex() ) vlayer, myParam, myField, self.shapefileName, self.encoding,
self.cmbCalcType.currentIndex(), self.chkWriteShapefile.isChecked() )
QObject.connect( self.testThread, SIGNAL( "runFinished( PyQt_PyObject )" ), self.runFinishedFromThread ) QObject.connect( self.testThread, SIGNAL( "runFinished( PyQt_PyObject )" ), self.runFinishedFromThread )
QObject.connect( self.testThread, SIGNAL( "runStatus( PyQt_PyObject )" ), self.runStatusFromThread ) QObject.connect( self.testThread, SIGNAL( "runStatus( PyQt_PyObject )" ), self.runStatusFromThread )
QObject.connect( self.testThread, SIGNAL( "runRange( PyQt_PyObject )" ), self.runRangeFromThread ) QObject.connect( self.testThread, SIGNAL( "runRange( PyQt_PyObject )" ), self.runRangeFromThread )
@ -234,20 +259,24 @@ class GeometryDialog( QDialog, Ui_Dialog ):
self.tr( "Unable to delete incomplete shapefile." ) ) self.tr( "Unable to delete incomplete shapefile." ) )
else: else:
if success == "valid_error": if success == "valid_error":
extra = self.tr("One or more features in the output layer may have invalid " extra = self.tr( "One or more features in the output layer may have invalid "
+ "geometry, please check using the check validity tool\n") + "geometry, please check using the check validity tool\n" )
success = True success = True
self.cancel_close.setText( "Close" ) self.cancel_close.setText( "Close" )
QObject.disconnect( self.cancel_close, SIGNAL( "clicked()" ), self.cancelThread ) QObject.disconnect( self.cancel_close, SIGNAL( "clicked()" ), self.cancelThread )
if success: if success:
addToTOC = QMessageBox.question( self, self.tr("Geometry"), if ( self.myFunction == 5 and self.chkWriteShapefile.isChecked() ) or self.myFunction != 5:
self.tr( "Created output shapefile:\n%1\n%2\n\nWould you like to add the new layer to the TOC?" ).arg( unicode( self.shapefileName ) ).arg( extra ), addToTOC = QMessageBox.question( self, self.tr("Geometry"),
QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton ) self.tr( "Created output shapefile:\n%1\n%2\n\nWould you like to add the new layer to the TOC?" ).arg( unicode( self.shapefileName ) ).arg( extra ),
if addToTOC == QMessageBox.Yes: QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton )
if not ftools_utils.addShapeToCanvas( unicode( self.shapefileName ) ): if addToTOC == QMessageBox.Yes:
QMessageBox.warning( self, self.tr( "Geometry"), if not ftools_utils.addShapeToCanvas( unicode( self.shapefileName ) ):
self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( self.shapefileName ) ) ) QMessageBox.warning( self, self.tr( "Geometry"),
self.populateLayers() self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( self.shapefileName ) ) )
self.populateLayers()
else:
QMessageBox.information( self, self.tr( "Geometry" ),
self.tr( "Layer '%1' updated" ).arg( self.inShape.currentText() ) )
else: else:
QMessageBox.warning( self, self.tr( "Geometry" ), self.tr( "Error writing output shapefile." ) ) QMessageBox.warning( self, self.tr( "Geometry" ), self.tr( "Error writing output shapefile." ) )
@ -258,7 +287,8 @@ class GeometryDialog( QDialog, Ui_Dialog ):
self.progressBar.setRange( range_vals[ 0 ], range_vals[ 1 ] ) self.progressBar.setRange( range_vals[ 0 ], range_vals[ 1 ] )
class geometryThread( QThread ): class geometryThread( QThread ):
def __init__( self, parentThread, parentObject, function, vlayer, myParam, myField, myName, myEncoding, myCalcType ): def __init__( self, parentThread, parentObject, function, vlayer, myParam,
myField, myName, myEncoding, myCalcType, myNewShape ):
QThread.__init__( self, parentThread ) QThread.__init__( self, parentThread )
self.parent = parentObject self.parent = parentObject
self.running = False self.running = False
@ -269,6 +299,7 @@ class geometryThread( QThread ):
self.myName = myName self.myName = myName
self.myEncoding = myEncoding self.myEncoding = myEncoding
self.myCalcType = myCalcType self.myCalcType = myCalcType
self.writeShape = myNewShape
def run( self ): def run( self ):
self.running = True self.running = True
@ -477,52 +508,98 @@ class geometryThread( QThread ):
return True return True
def export_geometry_info( self ): def export_geometry_info( self ):
vprovider = self.vlayer.dataProvider() if self.writeShape:
allAttrs = vprovider.attributeIndexes() vprovider = self.vlayer.dataProvider()
vprovider.select( allAttrs ) allAttrs = vprovider.attributeIndexes()
( fields, index1, index2 ) = self.checkGeometryFields( self.vlayer ) vprovider.select( allAttrs )
writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields, ( fields, index1, index2 ) = self.checkGeometryFields( self.vlayer )
vprovider.geometryType(), vprovider.crs() ) writer = QgsVectorFileWriter( self.myName, self.myEncoding, fields,
inFeat = QgsFeature() vprovider.geometryType(), vprovider.crs() )
outFeat = QgsFeature() inFeat = QgsFeature()
inGeom = QgsGeometry() outFeat = QgsFeature()
nFeat = vprovider.featureCount() inGeom = QgsGeometry()
nElement = 0 nFeat = vprovider.featureCount()
nElement = 0
# calculate with: # calculate with:
# 0 - layer CRS # 0 - layer CRS
# 1 - project CRS # 1 - project CRS
# 2 - ellipsoidal # 2 - ellipsoidal
ellips = None ellips = None
crs = None crs = None
coordTransform = None coordTransform = None
if self.myCalcType == 2: if self.myCalcType == 2:
settings = QSettings() settings = QSettings()
ellips = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString() ellips = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString()
crs = self.parent.iface.mapCanvas().mapRenderer().destinationCrs().srsid() crs = self.parent.iface.mapCanvas().mapRenderer().destinationCrs().srsid()
elif self.myCalcType == 1: elif self.myCalcType == 1:
mapCRS = self.parent.iface.mapCanvas().mapRenderer().destinationCrs() mapCRS = self.parent.iface.mapCanvas().mapRenderer().destinationCrs()
layCRS = self.vlayer.crs() layCRS = self.vlayer.crs()
coordTransform = QgsCoordinateTransform( layCRS, mapCRS ) coordTransform = QgsCoordinateTransform( layCRS, mapCRS )
self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0) self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0)
self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, nFeat ) ) self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, nFeat ) )
while vprovider.nextFeature(inFeat): while vprovider.nextFeature(inFeat):
self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement ) self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement )
nElement += 1 nElement += 1
inGeom = inFeat.geometry() inGeom = inFeat.geometry()
if self.myCalcType == 1: if self.myCalcType == 1:
inGeom.transform( coordTransform ) inGeom.transform( coordTransform )
( attr1, attr2 ) = self.simpleMeasure( inGeom, self.myCalcType, ellips, crs ) ( attr1, attr2 ) = self.simpleMeasure( inGeom, self.myCalcType, ellips, crs )
outFeat.setGeometry( inGeom ) outFeat.setGeometry( inGeom )
atMap = inFeat.attributeMap() atMap = inFeat.attributeMap()
outFeat.setAttributeMap( atMap ) outFeat.setAttributeMap( atMap )
outFeat.addAttribute( index1, QVariant( attr1 ) ) outFeat.addAttribute( index1, QVariant( attr1 ) )
outFeat.addAttribute( index2, QVariant( attr2 ) ) outFeat.addAttribute( index2, QVariant( attr2 ) )
writer.addFeature( outFeat ) writer.addFeature( outFeat )
del writer del writer
return True
else: # update existing file
newFields = []
vprovider = self.vlayer.dataProvider()
geomType = self.vlayer.geometryType()
( index1, index2 ) = self.findOrCreateFields()
inFeat = QgsFeature()
inGeom = QgsGeometry()
nFeat = vprovider.featureCount()
nElement = 0
# calculate with:
# 0 - layer CRS
# 1 - project CRS
# 2 - ellipsoidal
ellips = None
crs = None
coordTransform = None
if self.myCalcType == 2:
settings = QSettings()
ellips = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString()
crs = self.parent.iface.mapCanvas().mapRenderer().destinationCrs().srsid()
elif self.myCalcType == 1:
mapCRS = self.parent.iface.mapCanvas().mapRenderer().destinationCrs()
layCRS = self.vlayer.crs()
coordTransform = QgsCoordinateTransform( layCRS, mapCRS )
self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), 0)
self.emit( SIGNAL( "runRange( PyQt_PyObject )" ), ( 0, nFeat ) )
while vprovider.nextFeature(inFeat):
self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement )
nElement += 1
inGeom = inFeat.geometry()
if self.myCalcType == 1:
inGeom.transform( coordTransform )
( attr1, attr2 ) = self.simpleMeasure( inGeom, self.myCalcType, ellips, crs )
changeMap = {}
changeAttributeMap = { index1 : QVariant( attr1 ),
index2 : QVariant( attr2 ) }
changeMap[ inFeat.id() ] = changeAttributeMap
vprovider.changeAttributeValues( changeMap )
return True return True
def polygon_centroids( self ): def polygon_centroids( self ):
@ -854,21 +931,18 @@ class geometryThread( QThread ):
for i in fieldList.keys(): for i in fieldList.keys():
nameList.append( fieldList[ i ].name().toLower() ) nameList.append( fieldList[ i ].name().toLower() )
if geomType == QGis.Polygon: if geomType == QGis.Polygon:
plp = "Poly"
( found, index1 ) = self.checkForField( nameList, "AREA" ) ( found, index1 ) = self.checkForField( nameList, "AREA" )
if not found: if not found:
field = QgsField( "AREA", QVariant.Double, "double", 21, 6, self.tr( "Polygon area" ) ) field = QgsField( "AREA", QVariant.Double, "double", 21, 6, self.tr( "Polygon area" ) )
index1 = len( fieldList.keys() ) index1 = len( fieldList.keys() )
fieldList[ index1 ] = field fieldList[ index1 ] = field
( found, index2 ) = self.checkForField( nameList, "PERIMETER" )
( found, index2 ) = self.checkForField( nameList, "PERIMETER" )
if not found: if not found:
field = QgsField( "PERIMETER", QVariant.Double, "double", 21, 6, self.tr( "Polygon perimeter" ) ) field = QgsField( "PERIMETER", QVariant.Double, "double", 21, 6, self.tr( "Polygon perimeter" ) )
index2 = len( fieldList.keys() ) index2 = len( fieldList.keys() )
fieldList[ index2 ] = field fieldList[ index2 ] = field
elif geomType == QGis.Line: elif geomType == QGis.Line:
plp = "Line"
( found, index1 ) = self.checkForField( nameList, "LENGTH" ) ( found, index1 ) = self.checkForField( nameList, "LENGTH" )
if not found: if not found:
field = QgsField( "LENGTH", QVariant.Double, "double", 21, 6, self.tr( "Line length" ) ) field = QgsField( "LENGTH", QVariant.Double, "double", 21, 6, self.tr( "Line length" ) )
@ -876,12 +950,12 @@ class geometryThread( QThread ):
fieldList[ index1 ] = field fieldList[ index1 ] = field
index2 = index1 index2 = index1
else: else:
plp = "Point"
( found, index1 ) = self.checkForField( nameList, "XCOORD" ) ( found, index1 ) = self.checkForField( nameList, "XCOORD" )
if not found: if not found:
field = QgsField( "XCOORD", QVariant.Double, "double", 21, 6, self.tr( "Point x coordinate" ) ) field = QgsField( "XCOORD", QVariant.Double, "double", 21, 6, self.tr( "Point x coordinate" ) )
index1 = len( fieldList.keys() ) index1 = len( fieldList.keys() )
fieldList[ index1 ] = field fieldList[ index1 ] = field
( found, index2 ) = self.checkForField( nameList, "YCOORD" ) ( found, index2 ) = self.checkForField( nameList, "YCOORD" )
if not found: if not found:
field = QgsField( "YCOORD", QVariant.Double, "double", 21, 6, self.tr( "Point y coordinate" ) ) field = QgsField( "YCOORD", QVariant.Double, "double", 21, 6, self.tr( "Point y coordinate" ) )
@ -889,6 +963,52 @@ class geometryThread( QThread ):
fieldList[ index2 ] = field fieldList[ index2 ] = field
return ( fieldList, index1, index2 ) return ( fieldList, index1, index2 )
def findOrCreateFields( self ):
vprovider = self.vlayer.dataProvider()
fieldList = vprovider.fields()
geomType = self.vlayer.geometryType()
newFields = []
nameList = []
for i in fieldList.keys():
nameList.append( fieldList[ i ].name().toLower() )
if geomType == QGis.Polygon:
( found, index1 ) = self.checkForField( nameList, "AREA" )
if not found:
field = QgsField( "AREA", QVariant.Double, "double", 21, 6, self.tr( "Polygon area" ) )
index1 = len( fieldList.keys() )
newFields.append( field )
( found, index2 ) = self.checkForField( nameList, "PERIMETER" )
if not found:
field = QgsField( "PERIMETER", QVariant.Double, "double", 21, 6, self.tr( "Polygon perimeter" ) )
index2 = len( fieldList.keys() ) + 1
newFields.append( field )
elif geomType == QGis.Line:
( found, index1 ) = self.checkForField( nameList, "LENGTH" )
if not found:
field = QgsField( "LENGTH", QVariant.Double, "double", 21, 6, self.tr( "Line length" ) )
index1 = len( fieldList.keys() )
newFields.append( field )
index2 = index1
else:
( found, index1 ) = self.checkForField( nameList, "XCOORD" )
if not found:
field = QgsField( "XCOORD", QVariant.Double, "double", 21, 6, self.tr( "Point x coordinate" ) )
index1 = len( fieldList.keys() )
newFields.append( field )
( found, index2 ) = self.checkForField( nameList, "YCOORD" )
if not found:
field = QgsField( "YCOORD", QVariant.Double, "double", 21, 6, self.tr( "Point y coordinate" ) )
index2 = len( fieldList.keys() ) + 1
newFields.append( field )
vprovider.addAttributes( newFields )
self.vlayer.updateFieldMap()
return ( index1, index2 )
def extractAsLine( self, geom ): def extractAsLine( self, geom ):
multi_geom = QgsGeometry() multi_geom = QgsGeometry()
temp_geom = [] temp_geom = []

View File

@ -10,7 +10,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>390</width> <width>390</width>
<height>296</height> <height>331</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -63,7 +63,14 @@
<item row="5" column="0" colspan="2"> <item row="5" column="0" colspan="2">
<layout class="QVBoxLayout"> <layout class="QVBoxLayout">
<item> <item>
<widget class="QLabel" name="label_2"> <widget class="QCheckBox" name="chkWriteShapefile">
<property name="text">
<string>Save to new shapefile</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblOutputShapefile">
<property name="text"> <property name="text">
<string>Output point shapefile</string> <string>Output point shapefile</string>
</property> </property>