Index: python/plugins/fTools/tools/doJoinAttributes.py =================================================================== --- python/plugins/fTools/tools/doJoinAttributes.py (revision 13307) +++ python/plugins/fTools/tools/doJoinAttributes.py (working copy) @@ -101,12 +101,16 @@ useTable = True joinField = self.joinField.currentText() outPath = self.outShape.text() - self.compute(inName, inField, joinName, joinField, outPath, keep, useTable, self.progressBar) + res = self.compute(inName, inField, joinName, joinField, outPath, keep, useTable, self.progressBar) self.outShape.clear() - addToTOC = QMessageBox.question(self, self.tr("Join Attributes"), self.tr("Created output shapefile:\n%1\n\nWould you like to add the new layer to the TOC?").arg( unicode(self.shapefileName) ), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton) - if addToTOC == QMessageBox.Yes: - if not ftools_utils.addShapeToCanvas( unicode( outPath ) ): - QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ).arg( unicode( outPath ) )) + if res: + addToTOC = QMessageBox.question(self, self.tr("Join Attributes"), + self.tr("Created output shapefile:\n%1\n\nWould you like to add the new layer to the TOC?") + .arg( unicode(self.shapefileName) ), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton) + if addToTOC == QMessageBox.Yes: + if not ftools_utils.addShapeToCanvas( unicode( outPath ) ): + QMessageBox.warning( self, self.tr("Geoprocessing"), self.tr( "Error loading output shapefile:\n%1" ) + .arg( unicode( outPath ) )) self.progressBar.setValue(0) def outFile(self): @@ -171,12 +175,21 @@ seq = range(0, len(fieldList1) + len(fieldList2)) fieldList1.extend(fieldList2) fieldList1 = dict(zip(seq, fieldList1)) + # check for correct field names + longNames = ftools_utils.checkFieldNameLenght( fieldList1 ) + if not longNames.isEmpty(): + QMessageBox.warning( self, self.tr( 'Incorrect field names' ), + self.tr( 'Following field names are longer then 10 characters:\n%1' ) + .arg( longNames.join( '\n' ) ) ) + return False sRs = provider1.crs() progressBar.setValue(13) check = QFile(self.shapefileName) if check.exists(): if not QgsVectorFileWriter.deleteShapeFile(self.shapefileName): - return + QMessageBox.warning( self, self.tr( 'Error deleting shapefile' ), + self.tr( "Can't delete existing shapefile\n%1" ).arg( self.shapefileName ) ) + return False writer = QgsVectorFileWriter(self.shapefileName, self.encoding, fieldList1, provider1.geometryType(), sRs) inFeat = QgsFeature() outFeat = QgsFeature() @@ -215,6 +228,7 @@ nElement += 1 progressBar.setValue(nElement) del writer + return True def createFieldList(self, table, joinField): fieldList = {} @@ -236,14 +250,3 @@ fieldList[item] = field item = item + 1 return (fieldList, index2) - - def testForUniqueness(self, fieldList1, fieldList2): - changed = True - while changed: - changed = False - for i in fieldList1: - for j in fieldList2: - if j.name() == i.name(): - j = ftools_utils.createUniqueFieldName(j) - changed = True - return fieldList2 Index: python/plugins/fTools/tools/doSpatialJoin.py =================================================================== --- python/plugins/fTools/tools/doSpatialJoin.py (revision 13307) +++ python/plugins/fTools/tools/doSpatialJoin.py (working copy) @@ -86,10 +86,13 @@ outName = outPath.right((outPath.length() - outPath.lastIndexOf("/")) - 1) if outName.endsWith(".shp"): outName = outName.left(outName.length() - 4) - self.compute(inName, joinName, outPath, summary, sumList, keep, self.progressBar) + res = self.compute(inName, joinName, outPath, summary, sumList, keep, self.progressBar) self.outShape.clear() - addToTOC = QMessageBox.question(self, self.tr("Spatial Join"), self.tr("Created output shapefile:\n%1\n\nWould you like to add the new layer to the TOC?").arg(unicode(outPath)), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton) - if addToTOC == QMessageBox.Yes: + if res: + addToTOC = QMessageBox.question(self, self.tr("Spatial Join"), + self.tr("Created output shapefile:\n%1\n\nWould you like to add the new layer to the TOC?") + .arg(unicode(outPath)), QMessageBox.Yes, QMessageBox.No, QMessageBox.NoButton) + if addToTOC == QMessageBox.Yes: self.vlayer = QgsVectorLayer(outPath, unicode(outName), "ogr") QgsMapLayerRegistry.instance().addMapLayer(self.vlayer) self.progressBar.setValue(0) @@ -136,12 +139,22 @@ seq = range(0, len(fieldList1)) fieldList1 = dict(zip(seq, fieldList1)) + # check for correct field names + longNames = ftools_utils.checkFieldNameLenght( fieldList1 ) + if not longNames.isEmpty(): + QMessageBox.warning( self, self.tr( 'Incorrect field names' ), + self.tr( 'No output will be produced.\nFollowing field names are longer then 10 characters:\n%1' ) + .arg( longNames.join( '\n' ) ) ) + return False + sRs = provider1.crs() progressBar.setValue(13) check = QFile(self.shapefileName) if check.exists(): if not QgsVectorFileWriter.deleteShapeFile(self.shapefileName): - return + QMessageBox.warning( self, self.tr( 'Error deleting shapefile' ), + self.tr( "Can't delete existing shapefile\n%1" ).arg( self.shapefileName ) ) + return False writer = QgsVectorFileWriter(self.shapefileName, self.encoding, fieldList1, provider1.geometryType(), sRs) #writer = QgsVectorFileWriter(outName, "UTF-8", fieldList1, provider1.geometryType(), sRs) inFeat = QgsFeature() @@ -215,3 +228,4 @@ start = start + add progressBar.setValue(start) del writer + return True Index: python/plugins/fTools/tools/ftools_utils.py =================================================================== --- python/plugins/fTools/tools/ftools_utils.py (revision 13307) +++ python/plugins/fTools/tools/ftools_utils.py (working copy) @@ -12,6 +12,7 @@ # extractPoints( QgsGeometry ) # testForUniqueness( QList *QgsField, QList *QgsField ) # createUniqueFieldName( QgsField.name() ) +# checkFieldNameLenght( QgsFieldMap ) # getLayerNames( QGis.vectorType() ) # getFieldNames( QgsVectorLayer ) # getVectorLayerByName( QgsVectorLayer.name() ) @@ -158,6 +159,14 @@ field.setName( field.name() + "_2" ) return field +# Return list of field names with length more than 10 characters +def checkFieldNameLenght( fieldList ): + longNames = QStringList() + for num, field in fieldList.iteritems(): + if field.name().size() > 10: + longNames << unicode( field.name() ) + return longNames + # Return list of names of all layers in QgsMapLayerRegistry def getLayerNames( vTypes ): layermap = QgsMapLayerRegistry.instance().mapLayers()